k8sutil

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package k8sutil for Kubernetes helpers.

Package k8sutil for Kubernetes helpers.

Package k8sutil for Kubernetes helpers.

Package k8sutil for Kubernetes helpers.

Package k8sutil for Kubernetes helpers.

Package k8sutil for Kubernetes helpers.

Package k8sutil for Kubernetes helpers.

Index

Constants

View Source
const (
	// Namespace for rook
	Namespace = "rook"
	// DefaultNamespace for the cluster
	DefaultNamespace = "default"
	// DataDirVolume data dir volume
	DataDirVolume = "rook-data"
	// DataDir folder
	DataDir = "/var/lib/rook"
	// RookType for the CRD
	RookType = "kubernetes.io/rook"
	// PodNameEnvVar is the env variable for getting the pod name via downward api
	PodNameEnvVar = "POD_NAME"
	// PodNamespaceEnvVar is the env variable for getting the pod namespace via downward api
	PodNamespaceEnvVar = "POD_NAMESPACE"
	// NodeNameEnvVar is the env variable for getting the node via downward api
	NodeNameEnvVar = "NODE_NAME"

	// RookVersionLabelKey is the key used for reporting the Rook version which last created or
	// modified a resource.
	RookVersionLabelKey = "rook-version"
)
View Source
const (
	// AppAttr app label
	AppAttr = "app"
	// ClusterAttr cluster label
	ClusterAttr = "rook_cluster"
	// PublicIPEnvVar public IP env var
	PublicIPEnvVar = "ROOK_PUBLIC_IP"
	// PrivateIPEnvVar pod IP env var
	PrivateIPEnvVar = "ROOK_PRIVATE_IP"

	// DefaultRepoPrefix repo prefix
	DefaultRepoPrefix = "rook"
	// ConfigOverrideName config override name
	ConfigOverrideName = "rook-config-override"
	// ConfigOverrideVal config override value
	ConfigOverrideVal = "config"
)
View Source
const (
	BinariesMountPath = "/rook"
)

Variables

WellKnownTaints is a list of well-known taint keys in the Kubernetes code base. Kubernetes may automatically apply these taints to nodes during runtime. Most will be added with the `NoSchedule` affect, but some are created with `NoExecute`. Rook may wish to ignore these taints when decided whether to modify resources it creates based on whether taints are likely to have been added by Kubernetes or by the user. see: https://github.com/kubernetes/kubernetes/blob/master/pkg/scheduler/api/well_known_labels.go and: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/#taint-based-evictions

Functions

func AddRookVersionLabelToDaemonSet added in v1.0.0

func AddRookVersionLabelToDaemonSet(d *v1.DaemonSet)

AddRookVersionLabelToDaemonSet adds or updates a label reporting the Rook version which last modified a DaemonSet.

func AddRookVersionLabelToDeployment added in v1.0.0

func AddRookVersionLabelToDeployment(d *v1.Deployment)

AddRookVersionLabelToDeployment adds or updates a label reporting the Rook version which last modified a deployment.

func AddRookVersionLabelToJob added in v1.0.0

func AddRookVersionLabelToJob(j *v1.Job)

AddRookVersionLabelToJob adds or updates a label reporting the Rook version which last modified a Job.

func BinariesMountInfo added in v1.0.0

func BinariesMountInfo() (v1.EnvVar, v1.Volume, v1.VolumeMount)

func ClusterDaemonEnvVars added in v0.9.0

func ClusterDaemonEnvVars(image string) []v1.EnvVar

ClusterDaemonEnvVars Environment variables used by storage cluster daemon

func ConfigDirEnvVar added in v0.4.0

func ConfigDirEnvVar(dataDir string) v1.EnvVar

ConfigDirEnvVar config dir env var

func ConfigOverrideEnvVar added in v0.5.0

func ConfigOverrideEnvVar() v1.EnvVar

ConfigOverrideEnvVar config override env var

func ConfigOverrideMount added in v0.5.0

func ConfigOverrideMount() v1.VolumeMount

ConfigOverrideMount is an override mount

func ConfigOverrideVolume added in v0.5.0

func ConfigOverrideVolume() v1.Volume

ConfigOverrideVolume is an override volume

func CreateDaemonSet added in v1.0.0

