k8s

package
v0.24.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

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.

Package k8s provides a client for interacting with a Kubernetes cluster.

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

List of supported distros via distro detection.

Variables

This section is empty.

Functions

func SortImages

func SortImages(images, compareWith ImageMap) []string

SortImages returns a sorted list of images.

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 ImageMap

type ImageMap map[string]bool

ImageMap is a map of image/boolean pairs.

func BuildImageMap

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

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

type ImageNodeMap

type ImageNodeMap map[string][]string

ImageNodeMap is a map of image/node pairs.

type K8s

type K8s struct {
	Clientset  *kubernetes.Clientset
	RestConfig *rest.Config
	Log        Log
	Labels     Labels
}

K8s is a client for interacting with a Kubernetes cluster.

func New

func New(logger Log, defaultLabels Labels) (*K8s, error)

New creates a new K8s client.

func NewWithWait

func NewWithWait(logger Log, defaultLabels Labels, timeout time.Duration) (*K8s, error)

NewWithWait is a convenience function that creates a new K8s client and waits for the cluster to be healthy.

func (*K8s) CreateConfigmap

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

CreateConfigmap applies a configmap to the cluster.

func (*K8s) CreateNamespace

func (k *K8s) CreateNamespace(name string, 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(secret *corev1.Secret) error

CreateOrUpdateSecret creates or updates a Kubernetes secret.

func (*K8s) CreateOrUpdateTLSSecret added in v0.23.4

func (k *K8s) CreateOrUpdateTLSSecret(namespace, name string, conf GeneratedPKI) error

CreateOrUpdateTLSSecret creates or updates a Kubernetes secret with a new TLS secret.

func (*K8s) CreatePod

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

CreatePod inserts the given pod into the cluster.

func (*K8s) CreateSecret

func (k *K8s) CreateSecret(secret *corev1.Secret) error

CreateSecret creates a Kubernetes secret.

func (*K8s) CreateService

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

CreateService creates the given service in the cluster.

func (*K8s) DeleteConfigMapsByLabel

func (k *K8s) DeleteConfigMapsByLabel(namespace string, labels Labels) error

DeleteConfigMapsByLabel deletes a configmap by label(s).

func (*K8s) DeleteConfigmap

func (k *K8s) DeleteConfigmap(namespace, name string) error

DeleteConfigmap deletes a configmap by name.

func (*K8s) DeleteNamespace

func (k *K8s) DeleteNamespace(ctx context.Context, name string) error

DeleteNamespace deletes the given namespace from the cluster.

func (*K8s) DeletePod

func (k *K8s) DeletePod(namespace string, name string) error

DeletePod removes a pod from the cluster by namespace & name.

func (*K8s) DeleteSecret

func (k *K8s) DeleteSecret(secret *corev1.Secret) error

DeleteSecret deletes a Kubernetes secret.

func (*K8s) DeleteService

func (k *K8s) DeleteService(namespace, name string) error

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

func (*K8s) DetectDistro

func (k *K8s) DetectDistro() (string, error)

DetectDistro returns the matching distro or unknown if not found.

func (*K8s) GeneratePod

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

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

func (*K8s) GenerateSecret

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

GenerateSecret returns a Kubernetes secret object without applying it to the cluster.

func (*K8s) GenerateService

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

GenerateService returns a K8s service struct without writing to the cluster.

func (*K8s) GenerateTLSSecret

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

GenerateTLSSecret returns a Kubernetes secret object without applying it to the cluster.

func (*K8s) GetAllImages

func (k *K8s) GetAllImages() (ImageNodeMap, error)

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

func (*K8s) GetAllPods

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

GetAllPods returns a list of pods from the cluster for all namespaces.

func (*K8s) GetAllServiceAccounts

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

GetAllServiceAccounts returns a list of services accounts for all namespaces.

func (*K8s) GetArchitecture

func (k *K8s) GetArchitecture() (string, error)

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

func (*K8s) GetImagesWithNodes

func (k *K8s) GetImagesWithNodes(namespace string) (ImageNodeMap, error)

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

func (*K8s) GetNamespaces

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

GetNamespaces returns a list of namespaces in the cluster.

func (*K8s) GetNodes

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

GetNodes returns a list of nodes from the k8s cluster.

func (*K8s) GetPods

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

GetPods returns a list of pods from the cluster by namespace.

func (*K8s) GetSecret

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

GetSecret returns a Kubernetes secret.

func (*K8s) GetSecretsWithLabel

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

GetSecretsWithLabel returns a list of Kubernetes secrets with the given label.

func (*K8s) GetService

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

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

func (*K8s) GetServiceAccount

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

GetServiceAccount returns a single service account by namespace and name.

func (*K8s) GetServiceAccounts

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

GetServiceAccounts returns a list of service accounts in a given namespace.

func (*K8s) GetServicesByLabel

func (k *K8s) 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 (*K8s) GetServicesByLabelExists

func (k *K8s) 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 (*K8s) ReplaceConfigmap

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

ReplaceConfigmap deletes and recreates a configmap.

func (*K8s) ReplaceService

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

ReplaceService deletes and re-creates a service.

func (*K8s) SaveServiceAccount

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

SaveServiceAccount updates the given service account in the cluster.

func (*K8s) UpdateNamespace

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

UpdateNamespace updates the given namespace in the cluster.

func (*K8s) WaitForHealthyCluster

func (k *K8s) WaitForHealthyCluster(timeout time.Duration) error

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

func (*K8s) WaitForPodsAndContainers

func (k *K8s) WaitForPodsAndContainers(target PodLookup, include PodFilter) []string

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 Labels

type Labels map[string]string

Labels is a map of K8s labels.

type Log

type Log func(string, ...any)

Log is a function that logs a message.

type PodFilter

type PodFilter func(pod corev1.Pod) bool

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.

Jump to

Keyboard shortcuts

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