Documentation
¶
Overview ¶
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Package cluster contains Zarf-specific cluster management functions.
Index ¶
- Constants
- func AdoptZarfManagedLabels(labels map[string]string) map[string]string
- func ClientAndConfig() (kubernetes.Interface, *rest.Config, error)
- func NewZarfManagedApplyNamespace(name string) *v1ac.NamespaceApplyConfiguration
- func NewZarfManagedNamespace(name string) *corev1.Namespace
- func WatcherForConfig(cfg *rest.Config) (watcher.StatusWatcher, error)
- type Cluster
- func (c *Cluster) Connect(ctx context.Context, target string) (*Tunnel, error)
- func (c *Cluster) ConnectToZarfRegistryEndpoint(ctx context.Context, registryInfo state.RegistryInfo) (string, *Tunnel, error)
- func (c *Cluster) ConnectTunnelInfo(ctx context.Context, zt TunnelInfo) (*Tunnel, error)
- func (c *Cluster) CreateInjectorConfigMaps(ctx context.Context, tmpDir, imagesDir string, injectorSeedSrcs []string, ...) ([]string, string, error)
- func (c *Cluster) DeleteDeployedPackage(ctx context.Context, depPkg state.DeployedPackage) error
- func (c *Cluster) DeleteZarfNamespace(ctx context.Context) error
- func (c *Cluster) DisableRegHPAScaleDown(ctx context.Context) error
- func (c *Cluster) EnableRegHPAScaleDown(ctx context.Context) error
- func (c *Cluster) GenerateGitPullCreds(namespace, name string, gitServerInfo state.GitServerInfo) *v1ac.SecretApplyConfiguration
- func (c *Cluster) GenerateRegistryPullCreds(ctx context.Context, namespace, name string, registryInfo state.RegistryInfo) (*v1ac.SecretApplyConfiguration, error)
- func (c *Cluster) GetDeployedPackage(ctx context.Context, packageName string, opts ...state.DeployedPackageOptions) (*state.DeployedPackage, error)
- func (c *Cluster) GetDeployedZarfPackages(ctx context.Context) ([]state.DeployedPackage, error)
- func (c *Cluster) GetIPFamily(ctx context.Context) (_ state.IPFamily, err error)
- func (c *Cluster) GetInjectorDaemonsetImage(ctx context.Context) (string, error)
- func (c *Cluster) GetInstalledChartsForComponent(ctx context.Context, packageName string, component v1alpha1.ZarfComponent, ...) ([]state.InstalledChart, error)
- func (c *Cluster) GetServiceInfoFromRegistryAddress(ctx context.Context, registryInfo state.RegistryInfo) (string, error)
- func (c *Cluster) HandleDataInjection(ctx context.Context, data v1alpha1.ZarfDataInjection, dataInjectionPath string, ...) error
- func (c *Cluster) InitState(ctx context.Context, opts InitStateOptions) (*state.State, error)
- func (c *Cluster) InternalGitServerExists(ctx context.Context) (bool, error)
- func (c *Cluster) ListConnections(ctx context.Context) (state.ConnectStrings, error)
- func (c *Cluster) LoadState(ctx context.Context) (*state.State, error)
- func (c *Cluster) NewTargetTunnelInfo(ctx context.Context, target string) (TunnelInfo, error)
- func (c *Cluster) NewTunnel(namespace, resourceType, resourceName, urlSuffix string, local, remote int, ...) (*Tunnel, error)
- func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg v1alpha1.ZarfPackage, ...) (*state.DeployedPackage, error)
- func (c *Cluster) SaveState(ctx context.Context, s *state.State) error
- func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, injectorSeedSrcs []string, ...) (int, error)
- func (c *Cluster) StopInjection(ctx context.Context) error
- func (c *Cluster) StripZarfLabelsAndSecretsFromNamespaces(ctx context.Context)
- func (c *Cluster) UpdateDeployedPackage(ctx context.Context, depPkg state.DeployedPackage) error
- func (c *Cluster) UpdateGiteaPVC(ctx context.Context, pvcName string, shouldRollBack bool) (string, error)
- func (c *Cluster) UpdateInternalArtifactServerToken(ctx context.Context, oldGitServer state.GitServerInfo) (string, error)
- func (c *Cluster) UpdateInternalGitServerSecret(ctx context.Context, oldGitServer state.GitServerInfo, ...) error
- func (c *Cluster) UpdateZarfManagedGitSecrets(ctx context.Context, s *state.State) error
- func (c *Cluster) UpdateZarfManagedImageSecrets(ctx context.Context, s *state.State) error
- type DockerConfig
- type DockerConfigEntry
- type DockerConfigEntryWithAuth
- type InitStateOptions
- type Tunnel
- func (tunnel *Tunnel) Close()
- func (tunnel *Tunnel) Connect(ctx context.Context) ([]string, error)
- func (tunnel *Tunnel) Endpoints() []string
- func (tunnel *Tunnel) ErrChan() chan error
- func (tunnel *Tunnel) FullURLs() []string
- func (tunnel *Tunnel) HTTPEndpoints() []string
- func (tunnel *Tunnel) Wrap(function func() error) error
- type TunnelInfo
- type TunnelOption
- type ZarfInjectorOptions
Constants ¶
const ( // DefaultTimeout is the default time to wait for a cluster to be ready. DefaultTimeout = 30 * time.Second // AgentLabel is used to give instructions to the Zarf agent AgentLabel = "zarf.dev/agent" // FieldManagerName is the field manager used during server side apply FieldManagerName = "zarf" // PackageLabel is the label used to identify the owning of package. PackageLabel string = "zarf.dev/package" // NamespaceOverrideLabel is the label used to identify the namespace override. NamespaceOverrideLabel string = "zarf.dev/namespace-override" )
const ( DistroIsUnknown = "unknown" DistroIsK3s = "k3s" DistroIsK3d = "k3d" DistroIsKind = "kind" DistroIsMicroK8s = "microk8s" DistroIsEKS = "eks" DistroIsEKSAnywhere = "eksanywhere" DistroIsDockerDesktop = "dockerdesktop" DistroIsGKE = "gke" DistroIsAKS = "aks" DistroIsRKE2 = "rke2" DistroIsTKG = "tkg" )
List of supported distros via distro detection.
const ( ZarfConnectLabelName = "zarf.dev/connect-name" ZarfConnectAnnotationDescription = "zarf.dev/connect-description" ZarfConnectAnnotationURL = "zarf.dev/connect-url" ZarfRegistry = "REGISTRY" ZarfGit = "GIT" ZarfInjector = "INJECTOR" ZarfInjectorName = "zarf-injector" ZarfInjectorPort = 5000 ZarfRegistryName = "zarf-docker-registry" ZarfRegistryPort = 5000 ZarfGitServerName = "zarf-gitea-http" ZarfGitServerPort = 3000 )
Zarf specific connect strings
const ( PodResource = "pod" SvcResource = "svc" )
Zarf Tunnel Configuration Constants.
Variables ¶
This section is empty.
Functions ¶
func AdoptZarfManagedLabels ¶
AdoptZarfManagedLabels adds & deletes the necessary labels that signal to Zarf it should manage a namespace
func ClientAndConfig ¶ added in v0.42.0
func ClientAndConfig() (kubernetes.Interface, *rest.Config, error)
ClientAndConfig returns a Kubernetes client and the rest config used to configure the client.
func NewZarfManagedApplyNamespace ¶ added in v0.42.2
func NewZarfManagedApplyNamespace(name string) *v1ac.NamespaceApplyConfiguration
NewZarfManagedApplyNamespace returns a v1ac.NamespaceApplyConfiguration with Zarf-managed labels
func NewZarfManagedNamespace ¶
NewZarfManagedNamespace returns a corev1.Namespace with Zarf-managed labels
func WatcherForConfig ¶ added in v0.42.0
func WatcherForConfig(cfg *rest.Config) (watcher.StatusWatcher, error)
WatcherForConfig returns a status watcher for the give Kubernetes configuration.
Types ¶
type Cluster ¶
type Cluster struct {
// Clientset implements k8s client api
Clientset kubernetes.Interface
// RestConfig holds common options for a k8s client
RestConfig *rest.Config
// Watcher implements kstatus StatusWatcher
Watcher watcher.StatusWatcher
}
Cluster Zarf specific cluster management functions.
func New ¶ added in v0.54.0
New creates a new Cluster instance and validates connection to the cluster by fetching the Kubernetes version.
func NewWithWait ¶ added in v0.54.0
NewWithWait creates a new Cluster instance and waits for the given timeout for the cluster to be ready.
func (*Cluster) ConnectToZarfRegistryEndpoint ¶
func (c *Cluster) ConnectToZarfRegistryEndpoint(ctx context.Context, registryInfo state.RegistryInfo) (string, *Tunnel, error)
ConnectToZarfRegistryEndpoint determines if a registry endpoint is in cluster, and if so opens a tunnel to connect to it
func (*Cluster) ConnectTunnelInfo ¶
ConnectTunnelInfo connects to the cluster with the provided TunnelInfo
func (*Cluster) CreateInjectorConfigMaps ¶ added in v0.65.0
func (c *Cluster) CreateInjectorConfigMaps(ctx context.Context, tmpDir, imagesDir string, injectorSeedSrcs []string, pkgName string) ([]string, string, error)
CreateInjectorConfigMaps creates the required configmaps to run the injector
func (*Cluster) DeleteDeployedPackage ¶ added in v0.41.0
DeleteDeployedPackage removes the metadata for the deployed package.
func (*Cluster) DeleteZarfNamespace ¶
DeleteZarfNamespace deletes the Zarf namespace from the connected cluster.
func (*Cluster) DisableRegHPAScaleDown ¶
DisableRegHPAScaleDown disables the HPA scale down for the Zarf Registry.
func (*Cluster) EnableRegHPAScaleDown ¶
EnableRegHPAScaleDown enables the HPA scale down for the Zarf Registry.
func (*Cluster) GenerateGitPullCreds ¶
func (c *Cluster) GenerateGitPullCreds(namespace, name string, gitServerInfo state.GitServerInfo) *v1ac.SecretApplyConfiguration
GenerateGitPullCreds generates a secret containing the git credentials.
func (*Cluster) GenerateRegistryPullCreds ¶
func (c *Cluster) GenerateRegistryPullCreds(ctx context.Context, namespace, name string, registryInfo state.RegistryInfo) (*v1ac.SecretApplyConfiguration, error)
GenerateRegistryPullCreds generates a secret containing the registry credentials.
func (*Cluster) GetDeployedPackage ¶
func (c *Cluster) GetDeployedPackage(ctx context.Context, packageName string, opts ...state.DeployedPackageOptions) (*state.DeployedPackage, error)
GetDeployedPackage gets the metadata information about the package name provided (if it exists in the cluster). We determine what packages have been deployed to the cluster by looking for specific secrets in the Zarf namespace.
func (*Cluster) GetDeployedZarfPackages ¶
GetDeployedZarfPackages gets metadata information about packages that have been deployed to the cluster. We determine what packages have been deployed to the cluster by looking for specific secrets in the Zarf namespace. Returns a list of DeployedPackage structs and a list of errors.
func (*Cluster) GetIPFamily ¶ added in v0.65.0
GetIPFamily returns the IP family of the cluster, can be ipv4, ipv6, or dual.
func (*Cluster) GetInjectorDaemonsetImage ¶ added in v0.65.0
GetInjectorDaemonsetImage gets the image that is most likely to be accessible from all nodes It first grabs the latest version pause image with semver 3 or 4, under 1MiB, and with pause in the name. If there are no valid pause images then it grabs the smallest image.
func (*Cluster) GetInstalledChartsForComponent ¶
func (c *Cluster) GetInstalledChartsForComponent(ctx context.Context, packageName string, component v1alpha1.ZarfComponent, opts ...state.DeployedPackageOptions) ([]state.InstalledChart, error)
GetInstalledChartsForComponent returns any installed Helm Charts for the provided package component.
func (*Cluster) GetServiceInfoFromRegistryAddress ¶
func (c *Cluster) GetServiceInfoFromRegistryAddress(ctx context.Context, registryInfo state.RegistryInfo) (string, error)
GetServiceInfoFromRegistryAddress gets the service info for a registry address if it is a NodePort
func (*Cluster) HandleDataInjection ¶
func (c *Cluster) HandleDataInjection(ctx context.Context, data v1alpha1.ZarfDataInjection, dataInjectionPath string, dataIdx int) error
HandleDataInjection waits for the target pod(s) to come up and inject the data into them todo: this currently requires kubectl but we should have enough k8s work to make this native now.
func (*Cluster) InitState ¶ added in v0.54.0
InitState takes initOptions and hydrates a cluster's state from InitStateOptions. If state was already initialized then internal services (registry, git server, artifact server) won't be updated
func (*Cluster) InternalGitServerExists ¶ added in v0.38.3
InternalGitServerExists checks if the Zarf internal git server exists in the cluster.
func (*Cluster) ListConnections ¶
ListConnections will return a list of all Zarf connect matches found in the cluster.
func (*Cluster) LoadState ¶ added in v0.54.0
LoadState utilizes the k8s Clientset to load and return the current state.State data or an empty state.State if no cluster is found.
func (*Cluster) NewTargetTunnelInfo ¶ added in v0.38.0
NewTargetTunnelInfo returns a new TunnelInfo object for the specified target.
func (*Cluster) NewTunnel ¶
func (c *Cluster) NewTunnel(namespace, resourceType, resourceName, urlSuffix string, local, remote int, opts ...TunnelOption) (*Tunnel, error)
NewTunnel will create a new Tunnel struct. Note that if you use 0 for the local port, an open port on the host system will be selected automatically, and the Tunnel struct will be updated with the selected port.
func (*Cluster) RecordPackageDeployment ¶
func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg v1alpha1.ZarfPackage, components []state.DeployedComponent, generation int, opts ...state.DeployedPackageOptions) (*state.DeployedPackage, error)
RecordPackageDeployment saves metadata about a package that has been deployed to the cluster.
func (*Cluster) SaveState ¶ added in v0.54.0
SaveState takes a given state.State and persists it to k8s Cluster secrets.
func (*Cluster) StartInjection ¶
func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, injectorSeedSrcs []string, pkgName string, architecture string, opts ZarfInjectorOptions) (int, error)
StartInjection initializes a Zarf injection into the cluster
func (*Cluster) StopInjection ¶
StopInjection handles cleanup once the seed registry is up.
func (*Cluster) StripZarfLabelsAndSecretsFromNamespaces ¶
StripZarfLabelsAndSecretsFromNamespaces removes metadata and secrets from existing namespaces no longer manged by Zarf.
func (*Cluster) UpdateDeployedPackage ¶ added in v0.41.0
UpdateDeployedPackage updates the deployed package metadata.
func (*Cluster) UpdateGiteaPVC ¶ added in v0.38.0
func (c *Cluster) UpdateGiteaPVC(ctx context.Context, pvcName string, shouldRollBack bool) (string, error)
UpdateGiteaPVC updates the existing Gitea persistent volume claim and tells Gitea whether to create or not. TODO(mkcp): We return both string true/false and errors here so our callers get a string. This should be returning an empty val if we error, but we'll have to refactor upstream beforehand.
func (*Cluster) UpdateInternalArtifactServerToken ¶ added in v0.38.3
func (c *Cluster) UpdateInternalArtifactServerToken(ctx context.Context, oldGitServer state.GitServerInfo) (string, error)
UpdateInternalArtifactServerToken updates the the artifact server token on the internal gitea server and returns it
func (*Cluster) UpdateInternalGitServerSecret ¶ added in v0.38.3
func (c *Cluster) UpdateInternalGitServerSecret(ctx context.Context, oldGitServer state.GitServerInfo, newGitServer state.GitServerInfo) error
UpdateInternalGitServerSecret updates the internal gitea server secrets with the new git server info
func (*Cluster) UpdateZarfManagedGitSecrets ¶
UpdateZarfManagedGitSecrets updates all Zarf-managed git secrets in all namespaces based on state
type DockerConfig ¶
type DockerConfig struct {
Auths DockerConfigEntry `json:"auths"`
}
DockerConfig contains the authentication information from the machine's docker config.
type DockerConfigEntry ¶
type DockerConfigEntry map[string]DockerConfigEntryWithAuth
DockerConfigEntry contains a map of DockerConfigEntryWithAuth for a registry.
type DockerConfigEntryWithAuth ¶
type DockerConfigEntryWithAuth struct {
Auth string `json:"auth"`
}
DockerConfigEntryWithAuth contains a docker config authentication string.
type InitStateOptions ¶ added in v0.54.0
type InitStateOptions struct {
// Indicates if Zarf was initialized while deploying its own k8s cluster
ApplianceMode bool
// Information about the repository Zarf is going to be using
GitServer state.GitServerInfo
// Information about the container registry Zarf is going to be using
RegistryInfo state.RegistryInfo
// Information about the artifact registry Zarf is going to be using
ArtifactServer state.ArtifactServerInfo
// StorageClass of the k8s cluster Zarf is initializing
StorageClass string
// InjectorPort is the port that the injector will be exposed through
InjectorPort int
}
InitStateOptions tracks the user-defined options during cluster initialization.
type Tunnel ¶
type Tunnel struct {
// contains filtered or unexported fields
}
Tunnel is the main struct that configures and manages port forwarding tunnels to Kubernetes resources.
func (*Tunnel) Close ¶
func (tunnel *Tunnel) Close()
Close disconnects a tunnel connection by closing the StopChan, thereby stopping the goroutine.
func (*Tunnel) FullURLs ¶ added in v0.59.0
FullURLs returns the tunnel endpoint as a HTTP URL string with the urlSuffix appended.
func (*Tunnel) HTTPEndpoints ¶ added in v0.59.0
HTTPEndpoints returns all tunnel endpoints as a list of HTTP URL strings.
type TunnelInfo ¶
type TunnelInfo struct {
LocalPort int
RemotePort int
ListenAddresses []string
Namespace string
ResourceType string
ResourceName string
// contains filtered or unexported fields
}
TunnelInfo is a struct that contains the necessary info to create a new Tunnel
type TunnelOption ¶ added in v0.59.0
type TunnelOption func(*Tunnel)
TunnelOption is a function that configures a tunnel
func WithListenAddress ¶ added in v0.59.0
func WithListenAddress(addr []string) TunnelOption
WithListenAddress will set the listen address for the tunnel
type ZarfInjectorOptions ¶ added in v0.69.0
type ZarfInjectorOptions struct {
// - RegistryNodePort, with using uint16 allows for only the valid ports, this includes 0 as it will allow Kubernetes to choose the node port for us
RegistryNodePort uint16
// - InjectorNodePort, with using uint16 allows for only the valid ports, this includes 0 as it will allow Kubernetes to choose the node port for us
InjectorNodePort uint16
}
ZarfInjectorOptions represents the options used by injector pod