clusterutils

package
v1.0.29 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyComponentYAML

func ApplyComponentYAML(component, kubeconfigPath, manifest string, logger *utils.Logger, substitutions map[string]string)

ApplyComponentYAML applies a YAML manifest for a given component to the cluster. It logs the operation and any errors encountered.

Parameters:

component: Name of the component being applied.
kubeconfigPath: Path to the kubeconfig file.
manifest: Path or URL to the manifest YAML.
logger: Logger for output.
substitutions: Map of string substitutions to apply to the manifest.

func ApplySubstitutions

func ApplySubstitutions(data []byte, substitutions map[string]string) []byte

func ApplyYAMLManifest

func ApplyYAMLManifest(kubeconfigPath, manifestPathOrURL string, logger *utils.Logger, substitutions map[string]string) error

func BuildSubstitutions

func BuildSubstitutions(pairs ...string) map[string]string

func DeleteComponentYAML added in v1.0.29

func DeleteComponentYAML(component, kubeconfigPath, manifest string, logger *utils.Logger, substitutions map[string]string)

DeleteComponentYAML deletes a YAML manifest for a given component from the cluster. It logs the operation and any errors encountered.

func DeleteYAMLManifest added in v1.0.29

func DeleteYAMLManifest(kubeconfigPath, manifestPathOrURL string, logger *utils.Logger, substitutions map[string]string) error

DeleteYAMLManifest deletes the resources defined in a manifest from the cluster using kubectl delete -f.

func EnsureNamespace

func EnsureNamespace(kubeconfigPath, namespace string, logger *utils.Logger)

func ExecuteCommands

func ExecuteCommands(client *ssh.Client, commands []string, password string, logger *utils.Logger) error

ExecuteCommands runs a list of shell commands on the remote host via SSH.

Parameters:

client: SSH client.
commands: List of shell commands to execute.
password: Password for sudo commands (optional).
logger: Logger for output.

Returns:

Error if any command fails.

func ExecuteRemoteScript

func ExecuteRemoteScript(client *ssh.Client, script string, logger *utils.Logger) (string, error)

ExecuteRemoteScript runs a shell script on the remote host via SSH and returns its output.

Parameters:

client: SSH client.
script: Shell script to execute.
logger: Logger for output.

Returns:

Output string and error if execution fails.

func ForEachWorker

func ForEachWorker(workers []types.Worker, fn func(*types.Worker) error) error

func GetManifestData

func GetManifestData(manifestPathOrURL string) ([]byte, error)

func InstallHelmChart

func InstallHelmChart(kubeconfigPath, releaseName, namespace, repoName, repoURL, chartName, chartVersion, valuesFile string, logger *utils.Logger) error

InstallHelmChart installs or upgrades a Helm chart on the cluster using the provided parameters. It adds the repo, updates it, and runs the upgrade/install command.

Parameters:

kubeconfigPath: Path to the kubeconfig file.
releaseName: Name of the Helm release.
namespace: Kubernetes namespace for the release.
repoName: Name of the Helm repo.
repoURL: URL of the Helm repo.
chartName: Name of the chart in the repo.
chartVersion: Version of the chart to install.
valuesFile: Path to a values.yaml file (optional).
logger: Logger for output.

Returns:

Error if any Helm operation fails.

func KubeConfigPath

func KubeConfigPath(cluster *types.Cluster, logger *utils.Logger) string

KubeConfigPath returns the path to the kubeconfig file for the given cluster and logger session.

Parameters:

cluster: The cluster for which to get the kubeconfig path.
logger: Logger (used for session ID).

Returns:

Path to the kubeconfig YAML file.

func LabelNode

func LabelNode(kubeconfigPath, nodeName string, labels string, logger *utils.Logger) error

func PipeAndApply

func PipeAndApply(cmd *exec.Cmd, kubeconfig string, logger *utils.Logger)

func PipeAndDelete added in v1.0.29

func PipeAndDelete(cmd *exec.Cmd, kubeconfig string, logger *utils.Logger)

PipeAndDelete pipes the output of a command to 'kubectl delete -f -' using the given kubeconfig. Used for uninstalling resources generated by CLI tools like linkerd.

func PipeAndLog

func PipeAndLog(cmd *exec.Cmd, logger *utils.Logger)

func RenameKubeconfigContext added in v1.0.22

func RenameKubeconfigContext(kubeconfigPath, oldContext, newContext string, logger *utils.Logger)

func ResolveYamlPath

func ResolveYamlPath(filename string) string

func SSHConnect

func SSHConnect(userName, password, host string) (*ssh.Client, error)

SSHConnect establishes an SSH connection to the given host using username and password or available private keys.

Parameters:

userName: SSH username.
password: SSH password (optional if key is available).
host: Hostname or IP address.

Returns:

SSH client and error if connection fails.

func SplitYAMLDocs

func SplitYAMLDocs(data []byte) []string

func StreamOutput

func StreamOutput(r io.Reader, isErr bool, logger *utils.Logger)

func UninstallHelmRelease added in v1.0.29

func UninstallHelmRelease(kubeconfigPath, releaseName, namespace string, logger *utils.Logger) error

UninstallHelmRelease uninstalls a Helm release from the given namespace.

Parameters:

kubeconfigPath: Path to the kubeconfig file.
releaseName: Name of the Helm release to uninstall.
namespace: Kubernetes namespace of the release.
logger: Logger for output.

Returns:

Error if the Helm uninstall command fails.

func WaitForDeploymentReady

func WaitForDeploymentReady(kubeconfigPath, deployment, namespace string, logger *utils.Logger)

WaitForDeploymentReady waits until the specified deployment exists and is ready in the given namespace. It checks for deployment existence, then waits for rollout status.

Parameters:

kubeconfigPath: Path to the kubeconfig file.
deployment: Name of the deployment to check.
namespace: Kubernetes namespace.
logger: Logger for output.

Types

type AddonMigrationStatus added in v1.0.29

type AddonMigrationStatus int

AddonMigrationStatus represents the migration status of an addon (noop, apply, delete).

const (
	// AddonNoop indicates no migration action is needed for the addon.
	AddonNoop AddonMigrationStatus = iota
	// AddonApply indicates the addon should be applied (installed or upgraded).
	AddonApply
	// AddonDelete indicates the addon should be deleted (uninstalled).
	AddonDelete
)

func ComputeAddonMigrationStatus added in v1.0.29

func ComputeAddonMigrationStatus(name string, cluster *types.Cluster, oldVersion *types.Cluster, customAddon bool) AddonMigrationStatus

Jump to

Keyboard shortcuts

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