func CreateDaemonSet(name, namespace string, clientset kubernetes.Interface, ds *apps.DaemonSet) error

CreateDaemonSet creates

func CreateOrUpdateService added in v1.0.0

func CreateOrUpdateService(
	clientset kubernetes.Interface, namespace string, serviceDefinition *v1.Service,
) (*v1.Service, error)

CreateOrUpdateService creates a service or updates the service declaratively if it already exists.

func CreateStatefulSet added in v1.0.0

func CreateStatefulSet(name, namespace, appName string, clientset kubernetes.Interface, ss *apps.StatefulSet) (*corev1.Service, error)

create a apps.statefulset and a headless svc

func DeleteBatchJob added in v0.9.0

func DeleteBatchJob(clientset kubernetes.Interface, namespace, name string, wait bool) error

func DeleteDaemonset added in v0.6.0

func DeleteDaemonset(clientset kubernetes.Interface, namespace, name string) error

DeleteDaemonset makes a best effort at deleting a daemonset and its pods, then waits for them to be deleted

func DeleteDeployment added in v0.6.0

func DeleteDeployment(clientset kubernetes.Interface, namespace, name string) error

DeleteDeployment makes a best effort at deleting a deployment and its pods, then waits for them to be deleted

func DeleteReplicaSet added in v0.9.0

func DeleteReplicaSet(clientset kubernetes.Interface, namespace, name string) error

DeleteReplicaSet makes a best effort at deleting a deployment and its pods, then waits for them to be deleted

func GetContainerImage added in v0.7.0

func GetContainerImage(pod *v1.Pod, name string) (string, error)

func GetDaemonsets added in v1.0.3

func GetDaemonsets(clientset kubernetes.Interface, namespace, labelSelector string) (*apps.DaemonSetList, error)

GetDaemonsets returns a list of daemonsets names labels matching a given selector example of a label selector might be "app=rook-ceph-mon, mon!=b" more: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/

func GetDeploymentImage added in v0.9.0

func GetDeploymentImage(clientset kubernetes.Interface, namespace, name, container string) (string, error)

GetDeploymentImage returns the version of the image running in the pod spec for the desired container

func GetDeploymentSpecImage added in v0.9.0

func GetDeploymentSpecImage(clientset kubernetes.Interface, d apps.Deployment, container string, initContainer bool) (string, error)

func GetDeployments added in v0.9.0

func GetDeployments(clientset kubernetes.Interface, namespace, labelSelector string) (*apps.DeploymentList, error)

GetDeployments returns a list of deployment names labels matching a given selector example of a label selector might be "app=rook-ceph-mon, mon!=b" more: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/

func GetK8SVersion added in v0.6.0

func GetK8SVersion(clientset kubernetes.Interface) (*version.Version, error)

GetK8SVersion gets the version of the running K8S cluster

func GetKubernetesNodesMatchingRookNodes added in v1.0.0

func GetKubernetesNodesMatchingRookNodes(rookNodes []rookalpha.Node, clientset kubernetes.Interface) ([]v1.Node, error)

GetKubernetesNodesMatchingRookNodes lists all the nodes in Kubernetes and returns all the Kubernetes nodes that have a corresponding match in the list of Rook nodes.

func GetMatchingContainer added in v0.8.0

func GetMatchingContainer(containers []v1.Container, name string) (v1.Container, error)

func GetNodeHostNames added in v0.8.3

func GetNodeHostNames(clientset kubernetes.Interface) (map[string]string, error)

GetNodeHostNames returns the name of the node resource mapped to their hostname label. Typically these will be the same name, but sometimes they are not such as when nodes have a longer dns name, but the hostname is short.

func GetNodeNameFromHostname added in v0.8.3

func GetNodeNameFromHostname(clientset kubernetes.Interface, hostName string) (string, error)

GetNodeNameFromHostname returns the name of the node resource looked up by the hostname label Typically these will be the same name, but sometimes they are not such as when nodes have a longer dns name, but the hostname is short.

func GetNodeSchedulable added in v1.0.0

func GetNodeSchedulable(node v1.Node) bool

GetNodeSchedulable returns a boolean if the node is tainted as Schedulable or not true -> Node is schedulable false -> Node is unschedulable

