utils

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFileMountSource added in v0.5.0

func FindFileMountSource(filePath string, mounts []config.Mount) (string, error)

FindFileMountSource returns a mounted file's source location on the host

func FindFlagValueRaw

func FindFlagValueRaw(command []string, flag string) []string

FindFlagValueRaw returns the value of a specific flag in a commands slice. The following flag representations are supported:

--flag=foo
--flag foo
--flag
-flag=foo
-flag foo
-flag

Notable ambiguous behavior:

--flag="foo"           -> `"foo"`
--flag=foo --flag2=bar -> "foo --flag2=bar"
--flag=   foo          -> "foo"
--flag=                -> ""

func FindInnerValue

func FindInnerValue(values []string, flag string) []string

FindInnerValue returns the value of a specific flag when the format is flag1=value1,flag3=value3,flag3=value3

func GetAllObjectsMetadata added in v0.5.0

func GetAllObjectsMetadata(ctx context.Context, c client.Client, namespace string, selector labels.Selector, limit int64) ([]metav1.PartialObjectMetadata, error)

GetAllObjectsMetadata returns the object metadata for resources returned by 'kubectl get all' in a given namespace or all namespaces if it's set to "". It retrieves objects by portions set by limit.

func GetCommandOptionFromDeployment

func GetCommandOptionFromDeployment(ctx context.Context, c client.Client, deploymentName, containerName, namespace, option string) ([]string, error)

GetCommandOptionFromDeployment returns command and args from a specific deployment container.

func GetContainerCommand added in v0.5.0

func GetContainerCommand(pod corev1.Pod, containerName string) (string, error)

GetContainerCommand returns the used container command

func GetContainerFromDeployment

func GetContainerFromDeployment(deployment *appsv1.Deployment, containerName string) (container corev1.Container, found bool)

GetContainerFromDeployment returns a container object with a specific cainerName, if such container is not present it retuns found=false

func GetContainerFromPod added in v0.5.0

func GetContainerFromPod(pod *corev1.Pod, containerName string) (container corev1.Container, found bool)

GetContainerFromPod returns a container object with a specific cainerName, if such container is not present it retuns found=false

func GetContainerFromStatefulSet

func GetContainerFromStatefulSet(statefulSet *appsv1.StatefulSet, containerName string) (container corev1.Container, found bool)

GetContainerFromStatefulSet returns a container object with a specific cainerName, if such container is not present it retuns found=false

func GetDeploymentPods added in v0.4.0

func GetDeploymentPods(ctx context.Context, c client.Client, name, namespace string) ([]corev1.Pod, error)

GetDeploymentPods returns all pods of a given deployment.

func GetFileDataFromVolume

func GetFileDataFromVolume(ctx context.Context, c client.Client, namespace string, volume corev1.Volume, fileName string) ([]byte, error)

GetFileDataFromVolume returns byte slice of the value of a specific Data field in a ConfigMap or Secret volume

func GetKubeProxyConfig added in v0.5.0

func GetKubeProxyConfig(ctx context.Context, podExecutor pod.PodExecutor, kubeProxyPath string) (*config.KubeProxyConfig, error)

GetKubeProxyConfig returns the kube-proxy config specified by it's path

func GetKubeletCommand

func GetKubeletCommand(ctx context.Context, podExecutor pod.PodExecutor) (string, error)

GetKubeletCommand returns the used kubelet command

func GetKubeletConfig

func GetKubeletConfig(ctx context.Context, podExecutor pod.PodExecutor, rawKubeletCommand string) (*config.KubeletConfig, error)

GetKubeletConfig returns the kubelet config specified in the kubelet command's option `--config`

func GetNamespaces

func GetNamespaces(ctx context.Context, c client.Client) (map[string]corev1.Namespace, error)

GetNamespaces returns a map containing all namespaces, where the names of the namespaces are used as a keys.

func GetNodeConfigz

func GetNodeConfigz(ctx context.Context, coreV1RESTClient rest.Interface, nodeName string) (*config.KubeletConfig, error)

