cluster

package
v5.30.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cluster detects Kubernetes cluster distribution, provider, and other attributes by analyzing kubeconfig contexts and server endpoints.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCurrentContext indicates no current context is set in kubeconfig.
	ErrNoCurrentContext = errors.New("no current context set in kubeconfig")

	// ErrContextNotFound indicates the specified context was not found in kubeconfig.
	ErrContextNotFound = errors.New("context not found in kubeconfig")

	// ErrClusterNotFound indicates the cluster referenced by the context was not found.
	ErrClusterNotFound = errors.New("cluster not found in kubeconfig")

	// ErrUnknownContextPattern indicates the context name doesn't match any known distribution pattern.
	ErrUnknownContextPattern = errors.New(
		"unknown distribution: context does not match kind-, k3d-, or admin@ pattern",
	)

	// ErrEmptyClusterName is returned when cluster name detection results in an empty string.
	// This happens with malformed contexts like "kind-", "k3d-", or "admin@".
	ErrEmptyClusterName = errors.New("empty cluster name detected from context")

	// ErrUnableToDetectProvider indicates the provider could not be determined from the server endpoint.
	ErrUnableToDetectProvider = errors.New("unable to detect provider from server endpoint")

	// ErrNoCloudCredentials indicates no cloud provider credentials were found for a public IP.
	ErrNoCloudCredentials = errors.New("public IP detected but no cloud provider credentials found")

	// ErrNoHostInURL indicates a URL was parsed but contained no host component.
	ErrNoHostInURL = errors.New("no host found in URL")
)

Detection errors.

Functions

func DetectDistributionFromContext

func DetectDistributionFromContext(contextName string) (v1alpha1.Distribution, string, error)

DetectDistributionFromContext detects the Kubernetes distribution and cluster name from the kubeconfig context name pattern. Returns the distribution, cluster name, and any error.

Context name patterns:

  • kind-<cluster-name> → Vanilla (Kind)
  • k3d-<cluster-name> → K3s (K3d)
  • admin@<cluster-name> → Talos

Returns an error if the pattern is unrecognized or if the extracted cluster name is empty.

func ResolveKubeconfigPath

func ResolveKubeconfigPath(kubeconfigPath string) (string, error)

ResolveKubeconfigPath returns the kubeconfig path, resolving defaults if empty and expanding ~ to the home directory.

Types

type Info

type Info struct {
	Distribution   v1alpha1.Distribution
	Provider       v1alpha1.Provider
	ClusterName    string
	ServerURL      string
	KubeconfigPath string
}

Info contains the detected distribution and provider for a cluster.

func DetectInfo

func DetectInfo(kubeconfigPath, contextName string) (*Info, error)

DetectInfo detects the distribution and provider from the kubeconfig context. It reads the kubeconfig, determines the distribution from the context name pattern, and detects the provider by analyzing the server endpoint.

Jump to

Keyboard shortcuts

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