k8s

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: Apache-2.0 Imports: 15 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

View Source
const (
	// CassandraImage defines the default cassandra image
	// can be surcharded by the CRD
	CassandraImage = "sebmoule/cassandra-k8s"

	// CassandraImageVersion defines the default cassandra image version
	// can be surcharge by the CRD
	CassandraImageVersion = "3.11.1-dev" //
)

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 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 GetCassandraImage

func GetCassandraImage(cc *api.CassandraCluster) string

getCassandraImage returns the docker image to used for cassandra

func GetDCRackLabelsAndNodeSelectorForStatefulSet

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

GetDCRackLabelsForStatefulSet 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 InitClient

func InitClient()

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

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 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 RemoveString

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

RemoveString remove a string from a slice s := []string{"one", "two", "three"} s = RemoveString(s, "two") fmt.Println(s) // Prints [one three]

Types

This section is empty.

Jump to

Keyboard shortcuts

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