k8s

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package k8s provides utility functions for working with Kubernetes clusters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clientset

func Clientset() *kubernetes.Clientset

Clientset returns the Kubernetes clientset.

func CreateDaemonSet added in v0.7.0

func CreateDaemonSet(namespace, name string, labels map[string]string, initContainers []v1.Container, containers []v1.Container) (*appv1.DaemonSet, error)

CreateDaemonSet creates a new daemonset.

func CreateNetworkPolicy added in v0.7.0

func CreateNetworkPolicy(namespace string, name string, selectorMap map[string]string, ingressSelectorMap map[string]string, egressSelectorMap map[string]string) error

CreateNetworkPolicy creates a new NetworkPolicy resource.

func DaemonSetExists added in v0.7.0

func DaemonSetExists(namespace, name string) (bool, error)

DaemonSetExists checks if a daemonset exists.

func DeleteDaemonSet added in v0.7.0

func DeleteDaemonSet(namespace, name string) error

DeleteDaemonSet deletes an existing daemonset.

func DeleteNetworkPolicy added in v0.7.0

func DeleteNetworkPolicy(namespace string, name string) error

DeleteNetworkPolicy removes a NetworkPolicy resource.

func DeletePersistentVolumeClaim

func DeletePersistentVolumeClaim(namespace, name string)

DeletePersistentVolumeClaim deletes the PersistentVolumeClaim with the specified name in the specified namespace.

func DeletePod

func DeletePod(namespace, name string) error

DeletePod deletes a pod with the given name in the specified namespace.

func DeletePodWithGracePeriod added in v0.7.0

func DeletePodWithGracePeriod(namespace, name string, gracePeriodSeconds *int64) error

DeletePodWithGracePeriod deletes a pod with the given name in the specified namespace.

func DeleteService

func DeleteService(namespace, name string) error

DeleteService deletes a service if it exists.

func DeployPersistentVolumeClaim

func DeployPersistentVolumeClaim(namespace, name string, labels map[string]string, size resource.Quantity)

DeployPersistentVolumeClaim creates a new PersistentVolumeClaim in the specified namespace.

func DeployPod

func DeployPod(podConfig PodConfig, init bool) (*v1.Pod, error)

DeployPod creates a new pod in the given namespace if it doesn't already exist.

func DeployService

func DeployService(namespace, name string, labels, selectorMap map[string]string, portsTCP []int, portsUDP []int) (*v1.Service, error)

DeployService deploys a service if it does not exist.

func GetDaemonSet added in v0.7.0

func GetDaemonSet(namespace, name string) (*appv1.DaemonSet, error)

GetDaemonSet retrieves a daemonset.

func GetService

func GetService(namespace, name string) (*v1.Service, error)

GetService retrieves a service.

func GetServiceIP

func GetServiceIP(namespace, name string) (string, error)

GetServiceIP retrieves the IP address of a service.

func Initialize

func Initialize() error

Initialize sets up the Kubernetes client with the appropriate configuration.

func IsInitialized added in v0.7.0

func IsInitialized() bool

IsInitialized checks if the Kubernetes clientset has been initialized.

func IsPodRunning added in v0.7.0

func IsPodRunning(namespace, name string) (bool, error)

IsPodRunning returns true if all containers in the pod are running.

func Namespace

func Namespace() string

Namespace returns the current namespace in use.

func PatchService

func PatchService(namespace, name string, labels, selectorMap map[string]string, portsTCP, portsUDP []int) error

PatchService patches an existing service.

func PortForwardPod added in v0.5.0

func PortForwardPod(namespace string, podName string, localPort int, remotePort int) error

PortForwardPod forwards a local port to a port on a pod.

func ReplacePod

func ReplacePod(podConfig PodConfig) (*v1.Pod, error)

ReplacePod replaces a pod in the given namespace and returns the new Pod object.

func ReplacePodWithGracePeriod added in v0.7.0

func ReplacePodWithGracePeriod(podConfig PodConfig, gracePeriod *int64) (*v1.Pod, error)

ReplacePodWithGracePeriod replaces a pod in the given namespace and returns the new Pod object with a grace period.

func RunCommandInPod

func RunCommandInPod(namespace, podName, containerName string, cmd []string) (string, error)

RunCommandInPod runs a command in a container within a pod.

func UpdateDaemonSet added in v0.7.0

func UpdateDaemonSet(namespace, name string, labels map[string]string, initContainers []v1.Container, containers []v1.Container) (*appv1.DaemonSet, error)

UpdateDaemonSet updates an existing daemonset.

Types

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
	Image         string            // Name of the Docker 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
}

PodConfig contains the specifications for creating a new Pod object

type Volume added in v0.7.2

type Volume struct {
	Path  string
	Size  string
	Owner int64
}

Volume represents a volume.

func NewVolume added in v0.7.2

func NewVolume(path, size string, owner int64) *Volume

NewVolume creates a new volume with the given path, size and owner.

Jump to

Keyboard shortcuts

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