util

package
v0.0.0-...-b39e775 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindContainerInPodSpec

func FindContainerInPodSpec(podSpec *core.PodSpec, containerName string) (containerResource *core.Container, containerNumber int, foundContainer bool)

FindContainerInPodSpec finds a named container in a core/v1.PodSpec resource.

func FindContainerInUnstructured

func FindContainerInUnstructured(u *unstructured.Unstructured, containerName string) (containerResource *core.Container, podSpecPath string, containerNumber int, foundContainer bool, returnedErr error)

FindContainerInUnstructured is a wrapper around FindPodSpecInUnstructured and FindContainerInPodSpec.

func FindPodSpecInUnstructured

func FindPodSpecInUnstructured(podController *unstructured.Unstructured) (podSpec *core.PodSpec, foundPath string, returnErr error)

findPodSpecInUnstructured searches an unstructured.Unstructured resource for a pod specification, returning it as a core.podspec type, along with the path where the pod spec was found (such as spec.template.spec).

func GetControllerFromPod

func GetControllerFromPod(kubeClientResources KubeClientResources, pod *core.Pod) (*unstructured.Unstructured, error)

GetControllerFromPod accepts a typed pod object, and returns the pod-controller which owns the pod. E.G. an owning pod-controller might be a Kubernetes Deployment, DaemonSet, or CronJob.

func GetUnstructuredResourceFromObjectRef

func GetUnstructuredResourceFromObjectRef(kubeClientResources KubeClientResources, objectRef core.ObjectReference) (resource *unstructured.Unstructured, found bool, err error)

GetUnstructuredResourceFromObjectRef fffetches a resource from in-cluster, based on the GroupVersionKind from the provided core.ObjectReference. An ObjectReference is typically included in a Kube Event.

func InstallSignalHandler

func InstallSignalHandler(stop chan struct{})

InstallSignalHandler sends a message on sigint or sigterm

func MultiplyResourceQuantity

func MultiplyResourceQuantity(q *resource.Quantity, multiplier float64) (*resource.Quantity, error)

MultiplyResourceQuantity multiplies a k8s.io/apimachinery/pkg/api/resource.Quantity with a float64, returning a new resource.Quantity. If an error is returned, the resource.Quantity will be its zero value. To avoid losing precision and occasional failures converting to int64, the resource.Quantity and multiplier are converted to inf.Dec types to perform multiplication. For reference, see the quantity.AsInt64 documentation: https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity.AsInt64 Note that certain multipliers cause the units of the result to become smaller, I.E. from Gi to Mi or Ki.

func ParseArgs

func ParseArgs(options interface{})

ParseArgs needs a struct compatible to jeddevdk/go-flags and will fill it based on CLI parameters.

func PatchContainerMemoryLimits

func PatchContainerMemoryLimits(kubeClientResources KubeClientResources, resource *unstructured.Unstructured, containerName string, newContainerMemoryLimits *resource.Quantity) (*unstructured.Unstructured, error)

patchContainerMemoryLimits patches the named container with a new resources.limits.memory. The resource to be patched is of type unstructured.Unstructured, to support multiple Kinds that have a pod spec, using FindPodSpecInUnstructured() to locate the pod spec and containers.

Types

type KubeClientResources

type KubeClientResources struct {
	Client        kubernetes.Interface
	DynamicClient dynamic.Interface // used to find owning pod-controller
	RESTMapper    meta.RESTMapper   // used with dynamicClient
}

KubeClientResources bundles together Kubernetes clients and related resources.

func CreateKubeClientResources

func CreateKubeClientResources() KubeClientResources

CreateKubeClientResources returns a KubeClientResources type, trying first in-cluster, then local, KubeConfig.

type PodLister

type PodLister interface {
	Pods(namespace string) listersV1.PodNamespaceLister
}

Jump to

Keyboard shortcuts

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