func GetPodLog added in v0.9.0

func GetPodLog(clientset kubernetes.Interface, namespace string, labelSelector string) (string, error)

GetJobLog gets the logs for the pod. If there is more than one pod with the label selector, the logs from the first pod will be returned.

func GetPodPhaseMap added in v0.8.0

func GetPodPhaseMap(pods *v1.PodList) map[v1.PodPhase][]string

GetPodPhaseMap takes a list of pods and returns a map of pod phases to the names of pods that are in that phase

func GetRunningPod added in v0.8.0

func GetRunningPod(clientset kubernetes.Interface) (*v1.Pod, error)

func GetSpecContainerImage added in v0.8.1

func GetSpecContainerImage(spec v1.PodSpec, name string, initContainer bool) (string, error)

func GetValidNodes added in v0.8.1

func GetValidNodes(rookNodes []rookalpha.Node, clientset kubernetes.Interface, placement rookalpha.Placement) []rookalpha.Node

GetValidNodes returns all nodes that (1) are not cordoned, (2) meet Rook's placement terms, and (3) are ready.

func Hash added in v0.8.1

func Hash(s string) string

Hash MD5 hash a given string

func IndexToName added in v0.9.0

func IndexToName(index int) string

IndexToName converts an index to a daemon name based on as few letters of the alphabet as possible. For example:

0 -> a
1 -> b
25 -> z
26 -> aa

func MakeRookImage

func MakeRookImage(version string) string

MakeRookImage formats the container name

func MergeResourceRequirements added in v0.7.0

func MergeResourceRequirements(first, second v1.ResourceRequirements) v1.ResourceRequirements

func NameEnvVar added in v0.6.0

func NameEnvVar() v1.EnvVar

NameEnvVar pod name env var

func NameToIndex added in v0.9.0

func NameToIndex(name string) (int, error)

NameToIndex converts a daemon name to an index, which is the inverse of IndexToName For example:

a -> 0
b -> 1

func NamespaceEnvVar

func NamespaceEnvVar() v1.EnvVar

NamespaceEnvVar namespace env var

func NodeConfigURI added in v0.6.0

func NodeConfigURI() (string, error)

NodeConfigURI returns the node config URI path for this node

func NodeEnvVar added in v0.6.0

func NodeEnvVar() v1.EnvVar

NodeEnvVar node env var

func NodeIsInRookNodeList added in v1.0.0

func NodeIsInRookNodeList(targetNodeName string, rookNodes []rookalpha.Node) bool

NodeIsInRookNodeList will return true if the target node is found in a given list of Rook nodes.

func NodeIsReady added in v1.0.0

func NodeIsReady(node v1.Node) bool

NodeIsReady returns true if the node is ready. It returns false if the node is not ready.

func NodeIsTolerable added in v1.0.0

func NodeIsTolerable(node v1.Node, tolerations []v1.Toleration, ignoreWellKnownTaints bool) bool

NodeIsTolerable returns true if the node's taints are all tolerated by the given tolerations. There is the option to ignore well known taints defined in WellKnownTaints. See WellKnownTaints for more information.

func NodeMeetsAffinityTerms added in v1.0.0

func NodeMeetsAffinityTerms(node v1.Node, affinity *v1.NodeAffinity) (bool, error)

NodeMeetsAffinityTerms returns true if the node meets the terms of the node affinity. `PreferredDuringSchedulingIgnoredDuringExecution` terms are ignored and not used to judge a node's usability.

func NodeMeetsPlacementTerms added in v1.0.0

func NodeMeetsPlacementTerms(node v1.Node, placement rookalpha.Placement, ignoreWellKnownTaints bool) (bool, error)

NodeMeetsPlacementTerms returns true if the Rook placement allows the node to have resources scheduled on it. A node is placeable if it (1) meets any affinity terms that may be set in the placement, and (2) its taints are tolerated by the placements tolerations. There is the option to ignore well known taints defined in WellKnownTaints. See WellKnownTaints for more information.

func PathToVolumeName added in v0.4.0

func PathToVolumeName(path string) string

PathToVolumeName converts a path to a valid volume name

func PodIPEnvVar

func PodIPEnvVar(property string) v1.EnvVar

