Documentation ¶
Overview ¶
Package kit for Kubernetes operators
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.
Package k8sutil for Kubernetes helpers.
Index ¶
- Constants
- Variables
- func AddLabelToDeployment(key, value string, d *appsv1.Deployment)
- func AddLabelToJob(key, value string, b *batchv1.Job)
- func AddLabelToPod(key, value string, p *corev1.PodTemplateSpec)
- func AddRecommendedLabels(labels map[string]string, ...)
- func AddRookVersionLabelToDaemonSet(d *appsv1.DaemonSet)
- func AddRookVersionLabelToDeployment(d *appsv1.Deployment)
- func AddRookVersionLabelToJob(j *batch.Job)
- func AddRookVersionLabelToObjectMeta(meta *metav1.ObjectMeta)
- func AddUnreachableNodeToleration(podSpec *v1.PodSpec)
- func ApplyMultus(clusterNamespace string, netSpec *cephv1.NetworkSpec, ...) error
- func BaseKubernetesDeleteOptions() *metav1.DeleteOptions
- func BinariesMountInfo() (v1.EnvVar, v1.Volume, v1.VolumeMount)
- func ClusterDaemonEnvVars(image string) []v1.EnvVar
- func ConfigDirEnvVar(dataDir string) v1.EnvVar
- func ConfigOverrideEnvVar() v1.EnvVar
- func ConfigOverrideMount() v1.VolumeMount
- func ConfigOverrideVolume() v1.Volume
- func CreateDaemonSet(ctx context.Context, namespace string, clientset kubernetes.Interface, ...) error
- func CreateDeployment(ctx context.Context, clientset kubernetes.Interface, dep *appsv1.Deployment) (*appsv1.Deployment, error)
- func CreateOrUpdateConfigMap(ctx context.Context, clientset kubernetes.Interface, cm *v1.ConfigMap) (*v1.ConfigMap, error)
- func CreateOrUpdateCronJob(ctx context.Context, clientset kubernetes.Interface, cj *batchv1.CronJob) (*batchv1.CronJob, error)
- func CreateOrUpdateDeployment(ctx context.Context, clientset kubernetes.Interface, dep *appsv1.Deployment) (*appsv1.Deployment, error)
- func CreateOrUpdateEndpoint(ctx context.Context, clientset kubernetes.Interface, namespace string, ...) (*v1.Endpoints, error)
- func CreateOrUpdateSecret(ctx context.Context, clientset kubernetes.Interface, ...) (*v1.Secret, error)
- func CreateOrUpdateService(ctx context.Context, clientset kubernetes.Interface, namespace string, ...) (*v1.Service, error)
- func CreateOrUpdateServiceMonitor(context *clusterd.Context, ctx context.Context, ...) (*monitoringv1.ServiceMonitor, error)
- func DeleteBatchJob(ctx context.Context, clientset kubernetes.Interface, namespace, name string, ...) error
- func DeleteConfigMap(ctx context.Context, clientset kubernetes.Interface, cmName, namespace string, ...) error
- func DeleteDaemonset(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error
- func DeleteDeployment(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error
- func DeleteReplicaSet(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error
- func DeleteResource(delete func() error, verify func() error, resource string, opts *DeleteOptions, ...) error
- func DeleteService(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error
- func DeleteServiceMonitor(context *clusterd.Context, ctx context.Context, ns string, name string) error
- func DeploymentNames(deployments *appsv1.DeploymentList) (names []string)
- func ExpandPVCIfRequired(ctx context.Context, client client.Client, ...)
- func ExportService(ctx context.Context, c *clusterd.Context, service *v1.Service, ...) (string, error)
- func FindNetworkStatusByInterface(statuses []nadv1.NetworkStatus, ifaceName string) (nadv1.NetworkStatus, bool)
- func ForceDeletePodIfStuck(ctx context.Context, clusterdContext *clusterd.Context, pod v1.Pod) error
- func GenerateNodeAffinity(nodeAffinity string) (*v1.NodeAffinity, error)
- func GetContainerImage(pod *v1.Pod, name string) (string, error)
- func GetDaemonsets(ctx context.Context, clientset kubernetes.Interface, ...) (*appsv1.DaemonSetList, error)
- func GetDeploymentImage(ctx context.Context, clientset kubernetes.Interface, ...) (string, error)
- func GetDeploymentOwnerReference(ctx context.Context, clientset kubernetes.Interface, podName, namespace string) (*metav1.OwnerReference, error)
- func GetDeploymentSpecImage(clientset kubernetes.Interface, d appsv1.Deployment, container string, ...) (string, error)
- func GetDeployments(ctx context.Context, clientset kubernetes.Interface, ...) (*appsv1.DeploymentList, error)
- func GetExportedServiceIP(fqdn string) (string, error)
- func GetK8SVersion(clientset kubernetes.Interface) (*version.Version, error)
- func GetKubernetesNodesMatchingRookNodes(ctx context.Context, rookNodes []cephv1.Node, clientset kubernetes.Interface) ([]v1.Node, error)
- func GetMatchingContainer(containers []v1.Container, name string) (v1.Container, error)
- func GetNodeHostName(ctx context.Context, clientset kubernetes.Interface, nodeName string) (string, error)
- func GetNodeHostNameLabel(node *v1.Node) (string, error)
- func GetNodeHostNames(ctx context.Context, clientset kubernetes.Interface) (map[string]string, error)
- func GetNodeNameFromHostname(ctx context.Context, clientset kubernetes.Interface, hostName string) (string, error)
- func GetNodeSchedulable(node v1.Node) bool
- func GetNotReadyKubernetesNodes(ctx context.Context, clientset kubernetes.Interface) ([]v1.Node, error)
- func GetOperatorSetting(context context.Context, clientset kubernetes.Interface, ...) (string, error)
- func GetPodLog(ctx context.Context, clientset kubernetes.Interface, namespace string, ...) (string, error)
- func GetPodPhaseMap(pods *v1.PodList) map[v1.PodPhase][]string
- func GetRunningPod(ctx context.Context, clientset kubernetes.Interface) (*v1.Pod, error)
- func GetServiceMonitor(name string, namespace string, portName string) *monitoringv1.ServiceMonitor
- func GetSpecContainerImage(spec v1.PodSpec, name string, initContainer bool) (string, error)
- func GetValidNodes(ctx context.Context, rookStorage cephv1.StorageScopeSpec, ...) []cephv1.Node
- func GetValue(data map[string]string, settingName, defaultValue string) string
- func Hash(s string) string
- func IndexToName(index int) string
- func IsPodScheduled(ctx context.Context, clientSet kubernetes.Interface, ...) (bool, error)
- func IsServiceExported(ctx context.Context, c *clusterd.Context, name, namespace string) (bool, error)
- func MergeResourceRequirements(first, second v1.ResourceRequirements) v1.ResourceRequirements
- func NameEnvVar() v1.EnvVar
- func NameToIndex(name string) (int, error)
- func NamespaceEnvVar() v1.EnvVar
- func NodeConfigURI() (string, error)
- func NodeEnvVar() v1.EnvVar
- func NodeIsReady(node v1.Node) bool
- func NodeIsTolerable(node v1.Node, tolerations []v1.Toleration, ignoreWellKnownTaints bool) bool
- func NodeMeetsAffinityTerms(node v1.Node, affinity *v1.NodeAffinity) (bool, error)
- func NodeMeetsPlacementTerms(node v1.Node, placement cephv1.Placement, ignoreWellKnownTaints bool) (bool, error)
- func ParseNetworkStatusAnnotation(annotationValue string) ([]nadv1.NetworkStatus, error)
- func ParseServiceType(serviceString string) v1.ServiceType
- func ParseStringToLabels(in string) map[string]string
- func PathToVolumeName(path string) string
- func PodIPEnvVar(property string) v1.EnvVar
- func PodsRunningWithLabel(ctx context.Context, clientset kubernetes.Interface, namespace, label string) (int, error)
- func PodsWithLabelAreAllRunning(ctx context.Context, clientset kubernetes.Interface, namespace, label string) (bool, error)
- func RemoveDuplicateEnvVars(pod *v1.PodSpec)
- func RookNodesMatchingKubernetesNodes(rookStorage cephv1.StorageScopeSpec, kubernetesNodes []v1.Node) []cephv1.Node
- func RunReplaceableJob(ctx context.Context, clientset kubernetes.Interface, job *batch.Job, ...) error
- func SetNodeAntiAffinityForPod(pod *v1.PodSpec, requiredDuringScheduling bool, topologyKey string, ...)
- func SetOwnerRefsWithoutBlockOwner(object metav1.Object, ownerRefs []metav1.OwnerReference)
- func TaintIsWellKnown(t v1.Taint) bool
- func ToValidDNSLabel(input string) string
- func TruncateNodeName(format, nodeName string) string
- func TruncateNodeNameForJob(format, nodeName string) string
- func UpdateDeploymentAndWait(ctx context.Context, clusterContext *clusterd.Context, ...) error
- func UpdateMultipleDeployments(ctx context.Context, clientset kubernetes.Interface, ...) (DeploymentsUpdated, Failures, *int32)
- func UpdateService(ctx context.Context, clientset kubernetes.Interface, namespace string, ...) (*v1.Service, error)
- func ValidNode(node v1.Node, placement cephv1.Placement) error
- func WaitForDeploymentImage(ctx context.Context, clientset kubernetes.Interface, ...) error
- func WaitForDeploymentToStart(ctx context.Context, clusterdContext *clusterd.Context, ...) error
- func WaitForJobCompletion(ctx context.Context, clientset kubernetes.Interface, job *batch.Job, ...) error
- func WatchCR(resource CustomResource, namespace string, ...)
- func YamlToContainerResource(raw string) (v1.ResourceRequirements, error)
- func YamlToTolerations(raw string) ([]v1.Toleration, error)
- func YamlToVolumeMounts(raw string) ([]v1.VolumeMount, error)
- func YamlToVolumes(raw string) ([]v1.Volume, error)
- type ConfigMapKVStore
- func (kv *ConfigMapKVStore) ClearStore(ctx context.Context, storeName string) error
- func (kv *ConfigMapKVStore) GetStore(ctx context.Context, storeName string) (map[string]string, error)
- func (kv *ConfigMapKVStore) GetValue(ctx context.Context, storeName, key string) (string, error)
- func (kv *ConfigMapKVStore) SetValue(ctx context.Context, storeName, key, value string) error
- func (kv *ConfigMapKVStore) SetValueWithLabels(ctx context.Context, storeName, key, value string, labels map[string]string) error
- type ContainerResource
- type CustomResource
- type DeleteOptions
- type DeploymentsUpdated
- type Failure
- type Failures
- type LinuxIpAddrInfo
- type LinuxIpAddrResult
- type OwnerInfo
- type Patcher
- type WaitOptions
Constants ¶
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" // DefaultServiceAccount is a service-account used for components that do not specify a dedicated service-account. DefaultServiceAccount = "rook-ceph-default" )
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" ObservedGenerationNotAvailable int64 = -1 )
const ( // ReadyStatus reflects the completeness of tasks for ceph related CRs ReadyStatus = "Ready" // ProcessingStatus reflects that the tasks are in progress for ceph related CRs ProcessingStatus = "Processing" // FailedStatus reflects that some task failed for ceph related CRs FailedStatus = "Failed" // ReconcilingStatus indicates the CR is reconciling ReconcilingStatus = "Reconciling" // ReconcileFailedStatus indicates a reconciliation failed ReconcileFailedStatus = "ReconcileFailed" // EmptyStatus indicates the object just got created EmptyStatus = "" )
const (
BinariesMountPath = "/rook"
)
Variables ¶
var WellKnownTaints = []string{ v1.TaintNodeNotReady, v1.TaintNodeUnreachable, v1.TaintNodeUnschedulable, v1.TaintNodeMemoryPressure, v1.TaintNodeDiskPressure, v1.TaintNodeNetworkUnavailable, v1.TaintNodePIDPressure, cloudproviderapi.TaintExternalCloudProvider, cloudproviderapi.TaintNodeShutdown, }
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 AddLabelToDeployment ¶
func AddLabelToDeployment(key, value string, d *appsv1.Deployment)
func AddLabelToJob ¶
func AddLabelToPod ¶
func AddLabelToPod(key, value string, p *corev1.PodTemplateSpec)
func AddRecommendedLabels ¶
func AddRecommendedLabels(labels map[string]string, appName, parentName, resourceKind, resourceInstance string)
AddRecommendedLabels adds the labels to the resources created by rook The labels added are name, instance,etc
func AddRookVersionLabelToDaemonSet ¶
AddRookVersionLabelToDaemonSet adds or updates a label reporting the Rook version which last modified a DaemonSet.
func AddRookVersionLabelToDeployment ¶
func AddRookVersionLabelToDeployment(d *appsv1.Deployment)
AddRookVersionLabelToDeployment adds or updates a label reporting the Rook version which last modified a deployment.
func AddRookVersionLabelToJob ¶
AddRookVersionLabelToJob adds or updates a label reporting the Rook version which last modified a Job.
func AddRookVersionLabelToObjectMeta ¶
func AddRookVersionLabelToObjectMeta(meta *metav1.ObjectMeta)
func AddUnreachableNodeToleration ¶
Replaces the pod default toleration of 300s used when the node controller detect a not ready node (node.kubernetes.io/unreachable)
func ApplyMultus ¶
func ApplyMultus(clusterNamespace string, netSpec *cephv1.NetworkSpec, objectMeta *metav1.ObjectMeta) error
ApplyMultus apply multus selector to Pods Multus supports short and json syntax, use only one kind at a time.
func BaseKubernetesDeleteOptions ¶
func BaseKubernetesDeleteOptions() *metav1.DeleteOptions
BaseKubernetesDeleteOptions returns the base set of Kubernetes delete options which most delete operations should use.
func BinariesMountInfo ¶
func ClusterDaemonEnvVars ¶
ClusterDaemonEnvVars Environment variables used by storage cluster daemon
func ConfigDirEnvVar ¶
ConfigDirEnvVar config dir env var
func ConfigOverrideEnvVar ¶
ConfigOverrideEnvVar config override env var
func ConfigOverrideMount ¶
func ConfigOverrideMount() v1.VolumeMount
ConfigOverrideMount is an override mount
func ConfigOverrideVolume ¶
ConfigOverrideVolume is an override volume
func CreateDaemonSet ¶
func CreateDaemonSet(ctx context.Context, namespace string, clientset kubernetes.Interface, ds *appsv1.DaemonSet) error
CreateDaemonSet creates
func CreateDeployment ¶
func CreateDeployment(ctx context.Context, clientset kubernetes.Interface, dep *appsv1.Deployment) (*appsv1.Deployment, error)
CreateDeployment creates a deployment with a last applied hash annotation added
func CreateOrUpdateConfigMap ¶
func CreateOrUpdateCronJob ¶
func CreateOrUpdateDeployment ¶
func CreateOrUpdateDeployment(ctx context.Context, clientset kubernetes.Interface, dep *appsv1.Deployment) (*appsv1.Deployment, error)
func CreateOrUpdateEndpoint ¶
func CreateOrUpdateEndpoint(ctx context.Context, clientset kubernetes.Interface, namespace string, endpointDefinition *v1.Endpoints) (*v1.Endpoints, error)
CreateOrUpdateEndpoint creates a service or updates the service declaratively if it already exists.
func CreateOrUpdateSecret ¶
func CreateOrUpdateSecret(ctx context.Context, clientset kubernetes.Interface, secretDefinition *v1.Secret) (*v1.Secret, error)
CreateOrUpdateSecret creates a secret or updates the secret declaratively if it already exists.
func CreateOrUpdateService ¶
func CreateOrUpdateService( ctx context.Context, 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 CreateOrUpdateServiceMonitor ¶
func CreateOrUpdateServiceMonitor(context *clusterd.Context, ctx context.Context, serviceMonitorDefinition *monitoringv1.ServiceMonitor) (*monitoringv1.ServiceMonitor, error)
CreateOrUpdateServiceMonitor creates serviceMonitor object or an error
func DeleteBatchJob ¶
func DeleteBatchJob(ctx context.Context, clientset kubernetes.Interface, namespace, name string, wait bool) error
DeleteBatchJob deletes a Kubernetes job.
func DeleteConfigMap ¶
func DeleteConfigMap(ctx context.Context, clientset kubernetes.Interface, cmName, namespace string, opts *DeleteOptions) error
DeleteConfigMap deletes a ConfigMap.
func DeleteDaemonset ¶
func DeleteDaemonset(ctx context.Context, 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 ¶
func DeleteDeployment(ctx context.Context, 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 ¶
func DeleteReplicaSet(ctx context.Context, 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 DeleteResource ¶
func DeleteResource( delete func() error, verify func() error, resource string, opts *DeleteOptions, defaultWaitOptions *WaitOptions, ) error
DeleteResource implements the DeleteOptions logic around deletion of a Kubernetes resource.
The delete and verify functions used as parameters should implement and return the error from the Kubernetes `Delete` and `Get` commands respectively.
The resource string will be used to report the resource in log and error messages. A good pattern would be to set this string to the resource type (e.g., Deployment) and the name of the resource (e.g., my-deployment).
The default wait options should specify sane defaults for retry count and retry interval for deletion of the specific resource type. Only retry count and interval will be used from this parameter.
func DeleteService ¶
func DeleteService(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error
DeleteService deletes a Service and returns the error if any
func DeleteServiceMonitor ¶
func DeleteServiceMonitor(context *clusterd.Context, ctx context.Context, ns string, name string) error
DeleteServiceMonitor deletes a ServiceMonitor and returns the error if any
func DeploymentNames ¶
func DeploymentNames(deployments *appsv1.DeploymentList) (names []string)
DeploymentNames returns a list of the names of deployments in the deployment list
func ExpandPVCIfRequired ¶
func ExpandPVCIfRequired(ctx context.Context, client client.Client, desiredPVC *v1.PersistentVolumeClaim, currentPVC *v1.PersistentVolumeClaim)
ExpandPVCIfRequired will expand the PVC if requested size is greater than the actual size of existing PVC
func ExportService ¶
func ExportService(ctx context.Context, c *clusterd.Context, service *v1.Service, clusterID string) (string, error)
ExportService exports the service using MCS API and returns the external IP of the exported service
func FindNetworkStatusByInterface ¶
func FindNetworkStatusByInterface(statuses []nadv1.NetworkStatus, ifaceName string) (nadv1.NetworkStatus, bool)
func ForceDeletePodIfStuck ¶
func GenerateNodeAffinity ¶
func GenerateNodeAffinity(nodeAffinity string) (*v1.NodeAffinity, error)
GenerateNodeAffinity will return v1.NodeAffinity or error
func GetContainerImage ¶
GetContainerImage returns the container image matching the given name for a pod. If the pod only has a single container, the name argument is ignored.
func GetDaemonsets ¶
func GetDaemonsets(ctx context.Context, clientset kubernetes.Interface, namespace, labelSelector string) (*appsv1.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 ¶
func GetDeploymentImage(ctx context.Context, 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 GetDeploymentOwnerReference ¶
func GetDeploymentOwnerReference(ctx context.Context, clientset kubernetes.Interface, podName, namespace string) (*metav1.OwnerReference, error)
GetDeploymentOwnerReference returns an OwnerReference to the deployment that is running the given pod name
func GetDeploymentSpecImage ¶
func GetDeploymentSpecImage(clientset kubernetes.Interface, d appsv1.Deployment, container string, initContainer bool) (string, error)
GetDeploymentSpecImage returns the image name from the spec
func GetDeployments ¶
func GetDeployments(ctx context.Context, clientset kubernetes.Interface, namespace, labelSelector string) (*appsv1.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 GetExportedServiceIP ¶
func GetK8SVersion ¶
func GetK8SVersion(clientset kubernetes.Interface) (*version.Version, error)
GetK8SVersion gets the version of the running K8S cluster
func GetKubernetesNodesMatchingRookNodes ¶
func GetKubernetesNodesMatchingRookNodes(ctx context.Context, rookNodes []cephv1.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 ¶
GetMatchingContainer takes a list of containers and a name, and returns the first container in the list matching the name. If the list contains a single container it is always returned, even if the name does not match.
func GetNodeHostName ¶
func GetNodeHostName(ctx context.Context, clientset kubernetes.Interface, nodeName string) (string, error)
GetNodeHostName returns the hostname label given the node name.
func GetNodeHostNames ¶
func GetNodeHostNames(ctx context.Context, 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 ¶
func GetNodeNameFromHostname(ctx context.Context, 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 ¶
GetNodeSchedulable returns a boolean if the node is tainted as Schedulable or not true -> Node is schedulable false -> Node is unschedulable
func GetNotReadyKubernetesNodes ¶
func GetNotReadyKubernetesNodes(ctx context.Context, clientset kubernetes.Interface) ([]v1.Node, error)
GetNotReadyKubernetesNodes lists all the nodes that are in NotReady state
func GetOperatorSetting ¶
func GetOperatorSetting(context context.Context, clientset kubernetes.Interface, configMapName, settingName, defaultValue string) (string, error)
GetOperatorSetting gets the operator setting from ConfigMap or Env Var returns defaultValue if setting is not found
func GetPodLog ¶
func GetPodLog(ctx context.Context, 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 ¶
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 ¶
GetRunningPod reads the name and namespace of a pod from the environment, and returns the pod (if it exists).
func GetServiceMonitor ¶
func GetServiceMonitor(name string, namespace string, portName string) *monitoringv1.ServiceMonitor
GetServiceMonitor creates serviceMonitor object template
func GetSpecContainerImage ¶
GetSpecContainerImage returns the container image for a podspec, given a container name. The name is ignored if the podspec has a single container, in which case the image for that container is returned.
func GetValidNodes ¶
func GetValidNodes(ctx context.Context, rookStorage cephv1.StorageScopeSpec, clientset kubernetes.Interface, placement cephv1.Placement) []cephv1.Node
GetValidNodes returns all nodes that (1) are not cordoned, (2) meet Rook's placement terms, and (3) are ready.
func Hash ¶
Hash stableName computes a stable pseudorandom string suitable for inclusion in a Kubernetes object name from the given seed string. Do **NOT** edit this function in a way that would change its output as it needs to provide consistent mappings from string to hash across versions of rook.
func IndexToName ¶
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 IsPodScheduled ¶
func IsServiceExported ¶
func MergeResourceRequirements ¶
func MergeResourceRequirements(first, second v1.ResourceRequirements) v1.ResourceRequirements
func NameToIndex ¶
NameToIndex converts a daemon name to an index, which is the inverse of IndexToName For example:
a -> 0 b -> 1
func NodeConfigURI ¶
NodeConfigURI returns the node config URI path for this node
func NodeIsReady ¶
NodeIsReady returns true if the node is ready. It returns false if the node is not ready.
func NodeIsTolerable ¶
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 ¶
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 ¶
func NodeMeetsPlacementTerms(node v1.Node, placement cephv1.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 ParseNetworkStatusAnnotation ¶
func ParseNetworkStatusAnnotation(annotationValue string) ([]nadv1.NetworkStatus, error)
ParseNetworkStatusAnnotation takes the annotation value from k8s.v1.cni.cncf.io/network-status and returns the network status struct.
func ParseServiceType ¶
func ParseServiceType(serviceString string) v1.ServiceType
ParseServiceType parses a string and returns a*v1.ServiceType. If the ServiceType is invalid, this should be considered an error.
func ParseStringToLabels ¶
ParseStringToLabels parse a label selector string into a map[string]string
func PathToVolumeName ¶
PathToVolumeName converts a path to a valid volume name
func PodIPEnvVar ¶
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 ¶
func PodsRunningWithLabel(ctx context.Context, clientset kubernetes.Interface, namespace, label string) (int, error)
PodsRunningWithLabel returns the number of running pods with the given label
func PodsWithLabelAreAllRunning ¶
func PodsWithLabelAreAllRunning(ctx context.Context, clientset kubernetes.Interface, namespace, label string) (bool, error)
PodsWithLabelAreAllRunning returns whether all pods with the label are in running state
func RemoveDuplicateEnvVars ¶
func RookNodesMatchingKubernetesNodes ¶
func RookNodesMatchingKubernetesNodes(rookStorage cephv1.StorageScopeSpec, kubernetesNodes []v1.Node) []cephv1.Node
RookNodesMatchingKubernetesNodes returns only the given Rook nodes which have a corresponding match in the list of Kubernetes nodes.
func RunReplaceableJob ¶
func RunReplaceableJob(ctx context.Context, clientset kubernetes.Interface, job *batch.Job, deleteIfFound bool) error
RunReplaceableJob runs a Kubernetes job with the intention that the job can be replaced by another call to this function with the same job name. For example, if a storage operator is restarted/updated before the job can complete, the operator's next run of the job should replace the previous job if deleteIfFound is set to true.
func SetNodeAntiAffinityForPod ¶
func SetNodeAntiAffinityForPod(pod *v1.PodSpec, requiredDuringScheduling bool, topologyKey string, labels, nodeSelector map[string]string)
SetNodeAntiAffinityForPod assign pod anti-affinity when pod should not be co-located
func SetOwnerRefsWithoutBlockOwner ¶
func SetOwnerRefsWithoutBlockOwner(object metav1.Object, ownerRefs []metav1.OwnerReference)
func TaintIsWellKnown ¶
TaintIsWellKnown returns true if the taint's key is in the WellKnownTaints list. False otherwise. See WellKnownTaints for more information.
func ToValidDNSLabel ¶
ToValidDNSLabel converts a given string to a valid DNS-1035 spec label. The DNS-1035 spec follows the regex '[a-z]([-a-z0-9]*[a-z0-9])?' and is at most 63 chars long. DNS-1035 is used over DNS-1123 because it is more strict. Kubernetes docs are not always clear when a DNS_LABEL is supposed to be 1035 or 1123 compliant, so we use the more strict version for ease of use.
- Any input symbol that is not valid is converted to a dash ('-').
- Multiple resultant dashes in a row are compressed to a single dash.
- If the starting character is a number, a 'd' is prepended to preserve the number.
- Any non-alphanumeric starting or ending characters are removed.
- If the resultant string is longer than the maximum-allowed 63 characters], characters are removed from the middle and replaced with a double dash ('--') to reduce the string to 63 characters.
func TruncateNodeName ¶
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 Do **NOT** edit this function in a way that would change its output as it needs to provide consistent mappings from string to hash across versions of rook.
func TruncateNodeNameForJob ¶
TruncateNodeNameForJob hashes the nodeName in case it would case the name to be longer than 63 characters and avoids for a K8s 1.22 bug in the job pod name generation. If the job name contains a . or - in a certain position, the pod will fail to create.
func UpdateDeploymentAndWait ¶
func UpdateDeploymentAndWait(ctx context.Context, clusterContext *clusterd.Context, modifiedDeployment *appsv1.Deployment, namespace string, verifyCallback func(action string) error) 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. This method has a generic callback function that each backend can rely on It serves two purposes:
- verify that a resource can be stopped
- verify that we can continue the update procedure
Basically, we go one resource by one and check if we can stop and then if the resource has been successfully updated we check if we can go ahead and move to the next one.
func UpdateMultipleDeployments ¶
func UpdateMultipleDeployments( ctx context.Context, clientset kubernetes.Interface, deployments []*appsv1.Deployment, ) (DeploymentsUpdated, Failures, *int32)
UpdateMultipleDeployments updates multiple deployments and returns DeploymentsUpdated map of deployment names which were updated successfully and the observed generation of the deployments before they were updated. If deployments are already up to date, they are not reported in the DeploymentsUpdated map. The DeploymentsUpdated map can be used with the WaitForDeploymentsToUpdate function. Also returns a list of failures. Each failure returned includes the name of the deployment which could not be updated and the error experienced when attempting to update the deployment.
func UpdateService ¶
func UpdateService( ctx context.Context, 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 ¶
ValidNode returns true if the node (1) is schedulable, (2) meets Rook's placement terms, and (3) is ready. False otherwise.
func WaitForDeploymentImage ¶
func WaitForDeploymentImage(ctx context.Context, 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 ¶
func WaitForJobCompletion(ctx context.Context, 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.
func WatchCR ¶
func WatchCR(resource CustomResource, namespace string, handlers cache.ResourceEventHandlerFuncs, client rest.Interface, objType runtime.Object, done <-chan struct{})
WatchCR begins watching the custom resource (CRD). The call will block until a Done signal is raised during in the context. When the watch has detected a create, update, or delete event, it will handled by the functions in the resourceEventHandlers. After the callback returns, the watch loop will continue for the next event. If the callback returns an error, the error will be logged.
func YamlToContainerResource ¶
func YamlToContainerResource(raw string) (v1.ResourceRequirements, error)
YamlToContainerResource takes raw YAML string and converts it to resourcesrequirements
func YamlToTolerations ¶
func YamlToTolerations(raw string) ([]v1.Toleration, error)
This function takes raw YAML string and converts it to Kubernetes Tolerations array
func YamlToVolumeMounts ¶
func YamlToVolumeMounts(raw string) ([]v1.VolumeMount, error)
This function takes raw YAML string and converts it to Kubernetes Volume mount array.
Types ¶
type ConfigMapKVStore ¶
type ConfigMapKVStore struct {
// contains filtered or unexported fields
}
func NewConfigMapKVStore ¶
func NewConfigMapKVStore(namespace string, clientset kubernetes.Interface, ownerInfo *OwnerInfo) *ConfigMapKVStore
func (*ConfigMapKVStore) ClearStore ¶
func (kv *ConfigMapKVStore) ClearStore(ctx context.Context, storeName string) error
func (*ConfigMapKVStore) SetValue ¶
func (kv *ConfigMapKVStore) SetValue(ctx context.Context, storeName, key, value string) error
func (*ConfigMapKVStore) SetValueWithLabels ¶
type ContainerResource ¶
type ContainerResource struct { Name string `json:"name"` Resource v1.ResourceRequirements `json:"resource"` }
func YamlToContainerResourceArray ¶
func YamlToContainerResourceArray(raw string) ([]ContainerResource, error)
YamlToContainerResourceArray takes raw YAML string and converts it to array of ContainerResource
type CustomResource ¶
type CustomResource struct { // Name of the custom resource Name string // Plural of the custom resource in plural Plural string // Group the custom resource belongs to Group string // Version which should be defined in a const above Version string // Kind is the serialized interface of the resource. Kind string // APIVersion is the full API version name (combine Group and Version) APIVersion string }
CustomResource is for creating a Kubernetes TPR/CRD
type DeleteOptions ¶
type DeleteOptions struct { // MustDelete controls the idempotency of the delete operation. If MustDelete is true and the // resource being deleted does not exist, the delete operation is considered a failure. If // MustDelete is false and the resource being deleted does not exist, the delete operation is // considered a success. MustDelete bool // DeleteOptions is a superset of WaitOptions. WaitOptions }
DeleteOptions are a common set of options controlling the behavior of k8sutil delete operations. DeleteOptions is a superset of WaitOptions.
type DeploymentsUpdated ¶
DeploymentsUpdated is a mapping from deployment name to the observed generation of the old deployment which was updated.
func (*DeploymentsUpdated) Names ¶
func (d *DeploymentsUpdated) Names() (names []string)
Names returns the names of the deployments which were updated.
type Failures ¶
type Failures []Failure
func UpdateMultipleDeploymentsAndWait ¶
func UpdateMultipleDeploymentsAndWait( ctx context.Context, clientset kubernetes.Interface, deployments []*appsv1.Deployment, listFunc func() (*appsv1.DeploymentList, error), ) Failures
func WaitForDeploymentsToUpdate ¶
func WaitForDeploymentsToUpdate( deploymentsUpdated DeploymentsUpdated, progressDeadlineSeconds *int32, listFunc func() (*appsv1.DeploymentList, error), ) Failures
WaitForDeploymentsToUpdate waits for all deployments to update. It returns a list of failures. Each failure includes the name of the deployment which was not updated within the timeout and an error indicating the reason why.
func (*Failures) CollatedErrors ¶
type LinuxIpAddrInfo ¶
type LinuxIpAddrResult ¶
type LinuxIpAddrResult struct { InterfaceName string `json:"ifname"` AddrInfo []LinuxIpAddrInfo `json:"addr_info"` }
LinuxIpAddrResult provides a pared down Go struct for codifying json-formatted output from `ip --json address show`. Each result contains addresses associated with a single interface.
func ParseLinuxIpAddrOutput ¶
func ParseLinuxIpAddrOutput(rawOutput string) ([]LinuxIpAddrResult, error)
ParseLinuxIpAddrOutput parses raw json-encoded `ip --json address show` output
type OwnerInfo ¶
type OwnerInfo struct {
// contains filtered or unexported fields
}
OwnerInfo is to set owner references. Only one of owner and ownerRef must be valid.
func NewOwnerInfo ¶
NewOwnerInfo create a new ownerInfo to set ownerReference by controllerutil
func NewOwnerInfoWithOwnerRef ¶
func NewOwnerInfoWithOwnerRef(ownerRef *metav1.OwnerReference, namespace string) *OwnerInfo
NewOwnerInfoWithOwnerRef create a new ownerInfo to set ownerReference by rook itself
func (*OwnerInfo) SetControllerReference ¶
SetControllerReference set the controller reference of object
type Patcher ¶
type Patcher struct {
// contains filtered or unexported fields
}
Patcher is a utility for patching of objects and their status. Portion of this file is coming from https://github.com/kubernetes-sigs/cluster-api/blob/master/util/patch/patch.go
type WaitOptions ¶
type WaitOptions struct { // Wait defines whether the operation should wait in a loop and verify that the operation was // successful before returning. Wait bool // RetryCount defines how many times the operation should retry verification in the wait loop // before giving up. If RetryCount is zero, the operation should default to a sane value based // on the operation. RetryCount uint // RetryInterval defines the time the operation will wait before retrying verification. If // RetryInterval is zero, the operation should default to a sane value based on the operation. RetryInterval time.Duration // ErrorOnTimeout defines whether the operation should time out with an error. If ErrorOnTimeout // is true and the operation times out, the operation is considered a failure. If ErrorOnTimeout // is false and the operation times out, the operation should log a warning but not report // failure. ErrorOnTimeout bool }
WaitOptions are a common set of options controlling the behavior of k8sutil operations. If WaitOptions are specified, the operation should wait in a loop and verify that the operation being performed was successful.