Documentation ¶
Overview ¶
Package k8s provides utility functions for working with Kubernetes clusters.
Package k8s provides utility functions for working with Kubernetes clusters.
Index ¶
- Variables
- func SanitizeName(name string) string
- type Client
- func (c *Client) Clientset() *kubernetes.Clientset
- func (c *Client) ConfigMapExists(ctx context.Context, name string) (bool, error)
- func (c *Client) CreateConfigMap(ctx context.Context, name string, labels, data map[string]string) (*v1.ConfigMap, error)
- func (c *Client) CreateCustomResource(ctx context.Context, name string, gvr *schema.GroupVersionResource, ...) error
- func (c *Client) CreateDaemonSet(ctx context.Context, name string, labels map[string]string, ...) (*appv1.DaemonSet, error)
- func (c *Client) CreateNamespace(ctx context.Context, name string) error
- func (c *Client) CreateNetworkPolicy(ctx context.Context, name string, ...) error
- func (c *Client) CreatePersistentVolumeClaim(ctx context.Context, name string, labels map[string]string, ...) error
- func (c *Client) CreateReplicaSet(ctx context.Context, rsConfig ReplicaSetConfig, init bool) (*appv1.ReplicaSet, error)
- func (c *Client) CreateRole(ctx context.Context, name string, labels map[string]string, ...) error
- func (c *Client) CreateRoleBinding(ctx context.Context, name string, labels map[string]string, ...) error
- func (c *Client) CreateService(ctx context.Context, name string, labels, selectorMap map[string]string, ...) (*v1.Service, error)
- func (c *Client) CreateServiceAccount(ctx context.Context, name string, labels map[string]string) error
- func (c *Client) CustomResourceDefinitionExists(ctx context.Context, gvr *schema.GroupVersionResource) bool
- func (c *Client) DaemonSetExists(ctx context.Context, name string) (bool, error)
- func (c *Client) DeleteConfigMap(ctx context.Context, name string) error
- func (c *Client) DeleteDaemonSet(ctx context.Context, name string) error
- func (c *Client) DeleteNamespace(ctx context.Context, name string) error
- func (c *Client) DeleteNetworkPolicy(ctx context.Context, name string) error
- func (c *Client) DeletePersistentVolumeClaim(ctx context.Context, name string) error
- func (c *Client) DeletePod(ctx context.Context, name string) error
- func (c *Client) DeletePodWithGracePeriod(ctx context.Context, name string, gracePeriodSeconds *int64) error
- func (c *Client) DeleteReplicaSet(ctx context.Context, name string) error
- func (c *Client) DeleteReplicaSetWithGracePeriod(ctx context.Context, name string, gracePeriodSeconds *int64) error
- func (c *Client) DeleteRole(ctx context.Context, name string) error
- func (c *Client) DeleteRoleBinding(ctx context.Context, name string) error
- func (c *Client) DeleteService(ctx context.Context, name string) error
- func (c *Client) DeleteServiceAccount(ctx context.Context, name string) error
- func (c *Client) DeployPod(ctx context.Context, podConfig PodConfig, init bool) (*v1.Pod, error)
- func (c *Client) GetConfigMap(ctx context.Context, name string) (*v1.ConfigMap, error)
- func (c *Client) GetDaemonSet(ctx context.Context, name string) (*appv1.DaemonSet, error)
- func (c *Client) GetFirstPodFromReplicaSet(ctx context.Context, name string) (*v1.Pod, error)
- func (c *Client) GetNamespace(ctx context.Context, name string) (*corev1.Namespace, error)
- func (c *Client) GetNetworkPolicy(ctx context.Context, name string) (*v1.NetworkPolicy, error)
- func (c *Client) GetService(ctx context.Context, name string) (*v1.Service, error)
- func (c *Client) GetServiceIP(ctx context.Context, name string) (string, error)
- func (c *Client) IsPodRunning(ctx context.Context, name string) (bool, error)
- func (c *Client) IsReplicaSetRunning(ctx context.Context, name string) (bool, error)
- func (c *Client) Namespace() string
- func (c *Client) NamespaceExists(ctx context.Context, name string) bool
- func (c *Client) NetworkPolicyExists(ctx context.Context, name string) bool
- func (c *Client) NewFile(source, dest string) *File
- func (c *Client) NewVolume(path, size string, owner int64) *Volume
- func (c *Client) PatchService(ctx context.Context, name string, labels, selectorMap map[string]string, ...) (*v1.Service, error)
- func (c *Client) PortForwardPod(ctx context.Context, podName string, localPort, remotePort int) error
- func (c *Client) ReplacePod(ctx context.Context, podConfig PodConfig) (*v1.Pod, error)
- func (c *Client) ReplacePodWithGracePeriod(ctx context.Context, podConfig PodConfig, gracePeriod *int64) (*v1.Pod, error)
- func (c *Client) ReplaceReplicaSet(ctx context.Context, ReplicaSetConfig ReplicaSetConfig) (*appv1.ReplicaSet, error)
- func (c *Client) ReplaceReplicaSetWithGracePeriod(ctx context.Context, ReplicaSetConfig ReplicaSetConfig, gracePeriod *int64) (*appv1.ReplicaSet, error)
- func (c *Client) ReplicaSetExists(ctx context.Context, name string) (bool, error)
- func (c *Client) RunCommandInPod(ctx context.Context, podName, containerName string, cmd []string) (string, error)
- func (c *Client) UpdateDaemonSet(ctx context.Context, name string, labels map[string]string, ...) (*appv1.DaemonSet, error)
- type ContainerConfig
- type Error
- type File
- type PodConfig
- type ReplicaSetConfig
- type Volume
Constants ¶
This section is empty.
Variables ¶
var ( ErrKnuuNotInitialized = &Error{Code: "KnuuNotInitialized", Message: "knuu is not initialized"} ErrGettingConfigmap = &Error{Code: "ErrorGettingConfigmap", Message: "error getting configmap %s"} ErrConfigmapAlreadyExists = &Error{Code: "ConfigmapAlreadyExists", Message: "configmap %s already exists"} ErrCreatingConfigmap = &Error{Code: "ErrorCreatingConfigmap", Message: "error creating configmap %s"} ErrConfigmapDoesNotExist = &Error{Code: "ConfigmapDoesNotExist", Message: "configmap %s does not exist"} ErrDeletingConfigmap = &Error{Code: "ErrorDeletingConfigmap", Message: "error deleting configmap %s"} ErrGettingDaemonset = &Error{Code: "ErrorGettingDaemonset", Message: "error getting daemonset %s"} ErrCreatingDaemonset = &Error{Code: "ErrorCreatingDaemonset", Message: "error creating daemonset %s"} ErrUpdatingDaemonset = &Error{Code: "ErrorUpdatingDaemonset", Message: "error updating daemonset %s"} ErrDeletingDaemonset = &Error{Code: "ErrorDeletingDaemonset", Message: "error deleting daemonset %s"} ErrCreatingNamespace = &Error{Code: "ErrorCreatingNamespace", Message: "error creating namespace %s"} ErrDeletingNamespace = &Error{Code: "ErrorDeletingNamespace", Message: "error deleting namespace %s"} ErrGettingNamespace = &Error{Code: "ErrorGettingNamespace", Message: "error getting namespace %s"} ErrCreatingNetworkPolicy = &Error{Code: "ErrorCreatingNetworkPolicy", Message: "error creating network policy %s"} ErrDeletingNetworkPolicy = &Error{Code: "ErrorDeletingNetworkPolicy", Message: "error deleting network policy %s"} ErrGettingNetworkPolicy = &Error{Code: "ErrorGettingNetworkPolicy", Message: "error getting network policy %s"} ErrGettingPod = &Error{Code: "ErrorGettingPod", Message: "failed to get pod %s"} ErrPreparingPod = &Error{Code: "ErrorPreparingPod", Message: "error preparing pod"} ErrCreatingPod = &Error{Code: "ErrorCreatingPod", Message: "failed to create pod"} ErrDeletingPod = &Error{Code: "ErrorDeletingPod", Message: "failed to delete pod"} ErrDeployingPod = &Error{Code: "ErrorDeployingPod", Message: "failed to deploy pod"} ErrGettingK8sConfig = &Error{Code: "ErrorGettingK8sConfig", Message: "failed to get k8s config"} ErrCreatingExecutor = &Error{Code: "ErrorCreatingExecutor", Message: "failed to create Executor"} ErrExecutingCommand = &Error{Code: "ErrorExecutingCommand", Message: "failed to execute command"} ErrCommandExecution = &Error{Code: "ErrorCommandExecution", Message: "error while executing command"} ErrDeletingPodFailed = &Error{Code: "ErrorDeletingPodFailed", Message: "failed to delete pod %s"} ErrParsingMemoryRequest = &Error{Code: "ErrorParsingMemoryRequest", Message: "failed to parse memory request quantity '%s'"} ErrParsingMemoryLimit = &Error{Code: "ErrorParsingMemoryLimit", Message: "failed to parse memory limit quantity '%s'"} ErrParsingCPURequest = &Error{Code: "ErrorParsingCPURequest", Message: "failed to parse CPU request quantity '%s'"} ErrBuildingContainerVolumes = &Error{Code: "ErrorBuildingContainerVolumes", Message: "failed to build container volumes"} ErrBuildingResources = &Error{Code: "ErrorBuildingResources", Message: "failed to build resources"} ErrBuildingInitContainerVolumes = &Error{Code: "ErrorBuildingInitContainerVolumes", Message: "failed to build init container volumes"} ErrBuildingInitContainerCommand = &Error{Code: "ErrorBuildingInitContainerCommand", Message: "failed to build init container command"} ErrBuildingPodVolumes = &Error{Code: "ErrorBuildingPodVolumes", Message: "failed to build pod volumes"} ErrPreparingMainContainer = &Error{Code: "ErrorPreparingMainContainer", Message: "failed to prepare main container"} ErrPreparingInitContainer = &Error{Code: "ErrorPreparingInitContainer", Message: "failed to prepare init container"} ErrPreparingPodVolumes = &Error{Code: "ErrorPreparingPodVolumes", Message: "failed to prepare pod volumes"} ErrPreparingSidecarContainer = &Error{Code: "ErrorPreparingSidecarContainer", Message: "failed to prepare sidecar container"} ErrPreparingSidecarVolumes = &Error{Code: "ErrorPreparingSidecarVolumes", Message: "failed to prepare sidecar volumes"} ErrCreatingPodSpec = &Error{Code: "ErrorCreatingPodSpec", Message: "failed to create pod spec"} ErrGettingClusterConfig = &Error{Code: "ErrorGettingClusterConfig", Message: "failed to get cluster config"} ErrCreatingRoundTripper = &Error{Code: "ErrorCreatingRoundTripper", Message: "failed to create round tripper"} ErrCreatingPortForwarder = &Error{Code: "ErrorCreatingPortForwarder", Message: "failed to create port forwarder"} ErrPortForwarding = &Error{Code: "ErrorPortForwarding", Message: "failed to port forward: %v"} ErrForwardingPorts = &Error{Code: "ErrorForwardingPorts", Message: "error forwarding ports"} ErrPortForwardingTimeout = &Error{Code: "ErrorPortForwardingTimeout", Message: "timed out waiting for port forwarding to be ready"} ErrDeletingPersistentVolumeClaim = &Error{Code: "ErrorDeletingPersistentVolumeClaim", Message: "error deleting PersistentVolumeClaim %s"} ErrCreatingPersistentVolumeClaim = &Error{Code: "ErrorCreatingPersistentVolumeClaim", Message: "error creating PersistentVolumeClaim"} ErrGettingReplicaSet = &Error{Code: "ErrorGettingReplicaSet", Message: "failed to get ReplicaSet %s"} ErrCreatingReplicaSet = &Error{Code: "ErrorCreatingReplicaSet", Message: "failed to create ReplicaSet"} ErrDeletingReplicaSet = &Error{Code: "ErrorDeletingReplicaSet", Message: "failed to delete ReplicaSet %s"} ErrCheckingReplicaSetExists = &Error{Code: "ErrorCheckingReplicaSetExists", Message: "failed to check if ReplicaSet %s exists"} ErrWaitingForReplicaSet = &Error{Code: "ErrorWaitingForReplicaSet", Message: "error waiting for ReplicaSet to delete"} ErrDeployingReplicaSet = &Error{Code: "ErrorDeployingReplicaSet", Message: "failed to deploy ReplicaSet"} ErrPreparingPodSpec = &Error{Code: "ErrorPreparingPodSpec", Message: "failed to prepare pod spec"} ErrListingPodsForReplicaSet = &Error{Code: "ErrorListingPodsForReplicaSet", Message: "failed to list pods for ReplicaSet %s"} ErrNoPodsForReplicaSet = &Error{Code: "NoPodsForReplicaSet", Message: "no pods found for ReplicaSet %s"} ErrGettingService = &Error{Code: "ErrorGettingService", Message: "error getting service %s"} ErrPreparingService = &Error{Code: "ErrorPreparingService", Message: "error preparing service %s"} ErrCreatingService = &Error{Code: "ErrorCreatingService", Message: "error creating service %s"} ErrPatchingService = &Error{Code: "ErrorPatchingService", Message: "error patching service %s"} ErrDeletingService = &Error{Code: "ErrorDeletingService", Message: "error deleting service %s"} ErrNamespaceRequired = &Error{Code: "NamespaceRequired", Message: "namespace is required"} ErrServiceNameRequired = &Error{Code: "ServiceNameRequired", Message: "service name is required"} ErrNoPortsSpecified = &Error{Code: "NoPortsSpecified", Message: "no ports specified for service %s"} ErrRetrievingKubernetesConfig = &Error{Code: "RetrievingKubernetesConfig", Message: "retrieving the Kubernetes config"} ErrCreatingClientset = &Error{Code: "CreatingClientset", Message: "creating clientset for Kubernetes"} ErrCreatingDiscoveryClient = &Error{Code: "CreatingDiscoveryClient", Message: "creating discovery client for Kubernetes"} ErrCreatingDynamicClient = &Error{Code: "CreatingDynamicClient", Message: "creating dynamic client for Kubernetes"} ErrGettingResourceList = &Error{Code: "GettingResourceList", Message: "getting resource list for group version %s"} ErrResourceDoesNotExist = &Error{Code: "ResourceDoesNotExist", Message: "resource %s does not exist in group version %s"} ErrCreatingCustomResource = &Error{Code: "CreatingCustomResource", Message: "creating custom resource %s"} )
Functions ¶
func SanitizeName ¶ added in v0.13.2
SanitizeName ensures compliance with Kubernetes DNS-1123 subdomain names. It:
- Converts the input string to lowercase.
- Replaces underscores and any non-DNS-1123 compliant characters with hyphens.
- Trims leading and trailing hyphens.
- Ensures the name does not exceed 63 characters, trimming excess characters if necessary and ensuring it does not end with a hyphen after trimming.
Use this function to sanitize strings to be used as Kubernetes names for resources.
Types ¶
type Client ¶ added in v0.13.3
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Clientset ¶ added in v0.13.3
func (c *Client) Clientset() *kubernetes.Clientset
func (*Client) ConfigMapExists ¶ added in v0.13.3
func (*Client) CreateConfigMap ¶ added in v0.13.3
func (*Client) CreateCustomResource ¶ added in v0.13.3
func (*Client) CreateDaemonSet ¶ added in v0.13.3
func (*Client) CreateNamespace ¶ added in v0.13.3
func (*Client) CreateNetworkPolicy ¶ added in v0.13.3
func (*Client) CreatePersistentVolumeClaim ¶ added in v0.13.3
func (c *Client) CreatePersistentVolumeClaim( ctx context.Context, name string, labels map[string]string, size resource.Quantity, ) error
CreatePersistentVolumeClaim deploys a PersistentVolumeClaim if it does not exist.
func (*Client) CreateReplicaSet ¶ added in v0.13.3
func (c *Client) CreateReplicaSet(ctx context.Context, rsConfig ReplicaSetConfig, init bool) (*appv1.ReplicaSet, error)
CreateReplicaSet creates a new replicaSet in namespace that k8s is initialized with if it doesn't already exist.
func (*Client) CreateRole ¶ added in v0.13.3
func (*Client) CreateRoleBinding ¶ added in v0.13.3
func (*Client) CreateService ¶ added in v0.13.3
func (*Client) CreateServiceAccount ¶ added in v0.13.3
func (*Client) CustomResourceDefinitionExists ¶ added in v0.13.3
func (*Client) DaemonSetExists ¶ added in v0.13.3
func (*Client) DeleteConfigMap ¶ added in v0.13.3
func (*Client) DeleteDaemonSet ¶ added in v0.13.3
func (*Client) DeleteNamespace ¶ added in v0.13.3
func (*Client) DeleteNetworkPolicy ¶ added in v0.13.3
func (*Client) DeletePersistentVolumeClaim ¶ added in v0.13.3
func (*Client) DeletePodWithGracePeriod ¶ added in v0.13.3
func (*Client) DeleteReplicaSet ¶ added in v0.13.3
func (*Client) DeleteReplicaSetWithGracePeriod ¶ added in v0.13.3
func (*Client) DeleteRole ¶ added in v0.13.3
func (*Client) DeleteRoleBinding ¶ added in v0.13.3
func (*Client) DeleteService ¶ added in v0.13.3
func (*Client) DeleteServiceAccount ¶ added in v0.13.3
func (*Client) DeployPod ¶ added in v0.13.3
DeployPod creates a new pod in the namespace that k8s client is initiate with if it doesn't already exist.
func (*Client) GetConfigMap ¶ added in v0.13.3
func (*Client) GetDaemonSet ¶ added in v0.13.3
func (*Client) GetFirstPodFromReplicaSet ¶ added in v0.13.3
func (*Client) GetNamespace ¶ added in v0.13.3
func (*Client) GetNetworkPolicy ¶ added in v0.13.3
func (*Client) GetService ¶ added in v0.13.3
func (*Client) GetServiceIP ¶ added in v0.13.3
func (*Client) IsPodRunning ¶ added in v0.13.3
IsPodRunning returns true if all containers in the pod are running.
func (*Client) IsReplicaSetRunning ¶ added in v0.13.3
func (*Client) NamespaceExists ¶ added in v0.13.3
func (*Client) NetworkPolicyExists ¶ added in v0.13.3
func (*Client) PatchService ¶ added in v0.13.3
func (*Client) PortForwardPod ¶ added in v0.13.3
func (c *Client) PortForwardPod( ctx context.Context, podName string, localPort, remotePort int, ) error
PortForwardPod forwards a local port to a port on a pod.
func (*Client) ReplacePod ¶ added in v0.13.3
ReplacePod replaces a pod and returns the new Pod object.
func (*Client) ReplacePodWithGracePeriod ¶ added in v0.13.3
func (*Client) ReplaceReplicaSet ¶ added in v0.13.3
func (c *Client) ReplaceReplicaSet(ctx context.Context, ReplicaSetConfig ReplicaSetConfig) (*appv1.ReplicaSet, error)
func (*Client) ReplaceReplicaSetWithGracePeriod ¶ added in v0.13.3
func (c *Client) ReplaceReplicaSetWithGracePeriod(ctx context.Context, ReplicaSetConfig ReplicaSetConfig, gracePeriod *int64) (*appv1.ReplicaSet, error)
func (*Client) ReplicaSetExists ¶ added in v0.13.3
ReplicaSetExists checks if a ReplicaSet exists in the namespace that k8s is initialized with.
type ContainerConfig ¶ added in v0.9.0
type ContainerConfig struct { Name string // Name to assign to the Container Image string // Name of the container image to use for the container Command []string // Command to run in the container Args []string // Arguments to pass to the command in the container Env map[string]string // Environment variables to set in the container Volumes []*Volume // Volumes to mount in the Pod MemoryRequest string // Memory request for the container MemoryLimit string // Memory limit for the container CPURequest string // CPU request for the container LivenessProbe *v1.Probe // Liveness probe for the container ReadinessProbe *v1.Probe // Readiness probe for the container StartupProbe *v1.Probe // Startup probe for the container Files []*File // Files to add to the Pod SecurityContext *v1.SecurityContext // Security context for the container }
type Error ¶ added in v0.13.3
func (*Error) WithParams ¶ added in v0.13.3
type PodConfig ¶
type PodConfig struct { Namespace string // Kubernetes namespace of the Pod Name string // Name to assign to the Pod Labels map[string]string // Labels to apply to the Pod ServiceAccountName string // ServiceAccount to assign to Pod FsGroup int64 // FSGroup to apply to the Pod ContainerConfig ContainerConfig // ContainerConfig for the Pod SidecarConfigs []ContainerConfig // SideCarConfigs for the Pod }
type ReplicaSetConfig ¶ added in v0.12.0
type ReplicaSetConfig struct { Name string // Name of the ReplicaSet Namespace string // Namespace of the ReplicaSet Labels map[string]string // Labels to apply to the ReplicaSet, key/value represents the name/value of the label Replicas int32 // Replicas is the number of replicas PodConfig PodConfig // PodConfig represents the pod configuration }