k8s

package
v0.22.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	ZarfNamespace       = "zarf"
	ZarfStateSecretName = "zarf-state"
	ZarfStateDataKey    = "state"
)
View Source
const (
	PodResource  = "pod"
	SvcResource  = "svc"
	ZarfRegistry = "REGISTRY"
	ZarfLogging  = "LOGGING"
	ZarfGit      = "GIT"
	ZarfInjector = "INJECTOR"
)

Variables

This section is empty.

Functions

func CreateConfigmap

func CreateConfigmap(namespace, name string, labels map[string]string, data map[string][]byte) (*corev1.ConfigMap, error)

CreateConfigmap applys a configmap to the cluster

func CreateNamespace

func CreateNamespace(name string, namespace *corev1.Namespace) (*corev1.Namespace, error)

func CreatePod

func CreatePod(pod *corev1.Pod) (*corev1.Pod, error)

CreatePod inserts the given pod into the cluster

func CreateSecret

func CreateSecret(secret *corev1.Secret) error

func CreateService

func CreateService(service *corev1.Service) (*corev1.Service, error)

CreateService creates the given service in the cluster.

func DeleteConfigMapsByLabel

func DeleteConfigMapsByLabel(namespace string, labels map[string]string) error

DeleteConfigMapsByLabel deletes a configmap by label(s)

func DeleteConfigmap

func DeleteConfigmap(namespace, name string) error

DeleteConfigmap delets a confimap by name

func DeletePod

func DeletePod(namespace string, name string) error

DeletePod removees a pod from the cluster by namespace & name

func DeleteSecret

func DeleteSecret(secret *corev1.Secret) error

func DeleteService

func DeleteService(namespace, name string) error

DeleteService removes a service from the cluster by namespace and name.

func DeleteZarfNamespace

func DeleteZarfNamespace()

func DetectDistro

func DetectDistro() (string, error)

DetectDistro returns the matching distro or unknown if not found

func GeneratePod

func GeneratePod(name, namespace string) *corev1.Pod

GeneratePod creates a new pod without adding it to the k8s cluster

func GenerateRegistryPullCreds

func GenerateRegistryPullCreds(namespace, name string) *corev1.Secret

func GenerateSecret added in v0.19.0

func GenerateSecret(namespace, name string, secretType corev1.SecretType) *corev1.Secret

func GenerateService

func GenerateService(namespace, name string) *corev1.Service

GenerateService returns a K8s service struct without writing to the cluster

func GenerateTLSSecret

func GenerateTLSSecret(namespace, name string, conf types.GeneratedPKI) (*corev1.Secret, error)

func GetAllPods

func GetAllPods() (*corev1.PodList, error)

GetAllPods returns a list of pods from the cluster for all namesapces

func GetAllServiceAccounts

func GetAllServiceAccounts() (*corev1.ServiceAccountList, error)

GetAllServiceAccounts returns a list of services accounts for all namespaces.

func GetArchitecture

func GetArchitecture() (string, error)

GetArchitecture returns the cluster system architecture if found or an error if not

func GetAvailablePort

func GetAvailablePort() (int, error)

GetAvailablePort retrieves an available port on the host machine. This delegates the port selection to the golang net library by starting a server and then checking the port that the server is using.

func GetContext

func GetContext() (string, error)

GetContext returns the current k8s context

func GetDeployedZarfPackages added in v0.22.0

func GetDeployedZarfPackages() ([]types.DeployedPackage, error)

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.

func GetNamespaces

func GetNamespaces() (*corev1.NamespaceList, error)

func GetNodes

func GetNodes() (*corev1.NodeList, error)

GetNodes returns a list of nodes from the k8s cluster.

func GetPods

func GetPods(namespace string) (*corev1.PodList, error)

GetPods returns a list of pods from the cluster by namespace

func GetSecret

func GetSecret(namespace, name string) (*corev1.Secret, error)

func GetSecretsWithLabel added in v0.22.0

func GetSecretsWithLabel(namespace, labelSelector string) (*corev1.SecretList, error)

func GetService

func GetService(namespace, serviceName string) (*corev1.Service, error)

GetService returns a Kubernetes service resource in the provided namespace with the given name.

func GetServiceAccount

func GetServiceAccount(namespace, name string) (*corev1.ServiceAccount, error)

GetServiceAccount reutrns a single service account by namespace and name.

func GetServiceAccounts

func GetServiceAccounts(namespace string) (*corev1.ServiceAccountList, error)

GetServiceAccounts returns a list of service accounts in a given namespace

func GetServicesByLabel

func GetServicesByLabel(namespace, label, value string) (*corev1.ServiceList, error)

GetServicesByLabel returns a list of matched services given a label and value. To search all namespaces, pass "" in the namespace arg

func GetServicesByLabelExists

func GetServicesByLabelExists(namespace, label string) (*corev1.ServiceList, error)

GetServicesByLabelExists returns a list of matched services given a label. To search all namespaces, pass "" in the namespace arg

func LoadZarfState

func LoadZarfState() (types.ZarfState, error)

LoadZarfState returns the current zarf/zarf-state secret data or an empty ZarfState

func PrintConnectTable added in v0.20.0

