k8s

package
v1.1.5-release Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Provide K8S Client to be able to operate directly with K8S. For example to do exec cmd on a pod. Usage sample :

  clientset, cfg := k8s.MustNewKubeClientAndConfig()
	 sdtout, stderr,err := k8s.ExecPodFromName(clientset.(*kubernetes.Clientset),cfg,capi.Namespace,nodename,killCmd)
	 if err!=nil {
		logrus.Errorf("Error when run cmd to pod %s", nodename)
		return fmt.Errorf("failed execute command on pods: %v", err)
	 }

Index

Constants

This section is empty.

Variables

View Source
var ReLabelTime = regexp.MustCompile(`(?P<y>\d{4})(?P<m>\d{2})(?P<d>\d{2})T(?P<hh>\d{2})(?P<mm>\d{2})(?P<ss>\d{2})`)

Regex to extract date from label

Functions

func AddOwnerRefToObject

func AddOwnerRefToObject(o metav1.Object, r metav1.OwnerReference)

addOwnerRefToObject appends the desired OwnerReference to the object

func AsOwner

asOwner returns an owner reference set as the cassandra cluster CRD

func ContainSlice

func ContainSlice(ref []string, n []string) bool

ContainSlice return true if each element of n exists in ref

func Contains

func Contains(s []string, e string) bool

func DCRackLabelsAndNodeSelectorForStatefulSet

func DCRackLabelsAndNodeSelectorForStatefulSet(cc *api.CassandraCluster, dc int, rack int) (map[string]string, map[string]string)

DCRackLabelsAndNodeSelectorForStatefulSet function return a map with the labels DC & Rack to deploy on the statefulset. dc and int are the indice of respectively the dc and the rack in the CassandraCluster configuration

func ExecPod

func ExecPod(namespace string, pod *corev1.Pod, cmd []string) (string, string, error)

inspiration https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/exec.go func ExecPod(clientset *kubernetes.Clientset, cfg *rest.Config, namespace string, pod *corev1.Pod, cmd []string) (string, string, error) {

func ExecPodFromName

func ExecPodFromName(namespace string, name string, cmd []string) (string, string, error)

inspiration https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/exec.go func ExecPodFromName(clientset *kubernetes.Clientset, cfg *rest.Config, namespace string, name string, cmd []string) (string, string, error) {

func InitClient

func InitClient()

InitClient allow to setup an additional client to kubernetes API while operator-sdk don't gives us access to oit

func IsMarkedForDeletion

func IsMarkedForDeletion(m metav1.ObjectMeta) bool

IsMarkedForDeletion determines if the object is marked for deletion

func LabelTime

func LabelTime() string

LabelTime returns a supported label string containing the current date and time

func LabelTime2Time

func LabelTime2Time(label string) (time.Time, error)

LabelTime2Time converts a label string containing a time into a Time

func LabelsForCassandra

func LabelsForCassandra(cc *api.CassandraCluster) map[string]string

func LabelsForCassandraDC

func LabelsForCassandraDC(cc *api.CassandraCluster, dcName string) map[string]string

func LabelsForCassandraDCRack

func LabelsForCassandraDCRack(cc *api.CassandraCluster, dcName string, rackName string) map[string]string

labelsForCassandra returns the labels for selecting the resources belonging to the given name.

func LookupCassandraBackup

func LookupCassandraBackup(client runtimeClient.Client, backupName,
	backupNamespace string) (backup *api.CassandraBackup, err error)

func LookupCassandraCluster

func LookupCassandraCluster(client runtimeClient.Client, clusterName,
	clusterNamespace string) (cluster *api.CassandraCluster, err error)

LookupCassandra Cluster returns the running cluster instance based on its name and namespace

func MergeLabels

func MergeLabels(allLabels ...map[string]string) map[string]string

MergeLabels merges all the label maps received as argument into a single new label map.

func MergeSlice

func MergeSlice(old []string, new []string) []string

MergeSlice will add ad the end of old any elements of new which is missing we want to keep the order of elements in old

func MustNewKubeClientAndConfig

func MustNewKubeClientAndConfig() (kubernetes.Interface, *rest.Config)

Copy from k8sclient because not yet public MustNewKubeClientAndConfig returns the in-cluster config and kubernetes client or if KUBERNETES_CONFIG is given an out of cluster config and client

func PodByName

func PodByName(podList *v1.PodList, podName string) *v1.Pod

func PodHostname

func PodHostname(pod v1.Pod) string

PodHostname returns hostname of a pod

func RemoveString

func RemoveString(s []string, r string) []string

Types

This section is empty.

Jump to

Keyboard shortcuts

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