k8s

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 44 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"
)
View Source
const (
	PortRegistry = iota + 45001
	PortLogging
	PortGit
)

Variables

This section is empty.

Functions

func CreateConfigmap added in v0.16.0

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

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

func CreatePod added in v0.16.0

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

CreatePod inserts the given pod into the cluster

func CreateSecret added in v0.15.0

func CreateSecret(secret *corev1.Secret) error

func CreateService added in v0.16.0

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

CreateService creates the given service in the cluster.

func DeleteConfigMapsByLabel added in v0.16.0

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

DeleteConfigMapsByLabel deletes a configmap by label(s)

func DeleteConfigmap added in v0.16.0

func DeleteConfigmap(namespace, name string) error

DeleteConfigmap delets a confimap by name

func DeletePod added in v0.16.0

func DeletePod(namespace string, name string) error

DeletePod removees a pod from the cluster by namespace & name

func DeleteSecret added in v0.15.0

func DeleteSecret(secret *corev1.Secret) error

func DeleteService added in v0.16.0

func DeleteService(namespace, name string) error

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

func DeleteZarfNamespace added in v0.15.0

func DeleteZarfNamespace()

func DetectDistro added in v0.15.0

func DetectDistro() (string, error)

DetectDistro returns the matching distro or unknown if not found

func GeneratePod added in v0.16.0

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

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

func GenerateRegistryPullCreds added in v0.15.0

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

func GenerateService added in v0.16.0

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

GenerateService returns a K8s service struct without writing to the cluster

func GenerateTLSSecret added in v0.15.0

func GenerateTLSSecret(namespace, name, certPath, keyPath string) *corev1.Secret

func GetAllImages added in v0.16.0

func GetAllImages() ([]string, error)

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

func GetAllPods added in v0.16.0

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

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

func GetAllServiceAccounts added in v0.15.0

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

GetAllServiceAccounts returns a list of services accounts for all namespaces.

func GetArchitecture added in v0.16.0

func GetArchitecture() (string, error)

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

func GetAvailablePort added in v0.15.0

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

func GetContext() (string, error)

GetContext returns the current k8s context

func GetImages added in v0.16.0

func GetImages(namespace string) ([]string, error)

GetImages returns all images for in pods in a given namespace.

func GetNamespaces added in v0.15.0

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

func GetNodes added in v0.15.0

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

GetNodes returns a list of nodes from the k8s cluster.

func GetPods added in v0.16.0

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

GetPods returns a list of pods from the cluster by namespace

func GetSecret added in v0.15.0

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

func GetService added in v0.15.0

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

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

func GetServiceAccount added in v0.15.0

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

GetServiceAccount reutrns a single service account by namespace and name.

func GetServiceAccounts added in v0.15.0

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

GetServiceAccounts returns a list of service accounts in a given namespace

func GetServicesByLabel added in v0.15.0

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

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

func LoadZarfState() types.ZarfState

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

func ProcessYamlFilesInPath added in v0.15.0

func ProcessYamlFilesInPath(path string, componentImages []string) []string

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

func ReplaceConfigmap added in v0.16.0

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

ReplaceConfigmap deletes and recreates a configmap

func ReplaceSecret added in v0.15.0

func ReplaceSecret(secret *corev1.Secret) error

func ReplaceTLSSecret

func ReplaceTLSSecret(namespace, name, certPath, keyPath string)

func SaveServiceAccount added in v0.15.0

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

SaveServiceAccount updates the given service account in the cluster

func SaveZarfState added in v0.15.0

func SaveZarfState(state types.ZarfState) error

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

func SortImages added in v0.16.0

func SortImages(images, compareWith ImageMap) []string

SortImages returns a sorted list of images.

func SplitYAML added in v0.15.0

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 WaitForHealthyCluster added in v0.16.0

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

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

type DockerConfigEntry added in v0.15.0

type DockerConfigEntry map[string]DockerConfigEntryWithAuth

type DockerConfigEntryWithAuth added in v0.15.0

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

type ImageMap added in v0.16.0

type ImageMap map[string]bool

func BuildImageMap added in v0.16.0

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

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

type ImageSwap added in v0.15.0

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

ImageSwap Pre-compute all the replacements for the embedded registry

type Tunnel added in v0.15.0

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

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 NewZarfTunnel added in v0.15.0

func NewZarfTunnel() *Tunnel

func (*Tunnel) AddSpinner added in v0.16.0

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

func (*Tunnel) Close added in v0.15.0

func (tunnel *Tunnel) Close()

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

func (*Tunnel) Connect added in v0.15.0

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

func (*Tunnel) EnableAutoOpen added in v0.16.0

func (tunnel *Tunnel) EnableAutoOpen()

func (*Tunnel) Endpoint added in v0.15.0

func (tunnel *Tunnel) Endpoint() string

Endpoint returns the tunnel endpoint

func (*Tunnel) Establish added in v0.15.0

func (tunnel *Tunnel) Establish() (string, error)

Establish opens a tunnel to a kubernetes resource, as specified by the provided tunnel struct.

Jump to

Keyboard shortcuts

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