func PrintConnectTable() error

GenerateConnectionTable will print a table of all zarf connect matches found in the cluster

func ProcessYamlFilesInPath

func ProcessYamlFilesInPath(path string, component types.ZarfComponent) []string

ProcessYamlFilesInPath iterates over all yaml files in a given path and performs Zarf templating + image swapping

func ReplaceConfigmap

func ReplaceConfigmap(namespace, name string, labels map[string]string, data map[string][]byte) (*corev1.ConfigMap, error)

ReplaceConfigmap deletes and recreates a configmap

func ReplaceSecret

func ReplaceSecret(secret *corev1.Secret) error

func ReplaceService added in v0.19.0

func ReplaceService(service *corev1.Service) (*corev1.Service, error)

ReplaceService deletes and re-creates a service

func ReplaceTLSSecret

func ReplaceTLSSecret(namespace, name string, conf types.GeneratedPKI) error

func SaveServiceAccount

func SaveServiceAccount(svcAccount *corev1.ServiceAccount) (*corev1.ServiceAccount, error)

SaveServiceAccount updates the given service account in the cluster

func SaveZarfState

func SaveZarfState(state types.ZarfState) error

SaveZarfState takes a given state and makepersists it to the zarf/zarf-state secret

func SortImages

func SortImages(images, compareWith ImageMap) []string

SortImages returns a sorted list of images.

func SplitYAML

func SplitYAML(yamlData []byte) ([]*unstructured.Unstructured, error)

SplitYAML splits a YAML file into unstructured objects. Returns list of all unstructured objects found in the yaml. If an error occurs, returns objects that have been parsed so far too. Source: https://github.com/argoproj/gitops-engine/blob/v0.5.2/pkg/utils/kube/kube.go#L286

func StripZarfLabelsAndSecretsFromNamespaces added in v0.19.6

func StripZarfLabelsAndSecretsFromNamespaces()

StripZarfLabelsAndSecretsFromNamespaces removes metadata and secrets from existing namespaces no longer manged by Zarf.

func UpdateNamespace added in v0.19.1

func UpdateNamespace(namespace *corev1.Namespace) (*corev1.Namespace, error)

func WaitForHealthyCluster

func WaitForHealthyCluster(timeout time.Duration) error

WaitForHealthyCluster checks for an available K8s cluster every second until timeout.

func WaitForPodsAndContainers

func WaitForPodsAndContainers(target types.ZarfContainerTarget, waitForAllPods bool) []string

WaitForPodsAndContainers holds execution up to 30 seconds waiting for health pods and containers (if specified)

Types

type DockerConfig

type DockerConfig struct {
	Auths DockerConfigEntry `json:"auths"`
}

type DockerConfigEntry

type DockerConfigEntry map[string]DockerConfigEntryWithAuth

type DockerConfigEntryWithAuth

type DockerConfigEntryWithAuth struct {
	Auth string `json:"auth"`
}

type ImageMap

type ImageMap map[string]bool

func BuildImageMap

func BuildImageMap(images ImageMap, pod corev1.PodSpec) ImageMap

BuildImageMap looks for init container, ephemeral and regular container images.

type ImageNodeMap added in v0.19.4

type ImageNodeMap map[string][]string

func GetAllImages

func GetAllImages() (ImageNodeMap, error)

GetAllImages returns a list of images and their nodes found in pods in the cluster.

func GetImagesWithNodes added in v0.19.4

func GetImagesWithNodes(namespace string) (ImageNodeMap, error)

GetImagesWithNodes returns all images and their nodes in a given namespace.

type Tunnel

type Tunnel struct {
	// contains filtered or unexported fields
}

Tunnel is the main struct that configures and manages port forwading tunnels to Kubernetes resources.

func NewTunnel

func NewTunnel(namespace, resourceType, resourceName string, local, remote int) *Tunnel

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 NewTunnelFromServiceURL added in v0.22.0

func NewTunnelFromServiceURL(serviceURL string) (*Tunnel, error)

NewTunnelFromServiceURL takes a serviceURL and parses it to create a tunnel to the cluster. The string is expected to follow the following format: Example serviceURL: http://{SERVICE_NAME}.{NAMESPACE}.svc.cluster.local:{PORT}

func NewZarfTunnel

func NewZarfTunnel() *Tunnel

func (*Tunnel) AddSpinner

func (tunnel *Tunnel) AddSpinner(spinner *message.Spinner)

func (*Tunnel) Close

func (tunnel *Tunnel) Close()

Close disconnects a tunnel connection by closing the StopChan, thereby stopping the goroutine.

func (*Tunnel) Connect

func (tunnel *Tunnel) Connect(target string, blocking bool)

func (*Tunnel) EnableAutoOpen

func (tunnel *Tunnel) EnableAutoOpen()

func (*Tunnel) Endpoint

func (tunnel *Tunnel) Endpoint() string

Endpoint returns the tunnel endpoint

func (*Tunnel) HttpEndpoint added in v0.20.0

func (tunnel *Tunnel) HttpEndpoint() string

HttpEndpoint returns the tunnel endpoint as a HTTP URL string

Jump to

Keyboard shortcuts

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