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
- Variables
- func AddOwnerRefToObject(o metav1.Object, r metav1.OwnerReference)
- func AsOwner(cc *api.CassandraCluster) metav1.OwnerReference
- func ContainSlice(ref []string, n []string) bool
- func Contains(s []string, e string) bool
- func ExecPod(namespace string, pod *corev1.Pod, cmd []string) (string, string, error)
- func ExecPodFromName(namespace string, name string, cmd []string) (string, string, error)
- func GetCassandraImage(cc *api.CassandraCluster) string
- func GetDCRackLabelsAndNodeSelectorForStatefulSet(cc *api.CassandraCluster, dc int, rack int) (map[string]string, map[string]string)
- func InitClient()
- func LabelTime() string
- func LabelTime2Time(label string) (time.Time, error)
- func LabelsForCassandra(cc *api.CassandraCluster) map[string]string
- func LabelsForCassandraDC(cc *api.CassandraCluster, dcName string) map[string]string
- func LabelsForCassandraDCRack(cc *api.CassandraCluster, dcName string, rackName string) map[string]string
- func MergeLabels(allLabels ...map[string]string) map[string]string
- func MergeSlice(old []string, new []string) []string
- func MustNewKubeClientAndConfig() (kubernetes.Interface, *rest.Config)
- func RemoveString(s []string, r string) []string
Constants ¶
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 ¶
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 ¶
func AsOwner(cc *api.CassandraCluster) metav1.OwnerReference
asOwner returns an owner reference set as the cassandra cluster CRD
func ContainSlice ¶
ContainSlice return true if each element of n exists in ref
func ExecPod ¶
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 ¶
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 ¶
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 ¶
MergeLabels merges all the label maps received as argument into a single new label map.
func MergeSlice ¶
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 ¶
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.