utils

package
v0.0.0-...-d1f3ee2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const EducatesCLIDataHomeEnv = "EDUCATES_CLI_DATA_HOME"

EducatesCLIDataHomeEnv overrides the on-disk home for all Educates CLI state. When set and non-empty, it takes precedence over the default xdg.DataHome/educates location. Useful for CI and tests.

A second data home is not a way to run several local clusters side by side: it still creates the default kind cluster, binds the same host ports and manages the same registry, resolver and mirror containers as the first. Named local clusters, which share one data home, run side by side instead.

Variables

This section is empty.

Functions

func BoolPointer

func BoolPointer(b bool) *bool

func CmdError

func CmdError(cmd *cobra.Command, errorMessage string, additionalMessage string) error

CmdError builds an error for a failed command-argument validation. It is meant to be returned from a cobra command's Args function so that an invalid invocation reports a clear message followed by the command path (with a usage hint) and a pointer to --help, rather than cobra's terse default ("accepts 1 arg(s), received 0").

additionalMessage is the positional-argument hint appended after the command path, e.g. "NAME" so the user sees the expected argument.

func CmdErrorFullUsage

func CmdErrorFullUsage(cmd *cobra.Command, errorMessage string, additionalMessage string) error

CmdErrorFullUsage is like CmdError but appends the command's full usage string instead of a single hint line. Prefer it for commands that take several positional arguments, where the full usage is clearer than a short hint.

func GetContainerName

func GetContainerName(c container.Summary) string

GetContainerName returns a container's primary name with the leading slash Docker prefixes stripped, or "unknown" when the container has no name.

func GetEducatesHomeDir

func GetEducatesHomeDir() string

GetEducatesHomeDir returns the on-disk home for all Educates CLI state (the default local cluster's config.yaml and kind config file, clusters/ for named local clusters, secrets/, dnsmasq.conf, compose/, workshops/).

Resolution order:

  1. $EDUCATES_CLI_DATA_HOME if set and non-empty.
  2. $XDG_DATA_HOME/educates/ (default).

func PrintExportedDocuments

func PrintExportedDocuments(documents []ExportedYAMLDocument) error

PrintExportedDocuments writes the documents to stdout as a single YAML stream, separating them with '---'.

func PrintKeyValuesTable

func PrintKeyValuesTable(rows [][]string) string

PrintKeyValuesTable renders an aligned "Key: value" table (one row per key/value pair) as a string, without a trailing newline. Each row must be a two-element slice of {key, value}.

func PrintTable

func PrintTable(headers []string, rows [][]string) string

PrintTable renders a simple aligned text table with the given headers and rows, returning it as a string (without a trailing newline). Empty cells are rendered as blank while keeping their column, so callers can leave a value unset without breaking alignment.

func PrintYamlFilesInDir

func PrintYamlFilesInDir(w io.Writer, dir string, args []string) error

PrintYamlFilesInDir writes to w the YAML files in dir, each after a "---" line: all of them, or only those named, without the .yaml suffix, in args.

func RenderResourceAsYAMLDocument

func RenderResourceAsYAMLDocument(resource *unstructured.Unstructured) ([]byte, error)

RenderResourceAsYAMLDocument marshals an unstructured resource to a YAML document.

func SanitizeResourceForExport

func SanitizeResourceForExport(resource *unstructured.Unstructured) *unstructured.Unstructured

SanitizeResourceForExport returns a deep copy of resource with the cluster-managed fields removed (status, and the server-populated metadata fields) so the result is a clean, re-appliable manifest.

func SanitizeTrainingPortalResourceForExport

func SanitizeTrainingPortalResourceForExport(resource *unstructured.Unstructured) *unstructured.Unstructured

SanitizeTrainingPortalResourceForExport removes portal fields that should not be carried across clusters, in addition to the common sanitization (currently the generated portal password).

func SanitizeWorkshopResourceForExport

func SanitizeWorkshopResourceForExport(resource *unstructured.Unstructured, cfg *WorkshopResourceExportConfig) *unstructured.Unstructured

SanitizeWorkshopResourceForExport rewrites a Workshop resource for export: it substitutes the $(image_repository) and $(workshop_version) variables with the supplied values, records the version under spec.version when it isn't already set (and isn't "latest"), and drops the spec.publish block (a build-time concern that shouldn't ship in an exported workshop).

func ValidateAndResolveIP

func ValidateAndResolveIP(bindIP string) (string, error)

*

  • This function is used to validate and resolve an IP address.
  • It is used when creating a new local registry or registry mirror.

func WriteExportedDocuments

func WriteExportedDocuments(dir string, documents []ExportedYAMLDocument) error

WriteExportedDocuments writes each document to dir/<doc.Name>, creating the directory if needed.

func WriteYamlByteArrayItemsToDir

func WriteYamlByteArrayItemsToDir(files [][]byte, dir string) error

func YesNoPrompt

func YesNoPrompt(label string, def bool) bool

YesNoPrompt prompts the user for a yes/no answer to a question. It returns true if the user answers yes, false if the user answers no, and the default value if the user does not answer.

Types

type ExportedYAMLDocument

type ExportedYAMLDocument struct {
	Name string
	Data []byte
}

ExportedYAMLDocument is a single named YAML document produced by an export. Name is used as the file name when writing to a directory; Data is the YAML body.

type WorkshopResourceExportConfig

type WorkshopResourceExportConfig struct {
	Repository      string
	WorkshopVersion string
}

WorkshopResourceExportConfig controls how a Workshop resource is rewritten on export.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL