k8s

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 44 Imported by: 17

Documentation

Overview

Copyright (C) 2021-2023, Kubefirst

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

This program is licensed under MIT. See the LICENSE file for more details.

Index

Constants

This section is empty.

Variables

View Source
var GitlabSecretClient coreV1Types.SecretInterface

Functions

func CheckForExistingPortForwards

func CheckForExistingPortForwards(ports ...int) error

CheckForExistingPortForwards determines whether or not port forwards are already running

func CreateSecretV2

func CreateSecretV2(clientset *kubernetes.Clientset, secret *v1.Secret) error

CreateSecretV2 creates a Kubernetes Secret

func GetClientConfig

func GetClientConfig(kubeconfigPath string) (*rest.Config, error)

GetClientConfig returns a rest.Config object for working with the Kubernetes API

func GetClientSet

func GetClientSet(kubeconfigPath string) (*kubernetes.Clientset, error)

GetClientSet - Get reference to k8s credentials to use APIS

func GetSecretValue

func GetSecretValue(k8sClient coreV1Types.SecretInterface, secretName, key string) string

func OpenPortForwardPodWrapper

func OpenPortForwardPodWrapper(
	clientset *kubernetes.Clientset,
	restConfig *rest.Config,
	podName string,
	namespace string,
	podPort int,
	podLocalPort int,
	stopChannel chan struct{},
)

OpenPortForwardPodWrapper wrapper for PortForwardPod function. This functions make it easier to open and close port forward request. By providing the function parameters, the function will manage to create the port forward. The parameter for the stopChannel controls when the port forward must be closed.

Example:

vaultStopChannel := make(chan struct{}, 1)
go func() {
	OpenPortForwardWrapper(
		pkg.VaultPodName,
		pkg.VaultNamespace,
		pkg.VaultPodPort,
		pkg.VaultPodLocalPort,
		vaultStopChannel)
	wg.Done()
}()

func PodExecSession

func PodExecSession(kubeConfigPath string, p *PodSessionOptions, silent bool) error

PodExecSession executes a command against a Pod

func PortForwardPod

func PortForwardPod(clientset *kubernetes.Clientset, req PortForwardAPodRequest) error

PortForwardPod receives a PortForwardAPodRequest, and enables port forwarding for the specified resource. If the provided Pod name matches a running Pod, it will try to port forward for that Pod on the specified port.

func PortForwardPodWithRetry

func PortForwardPodWithRetry(clientset *kubernetes.Clientset, req PortForwardAPodRequest) error

func ReadConfigMapV2

func ReadConfigMapV2(kubeConfigPath string, namespace string, configMapName string) (map[string]string, error)

ReadConfigMapV2 reads the content of a Kubernetes ConfigMap

func ReadSecretV2

func ReadSecretV2(clientset *kubernetes.Clientset, namespace string, secretName string) (map[string]string, error)

ReadSecretV2 reads the content of a Kubernetes Secret

func ReadService

func ReadService(kubeConfigPath string, namespace string, serviceName string) (*v1.Service, error)

ReadService reads a Kubernetes Service object

func ReturnDeploymentObject

func ReturnDeploymentObject(clientset *kubernetes.Clientset, matchLabel string, matchLabelValue string, namespace string, timeoutSeconds int) (*appsv1.Deployment, error)

ReturnDeploymentObject returns a matching appsv1.Deployment object based on the filters

func ReturnJobObject

func ReturnJobObject(clientset *kubernetes.Clientset, namespace string, jobName string) (*batchv1.Job, error)

ReturnJobObject returns a matching appsv1.StatefulSet object based on the filters

func ReturnPodObject

func ReturnPodObject(kubeConfigPath string, matchLabel string, matchLabelValue string, namespace string, timeoutSeconds int) (*v1.Pod, error)

ReturnPodObject returns a matching v1.Pod object based on the filters

func ReturnStatefulSetObject

func ReturnStatefulSetObject(clientset *kubernetes.Clientset, matchLabel string, matchLabelValue string, namespace string, timeoutSeconds int) (*appsv1.StatefulSet, error)

ReturnStatefulSetObject returns a matching appsv1.StatefulSet object based on the filters

func VerifyArgoCDReadiness

func VerifyArgoCDReadiness(clientset *kubernetes.Clientset, highAvailabilityEnabled bool, timeoutSeconds int) (bool, error)

