k8s

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 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

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 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, certPath, keyPath string) *corev1.Secret

func GetAllImages

func GetAllImages() ([]string, error)

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

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 GetImages

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

GetImages returns all images for in pods in a given 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 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

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

func ProcessYamlFilesInPath

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

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 ReplaceTLSSecret

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

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 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 ImageSwap

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

ImageSwap Pre-compute all the replacements for the embedded registry

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 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) Establish

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