PodIPEnvVar returns an env var such that the pod's ip will be mapped to the given property (env var) name within the container.

func PodsRunningWithLabel added in v0.9.0

func PodsRunningWithLabel(clientset kubernetes.Interface, namespace, label string) (int, error)

func RookNodesMatchingKubernetesNodes added in v1.0.0

func RookNodesMatchingKubernetesNodes(rookNodes []rookalpha.Node, kubernetesNodes []v1.Node) []rookalpha.Node

RookNodesMatchingKubernetesNodes returns only the given Rook nodes which have a corresponding match in the list of Kubernetes nodes.

func RunReplaceableJob added in v0.9.0

func RunReplaceableJob(clientset kubernetes.Interface, job *batch.Job, deleteIfFound bool) error

func SetOwnerRef added in v0.8.0

func SetOwnerRef(object *metav1.ObjectMeta, ownerRef *metav1.OwnerReference)

func SetOwnerRefs added in v0.8.0

func SetOwnerRefs(object *metav1.ObjectMeta, ownerRefs []metav1.OwnerReference)

func TaintIsWellKnown added in v1.0.0

func TaintIsWellKnown(t v1.Taint) bool

TaintIsWellKnown returns true if the taint's key is in the WellKnownTaints list. False otherwise. See WellKnownTaints for more information.

func TruncateNodeName added in v0.8.1

func TruncateNodeName(format, nodeName string) string

TruncateNodeName hashes the nodeName in case it would case the name to be longer than 63 characters WARNING If your format and nodeName as a hash, are longer than 63 chars it won't be truncated! Your format alone should only be 31 chars at max because of MD5 hash being 32 chars. For more information, see the following resources: https://stackoverflow.com/a/50451893 https://stackoverflow.com/a/32294443

func UpdateDeploymentAndWait added in v0.8.1

func UpdateDeploymentAndWait(context *clusterd.Context, deployment *apps.Deployment, namespace string) (*v1.Deployment, error)

UpdateDeploymentAndWait updates a deployment and waits until it is running to return. It will error if the deployment does not exist to be updated or if it takes too long.

func UpdateService added in v1.0.0

func UpdateService(
	clientset kubernetes.Interface, namespace string, serviceDefinition *v1.Service,
) (*v1.Service, error)

UpdateService updates a service declaratively. If the service does not exist this is considered an error condition.

func ValidNode added in v0.8.1

func ValidNode(node v1.Node, placement rookalpha.Placement) (bool, error)

ValidNode returns true if the node (1) is schedulable, (2) meets Rook's placement terms, and (3) is ready. False otherwise.

func WaitForDeploymentImage added in v0.9.0

func WaitForDeploymentImage(clientset kubernetes.Interface, namespace, label, container string, initContainer bool, desiredImage string) error

WaitForDeploymentImage waits for all deployments with the given labels are running. WARNING:This is currently only useful for testing!

func WaitForJobCompletion added in v0.9.0

func WaitForJobCompletion(clientset kubernetes.Interface, job *batch.Job, timeout time.Duration) error

WaitForJobCompletion waits for a job to reach the completed state. Assumes that only one pod needs to complete.

Types

type ConfigMapKVStore added in v0.6.0

type ConfigMapKVStore struct {
	// contains filtered or unexported fields
}

func NewConfigMapKVStore added in v0.6.0

func NewConfigMapKVStore(namespace string, clientset kubernetes.Interface, ownerRef metav1.OwnerReference) *ConfigMapKVStore

func (*ConfigMapKVStore) ClearStore added in v0.6.0

func (kv *ConfigMapKVStore) ClearStore(storeName string) error

func (*ConfigMapKVStore) GetStore added in v0.6.0

func (kv *ConfigMapKVStore) GetStore(storeName string) (map[string]string, error)

func (*ConfigMapKVStore) GetValue added in v0.6.0

func (kv *ConfigMapKVStore) GetValue(storeName, key string) (string, error)

func (*ConfigMapKVStore) SetValue added in v0.6.0

func (kv *ConfigMapKVStore) SetValue(storeName, key, value string) error

func (*ConfigMapKVStore) SetValueWithLabels added in v0.8.0

func (kv *ConfigMapKVStore) SetValueWithLabels(storeName, key, value string, labels map[string]string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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