VerifyArgoCDReadiness waits for critical resources within ArgoCD to be ready and only returns once they're all healthy

This helps prevent race conditions and timeouts

func WaitForDeploymentReady

func WaitForDeploymentReady(clientset *kubernetes.Clientset, deployment *appsv1.Deployment, timeoutSeconds int) (bool, error)

WaitForDeploymentReady waits for a target Deployment to become ready

func WaitForJobComplete

func WaitForJobComplete(clientset *kubernetes.Clientset, job *batchv1.Job, timeoutSeconds int64) (bool, error)

WaitForJobComplete waits for a target Job to reach completion

func WaitForNamespaceandPods

func WaitForNamespaceandPods(kubeconfigPath, kubectlClientPath, namespace, podLabel string)

func WaitForPodReady

func WaitForPodReady(clientset *kubernetes.Clientset, pod *v1.Pod, timeoutSeconds int) (bool, error)

WaitForPodReady waits for a target Pod to become ready

func WaitForStatefulSetReady

func WaitForStatefulSetReady(clientset *kubernetes.Clientset, statefulset *appsv1.StatefulSet, timeoutSeconds int, ignoreReady bool) (bool, error)

WaitForStatefulSetReady waits for a target StatefulSet to become ready

Types

type KubernetesClient

type KubernetesClient struct {
	Clientset      *kubernetes.Clientset
	RestConfig     *rest.Config
	KubeConfigPath string
}

func CreateKubeConfig

func CreateKubeConfig(inCluster bool, kubeConfigPath string) *KubernetesClient

CreateKubeConfig returns a struct KubernetesClient with references to a clientset, restConfig, and path to the Kubernetes config used to generate the client

func (KubernetesClient) ApplyObjects

func (kcl KubernetesClient) ApplyObjects(namespace string, yamlData [][]byte) error

ApplyObjects parses a structured Kubernetes-compatible yaml file and applies its objects to a target Kubernetes cluster

func (KubernetesClient) KustomizeBuild

func (kcl KubernetesClient) KustomizeBuild(kustomizationDirectory string) (*bytes.Buffer, error)

KustomizeBuild parses a file path and returns manifests built via kustomization.yaml if present

kustomizationDirectory should be a directory containing a kustomization.yaml file and subsequent configuration

The return values is a string representation of parsed resources in yaml

func (KubernetesClient) ReadYAMLFile

func (kcl KubernetesClient) ReadYAMLFile(filepath string) (string, error)

ReadYAMLFile reads a yaml file in the filesystem

func (KubernetesClient) SplitYAMLFile

func (kcl KubernetesClient) SplitYAMLFile(yamlData *bytes.Buffer) ([][]byte, error)

SplitYAMLFile takes a separated (---) yaml doc and returns [][]byte

type PatchJson

type PatchJson struct {
	Op   string `json:"op"`
	Path string `json:"path"`
}

type PodSessionOptions

type PodSessionOptions struct {
	Command    []string
	Namespace  string
	PodName    string
	Stdin      bool
	Stdout     bool
	Stderr     bool
	TtyEnabled bool
}

podSessionOptions provides a struct to assign parameters to an exec session

type PortForwardAPodRequest

type PortForwardAPodRequest struct {
	// RestConfig is the kubernetes config
	RestConfig *rest.Config
	// Pod is the selected pod for this port forwarding
	Pod v1.Pod
	// LocalPort is the local port that will be selected to expose the PodPort
	LocalPort int
	// PodPort is the target port for the pod
	PodPort int

	// StopCh is the channel used to manage the port forward lifecycle
	StopCh <-chan struct{}
	// ReadyCh communicates when the tunnel is ready to receive traffic
	ReadyCh chan struct{}
}

type PortForwardAServiceRequest

type PortForwardAServiceRequest struct {
	// RestConfig is the kubernetes config
	RestConfig *rest.Config
	// Service is the selected service for this port forwarding
	Service v1.Service
	// LocalPort is the local port that will be selected to expose the ServicePort
	LocalPort int
	// ServicePort is the target port for the service
	ServicePort int

	// StopCh is the channel used to manage the port forward lifecycle
	StopCh <-chan struct{}
	// ReadyCh communicates when the tunnel is ready to receive traffic
	ReadyCh chan struct{}
}

Jump to

Keyboard shortcuts

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