GetNodeConfigz returns the runtime kubelet config

func GetNodes

func GetNodes(ctx context.Context, c client.Client, limit int64) ([]corev1.Node, error)

GetNodes return all nodes. It retrieves pods by portions set by limit.

func GetNodesAllocatablePodsNum added in v0.4.0

func GetNodesAllocatablePodsNum(pods []corev1.Pod, nodes []corev1.Node) map[string]int

GetNodesAllocatablePodsNum return the number of free allocatable spots of pods for all nodes.

func GetObjectsMetadata

func GetObjectsMetadata(ctx context.Context, c client.Client, gvk schema.GroupVersionKind, namespace string, selector labels.Selector, limit int64) ([]metav1.PartialObjectMetadata, error)

GetObjectsMetadata returns the object metadata for all resources of a given group version kind for a namespace, or all namespaces if it's set to "". It retrieves objects by portions set by limit.

func GetPods

func GetPods(ctx context.Context, c client.Client, namespace string, selector labels.Selector, limit int64) ([]corev1.Pod, error)

GetPods returns all pods for a given namespace, or all namespaces if it's set to empty string "". It retrieves pods by portions set by limit.

func GetReplicaSets added in v0.4.0

func GetReplicaSets(ctx context.Context, c client.Client, namespace string, selector labels.Selector, limit int64) ([]appsv1.ReplicaSet, error)

GetReplicaSets returns all replicaSets for a given namespace, or all namespaces if it's set to empty string "". It retrieves replicaSets by portions set by limit.

func GetVolumeConfigByteSliceByMountPath

func GetVolumeConfigByteSliceByMountPath(ctx context.Context, c client.Client, deployment *appsv1.Deployment, containerName, mountPath string) ([]byte, error)

GetVolumeConfigByteSliceByMountPath returns the byte slice data of a specific volume in a deployment by the volumes mountPath and containerName

func GetVolumeFromDeployment

func GetVolumeFromDeployment(deployment *appsv1.Deployment, volumeName string) (volume corev1.Volume, found bool)

GetVolumeFromDeployment returns a volume object with a specific volumeName, if such volume is not present it retuns found=false

func GetVolumeFromStatefulSet

func GetVolumeFromStatefulSet(statefulSet *appsv1.StatefulSet, volumeName string) (volume corev1.Volume, found bool)

GetVolumeFromStatefulSet returns a volume object with a specific volumeName, if such volume is not present it retuns found=false

func IsFlagSet

func IsFlagSet(rawCommand, option string) bool

IsFlagSet returns true if a specific flag is set in the command

func NodeReadyStatus

func NodeReadyStatus(node corev1.Node) bool

NodeReadyStatus returns true if the given node has NodeReady status condition true and false in every other case.

func RESTConfigFromFile added in v0.3.0

func RESTConfigFromFile(filePath string) (*rest.Config, error)

RESTConfigFromFile builds a *rest.Config from a file.

func SelectNodes added in v0.5.0

func SelectNodes(nodes []corev1.Node, nodesAllocatablePods map[string]int, labels []string) ([]corev1.Node, []rule.CheckResult)

SelectNodes returns a subset of nodes. Containing a single node per unique label value combination. Nodes that have reached their allocation limit will not be returned. If no labels are provided all allocatable nodes will be returned.

func SelectPodOfReferenceGroup added in v0.4.0

func SelectPodOfReferenceGroup(pods []corev1.Pod, nodesAllocatablePods map[string]int, target rule.Target) (map[string][]corev1.Pod, []rule.CheckResult)

SelectPodOfReferenceGroup returns a single pod per owner reference group as well as groups the returned pods by the nodes they are scheduled on. Pods that do not have an owner reference will always be selected. Pods will not be grouped to nodes, which have reached their allocation limit. It tries to pick the pods in a way that fewer nodes will be selected.

Types

This section is empty.

Jump to

Keyboard shortcuts

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