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 ¶
- 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 DCRackLabelsAndNodeSelectorForStatefulSet(cc *api.CassandraCluster, dc int, rack int) (map[string]string, map[string]string)
- func ExecPod(namespace string, pod *corev1.Pod, cmd []string) (string, string, error)
- func ExecPodFromName(namespace string, name string, cmd []string) (string, string, error)
- func InitClient()
- func IsMarkedForDeletion(m metav1.ObjectMeta) bool
- 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 LookupCassandraBackup(client runtimeClient.Client, backupName, backupNamespace string) (backup *api.CassandraBackup, err error)
- func LookupCassandraCluster(client runtimeClient.Client, clusterName, clusterNamespace string) (cluster *api.CassandraCluster, err error)
- func MergeLabels(allLabels ...map[string]string) map[string]string
- func MergeSlice(old []string, new []string) []string
- func MustNewKubeClientAndConfig() (kubernetes.Interface, *rest.Config)
- func PodByName(podList *v1.PodList, podName string) *v1.Pod
- func PodHostname(pod v1.Pod) string
- func RemoveString(s []string, r string) []string
Constants ¶
This section is empty.
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 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 ¶
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 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 ¶
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 ¶
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 ¶
Types ¶
This section is empty.