Documentation
¶
Overview ¶
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Index ¶
- Constants
- func MakeLabels(labels map[string]string) string
- type GeneratedPKI
- type K8s
- func (k *K8s) AddLabelsAndAnnotations(ctx context.Context, resourceNamespace, resourceName string, ...) error
- func (k *K8s) CreateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
- func (k *K8s) CreateOrUpdateSecret(ctx context.Context, secret *corev1.Secret) (createdSecret *corev1.Secret, err error)
- func (k *K8s) CreateOrUpdateTLSSecret(ctx context.Context, namespace, name string, conf GeneratedPKI) (*corev1.Secret, error)
- func (k *K8s) CreatePod(ctx context.Context, pod *corev1.Pod) (*corev1.Pod, error)
- func (k *K8s) DeleteNamespace(ctx context.Context, name string) error
- func (k *K8s) DeletePod(ctx context.Context, namespace string, name string) error
- func (k *K8s) DeletePods(ctx context.Context, target PodLookup) error
- func (k *K8s) DeleteSecret(ctx context.Context, secret *corev1.Secret) error
- func (k *K8s) FindPodContainerPort(ctx context.Context, svc corev1.Service) int
- func (k *K8s) GeneratePod(name, namespace string) *corev1.Pod
- func (k *K8s) GenerateSecret(namespace, name string, secretType corev1.SecretType) *corev1.Secret
- func (k *K8s) GenerateTLSSecret(namespace, name string, conf GeneratedPKI) (*corev1.Secret, error)
- func (k *K8s) GetAllPods(ctx context.Context) (*corev1.PodList, error)
- func (k *K8s) GetArchitectures(ctx context.Context) ([]string, error)
- func (k *K8s) GetNamespaces(ctx context.Context) (*corev1.NamespaceList, error)
- func (k *K8s) GetNode(ctx context.Context, nodeName string) (*corev1.Node, error)
- func (k *K8s) GetNodes(ctx context.Context) (*corev1.NodeList, error)
- func (k *K8s) GetPods(ctx context.Context, namespace string, listOpts metav1.ListOptions) (*corev1.PodList, error)
- func (k *K8s) GetSecret(ctx context.Context, namespace, name string) (*corev1.Secret, error)
- func (k *K8s) GetSecretsWithLabel(ctx context.Context, namespace, labelSelector string) (*corev1.SecretList, error)
- func (k *K8s) GetServerVersion() (version string, err error)
- func (k *K8s) HandleDeprecations(rawData *unstructured.Unstructured, kubernetesVersion semver.Version) (*unstructured.Unstructured, bool, error)
- func (k *K8s) IsInitialNamespace(name string) bool
- func (k *K8s) NewTunnel(namespace, resourceType, resourceName, urlSuffix string, local, remote int) (*Tunnel, error)
- func (k *K8s) RemoveLabelsAndAnnotations(ctx context.Context, resourceNamespace, resourceName string, ...) error
- func (k *K8s) UpdateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
- func (k *K8s) WaitForHealthyCluster(ctx context.Context) error
- func (k *K8s) WaitForPodsAndContainers(ctx context.Context, target PodLookup, include PodFilter) []corev1.Pod
- type Labels
- type Log
- type PodFilter
- type PodLookup
- type Tunnel
- func (tunnel *Tunnel) Close()
- func (tunnel *Tunnel) Connect(ctx context.Context) (string, error)
- func (tunnel *Tunnel) Endpoint() string
- func (tunnel *Tunnel) ErrChan() chan error
- func (tunnel *Tunnel) FullURL() string
- func (tunnel *Tunnel) HTTPEndpoint() string
- func (tunnel *Tunnel) Wrap(function func() error) error
Constants ¶
const ( // ZarfManagedByLabel is used to denote Zarf manages the lifecycle of a resource ZarfManagedByLabel = "app.kubernetes.io/managed-by" // AgentLabel is used to give instructions to the Zarf agent AgentLabel = "zarf.dev/agent" )
const ( PodResource = "pod" SvcResource = "svc" )
Zarf Tunnel Configuration Constants.
Variables ¶
This section is empty.
Functions ¶
func MakeLabels ¶ added in v0.30.0
MakeLabels is a helper to format a map of label key and value pairs into a single string for use as a selector.
Types ¶
type GeneratedPKI ¶
type GeneratedPKI struct { CA []byte `json:"ca"` Cert []byte `json:"cert"` Key []byte `json:"key"` }
GeneratedPKI is a struct for storing generated PKI data.
type K8s ¶
type K8s struct { Clientset kubernetes.Interface RestConfig *rest.Config Log Log }
K8s is a client for interacting with a Kubernetes cluster.
func (*K8s) AddLabelsAndAnnotations ¶ added in v0.26.1
func (k *K8s) AddLabelsAndAnnotations(ctx context.Context, resourceNamespace, resourceName string, groupKind schema.GroupKind, labels, annotations map[string]string) error
AddLabelsAndAnnotations adds the provided labels and annotations to the specified K8s resource
func (*K8s) CreateNamespace ¶
func (k *K8s) CreateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
CreateNamespace creates the given namespace or returns it if it already exists in the cluster.
func (*K8s) CreateOrUpdateSecret ¶ added in v0.23.4
func (k *K8s) CreateOrUpdateSecret(ctx context.Context, secret *corev1.Secret) (createdSecret *corev1.Secret, err error)
CreateOrUpdateSecret creates or updates a Kubernetes secret.
func (*K8s) CreateOrUpdateTLSSecret ¶ added in v0.23.4
func (k *K8s) CreateOrUpdateTLSSecret(ctx context.Context, namespace, name string, conf GeneratedPKI) (*corev1.Secret, error)
CreateOrUpdateTLSSecret creates or updates a Kubernetes secret with a new TLS secret.
func (*K8s) DeleteNamespace ¶
DeleteNamespace deletes the given namespace from the cluster.
func (*K8s) DeletePods ¶ added in v0.30.1
DeletePods removes a collection of pods from the cluster by pod lookup.
func (*K8s) DeleteSecret ¶
DeleteSecret deletes a Kubernetes secret.
func (*K8s) FindPodContainerPort ¶ added in v0.30.0
FindPodContainerPort will find a pod's container port from a service and return it.
Returns 0 if no port is found.
func (*K8s) GeneratePod ¶
GeneratePod creates a new pod without adding it to the k8s cluster.
func (*K8s) GenerateSecret ¶
GenerateSecret returns a Kubernetes secret object without applying it to the cluster.
func (*K8s) GenerateTLSSecret ¶
GenerateTLSSecret returns a Kubernetes secret object without applying it to the cluster.
func (*K8s) GetAllPods ¶
GetAllPods returns a list of pods from the cluster for all namespaces.
func (*K8s) GetArchitectures ¶ added in v0.31.0
GetArchitectures returns the cluster system architectures if found.
func (*K8s) GetNamespaces ¶
GetNamespaces returns a list of namespaces in the cluster.
func (*K8s) GetPods ¶
func (k *K8s) GetPods(ctx context.Context, namespace string, listOpts metav1.ListOptions) (*corev1.PodList, error)
GetPods returns a list of pods from the cluster by namespace.
func (*K8s) GetSecretsWithLabel ¶
func (k *K8s) GetSecretsWithLabel(ctx context.Context, namespace, labelSelector string) (*corev1.SecretList, error)
GetSecretsWithLabel returns a list of Kubernetes secrets with the given label.
func (*K8s) GetServerVersion ¶ added in v0.29.0
GetServerVersion retrieves and returns the k8s revision.
func (*K8s) HandleDeprecations ¶ added in v0.28.0
func (k *K8s) HandleDeprecations(rawData *unstructured.Unstructured, kubernetesVersion semver.Version) (*unstructured.Unstructured, bool, error)
HandleDeprecations takes in an unstructured object and the version of kubernetes in a cluster and returns a converted version of that object and whether it was modified (if applicable)
func (*K8s) IsInitialNamespace ¶ added in v0.26.1
IsInitialNamespace returns true if the given namespace name is an initial k8s namespace: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#initial-namespaces
func (*K8s) NewTunnel ¶ added in v0.30.0
func (k *K8s) NewTunnel(namespace, resourceType, resourceName, urlSuffix string, local, remote int) (*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 (*K8s) RemoveLabelsAndAnnotations ¶ added in v0.32.0
func (k *K8s) RemoveLabelsAndAnnotations(ctx context.Context, resourceNamespace, resourceName string, groupKind schema.GroupKind, labels, annotations map[string]string) error
RemoveLabelsAndAnnotations removes the provided labels and annotations to the specified K8s resource
func (*K8s) UpdateNamespace ¶
func (k *K8s) UpdateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error)
UpdateNamespace updates the given namespace in the cluster.
func (*K8s) WaitForHealthyCluster ¶
WaitForHealthyCluster checks for an available K8s cluster every second until timeout.
func (*K8s) WaitForPodsAndContainers ¶
func (k *K8s) WaitForPodsAndContainers(ctx context.Context, target PodLookup, include PodFilter) []corev1.Pod
WaitForPodsAndContainers attempts to find pods matching the given selector and optional inclusion filter It will wait up to 90 seconds for the pods to be found and will return a list of matching pod names If the timeout is reached, an empty list will be returned.
type PodFilter ¶
PodFilter is a function that returns true if the pod should be targeted for data injection or lookups.
type PodLookup ¶
type PodLookup struct { Namespace string `json:"namespace" jsonschema:"description=The namespace to target for data injection"` Selector string `json:"selector" jsonschema:"description=The K8s selector to target for data injection"` Container string `json:"container" jsonschema:"description=The container to target for data injection"` }
PodLookup is a struct for specifying a pod to target for data injection or lookups.
type Tunnel ¶ added in v0.30.0
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 ¶ added in v0.30.0
func (tunnel *Tunnel) Close()
Close disconnects a tunnel connection by closing the StopChan, thereby stopping the goroutine.
func (*Tunnel) Endpoint ¶ added in v0.30.0
Endpoint returns the tunnel ip address and port (i.e. for docker registries)
func (*Tunnel) FullURL ¶ added in v0.30.0
FullURL returns the tunnel endpoint as a HTTP URL string with the urlSuffix appended.
func (*Tunnel) HTTPEndpoint ¶ added in v0.30.0
HTTPEndpoint returns the tunnel endpoint as a HTTP URL string.