kubernetes

package
v0.0.0-...-7801012 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOrReplaceContainer

func AddOrReplaceContainer(containerName string, container v1.Container, podSpec *v1.PodSpec)

AddOrReplaceContainer replace the existing container or add if it doesn't exist in the .spec.containers attribute

func AddOrReplaceVolume

func AddOrReplaceVolume(podSpec *corev1.PodSpec, volumes ...corev1.Volume)

AddOrReplaceVolume adds or removes the given volumes to the PodSpec. If there's already a volume with the same name, it's replaced.

func AddOrReplaceVolumeMount

func AddOrReplaceVolumeMount(containerIndex int, podSpec *corev1.PodSpec, mounts ...corev1.VolumeMount)

AddOrReplaceVolumeMount same as AddOrReplaceVolume, but with VolumeMounts in a specific container

func AnnotateDeploymentConfigChecksum

func AnnotateDeploymentConfigChecksum(workflow *operatorapi.SonataFlow, deployment *appsv1.Deployment, userPropsCM *v1.ConfigMap, managedPropsCM *v1.ConfigMap) error

AnnotateDeploymentConfigChecksum adds the checksum/config annotation to the template annotations of the Deployment to set the current configuration. If the checksum has changed from the previous value, the restartedAt annotation is also added and a new rollout is started. Code adapted from here: https://github.com/kubernetes/kubectl/blob/release-1.26/pkg/polymorphichelpers/objectrestarter.go#L44

func CreateOrReplaceEnv

func CreateOrReplaceEnv(container *v1.Container, name, value string)

func GetAnnotationAsBool

func GetAnnotationAsBool(object client.Object, key string) bool

GetAnnotationAsBool returns the boolean value from the given annotation. If the annotation is not present or is there an error in the ParseBool conversion, returns false.

func GetContainerByName

func GetContainerByName(name string, podSpec *v1.PodSpec) (*v1.Container, int)

GetContainerByName returns a pointer to the Container within the given Deployment. If none found, returns nil. It also returns the position where the container was found, -1 if none

func GetContainerPortByName

func GetContainerPortByName(name string, container *v1.Container) (*v1.ContainerPort, int)

GetContainerPortByName returns a pointer to the ContainerPort within the given Container. If none found, returns nil. It also returns the position where the container port was found, -1 if none.

func GetDeploymentUnavailabilityMessage

func GetDeploymentUnavailabilityMessage(deployment *appsv1.Deployment) string

GetDeploymentUnavailabilityMessage returns a string explaining why the given deployment is unavailable. If empty, there's no replica failure. Note that the Deployment might be available, but a second replica failed to scale. Always check IsDeploymentAvailable.

See: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#failed-deployment

func GetImagePullPolicy

func GetImagePullPolicy(imageTag string) corev1.PullPolicy

GetImagePullPolicy gets the default corev1.PullPolicy depending on the image tag specified. It follows the conventions of docker client and OpenShift. If no tag specified, it assumes latest. Returns PullAlways if latest tag, empty otherwise to let the cluster figure it out. See: https://kubernetes.io/docs/concepts/containers/images/#updating-images

func GetImageTag

func GetImageTag(imageTag string) string

GetImageTag gets the tag after `:` in an image tag or empty if not found.

func GetLastGeneration

func GetLastGeneration(namespace string, name string, c client.Client, ctx context.Context) int64

func GetServicePortByName

func GetServicePortByName(name string, service *v1.Service) (*v1.ServicePort, int)

GetServicePortByName returns a pointer to the ServicePort within the given Service. If none found, returns nil. It also returns the position where the service port por was found, -1 if none.

func IsDeploymentAvailable

func IsDeploymentAvailable(deployment *appsv1.Deployment) bool

IsDeploymentAvailable verifies if the Deployment conditions match the Available status

func IsDeploymentFailed

func IsDeploymentFailed(deployment *appsv1.Deployment) bool

IsDeploymentFailed returns true in case of Deployment not available (IsDeploymentAvailable returns false) or it has a condition of DeploymentReplicaFailure == true.

func IsDeploymentMinimumReplicasUnavailable

func IsDeploymentMinimumReplicasUnavailable(deployment *appsv1.Deployment) bool

IsDeploymentMinimumReplicasUnavailable verifies if the deployment has the minimum replicas available

func IsObjectNew

func IsObjectNew(object ctrl.Object) bool

IsObjectNew verifies if the given object hasn't been created in the cluster

func LoadResourceFromYaml

func LoadResourceFromYaml(scheme *runtime.Scheme, data string) (ctrl.Object, error)

LoadResourceFromYaml returns a Kubernetes resource from its serialized YAML definition.

func LoadUnstructuredFromYaml

func LoadUnstructuredFromYaml(data string) (ctrl.Object, error)

LoadUnstructuredFromYaml returns an unstructured resource from its serialized YAML definition.

func MarkDeploymentToRollout

func MarkDeploymentToRollout(deployment *appsv1.Deployment) error

MarkDeploymentToRollout marks the given Deployment to restart now. The object must be updated. Code adapted from here: https://github.com/kubernetes/kubectl/blob/release-1.26/pkg/polymorphichelpers/objectrestarter.go#L44

func MustSafeDNS1035

func MustSafeDNS1035(prefix, s string) string

MustSafeDNS1035 see SafeDNS1035. Use this function only if you control the prefix.

func ReplaceResource

func ReplaceResource(ctx context.Context, c client.Client, res ctrl.Object) (bool, error)

ReplaceResource allows to completely replace a resource on Kubernetes, taking care of immutable fields and resource versions.

func RetrieveServiceURL

func RetrieveServiceURL(service *v1.Service) (*apis.URL, error)

RetrieveServiceURL function that based on the service name, namespace and eventually the nodeport, will provide the service URI

func SafeDNS1035

func SafeDNS1035(prefix, s string) (string, error)

SafeDNS1035 generates a safe encoded string based on "s" with the given prefix. Ideally used with internal generated names.

See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names

func SecurityDefaults

func SecurityDefaults() *corev1.SecurityContext

func SetAnnotation

func SetAnnotation(object client.Object, key, value string)

SetAnnotation Safely set the annotation to the object

func ToTypedLocalReference

func ToTypedLocalReference(object ctrl.Object) *v1.TypedLocalObjectReference

ToTypedLocalReference ...

func VolumeAddVolumeProjectionConfigMap

func VolumeAddVolumeProjectionConfigMap(volumes []corev1.Volume, cmName, mountName string) []corev1.Volume

VolumeAddVolumeProjectionConfigMap adds a new ConfigMapProjection to the given Volume array. It looks for the given mount name in the Volume array. If finds it, adds a new projection for the given ConfigMap. If it doesn't find it, adds a new VolumeSource and the projection to it.

func VolumeConfigMap

func VolumeConfigMap(name string, cmName string, items ...corev1.KeyToPath) corev1.Volume

VolumeConfigMap creates a new Volume referencing the given ConfigMap name.

func VolumeMount

func VolumeMount(name string, readonly bool, mountPath string) corev1.VolumeMount

func VolumeMountAdd

func VolumeMountAdd(volumeMount []corev1.VolumeMount, name, mountPath string) []corev1.VolumeMount

VolumeMountAdd adds a new VolumeMount to the given collection. If there's already a VolumeMount with the same mount path, the function overrides the name.

func VolumeProjectionAddConfigMap

func VolumeProjectionAddConfigMap(volumeSource *corev1.ProjectedVolumeSource, cmName string, items ...corev1.KeyToPath)

VolumeProjectionAddConfigMap adds the given ConfigMap to the ProjectedVolumeSource sources. Overrides the items if already exists in the list.

Types

type Collection

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

A Collection is a container of Kubernetes resources.

func NewCollection

func NewCollection(objects ...ctrl.Object) *Collection

NewCollection creates a new empty collection.

func (*Collection) Add

func (c *Collection) Add(resource ctrl.Object)

Add adds a resource to the collection.

func (*Collection) AddAll

func (c *Collection) AddAll(resource []ctrl.Object)

AddAll adds all resources to the collection.

func (*Collection) AddFirst

func (c *Collection) AddFirst(resource ctrl.Object)

AddFirst adds a resource to the head of the collection.

func (*Collection) AsKubernetesList

func (c *Collection) AsKubernetesList() *corev1.List

AsKubernetesList returns all resources wrapped in a Kubernetes list.

func (*Collection) GetConfigMap

func (c *Collection) GetConfigMap(filter func(*corev1.ConfigMap) bool) *corev1.ConfigMap

GetConfigMap returns a ConfigMap that matches the given function.

func (*Collection) GetContainer

func (c *Collection) GetContainer(filter func(container *corev1.Container) bool) *corev1.Container

GetContainer --.

func (*Collection) GetContainerByName

func (c *Collection) GetContainerByName(name string) *corev1.Container

GetContainerByName --.

func (*Collection) GetController

func (c *Collection) GetController(filter func(object ctrl.Object) bool) ctrl.Object

GetController returns the controller associated with the workflow (e.g. Deployment).

func (*Collection) GetCronJob

func (c *Collection) GetCronJob(filter func(job *batchv1.CronJob) bool) *batchv1.CronJob

GetCronJob returns a CronJob that matches the given function.

func (*Collection) GetDeployment

func (c *Collection) GetDeployment(filter func(*appsv1.Deployment) bool) *appsv1.Deployment

GetDeployment returns a Deployment that matches the given function.

func (*Collection) GetDeploymentForWorkflow

func (c *Collection) GetDeploymentForWorkflow(workflow *operatorapi.SonataFlow) *appsv1.Deployment

GetDeploymentForWorkflow returns a Deployment for the given workflow.

func (*Collection) GetPodMonitor

func (c *Collection) GetPodMonitor(filter func(*monitoringv1.PodMonitor) bool) *monitoringv1.PodMonitor

func (*Collection) GetRoute

func (c *Collection) GetRoute(filter func(*routev1.Route) bool) *routev1.Route

GetRoute returns a Route that matches the given function.

func (*Collection) GetService

func (c *Collection) GetService(filter func(*corev1.Service) bool) *corev1.Service

GetService returns a Service that matches the given function.

func (*Collection) GetServiceForWorkflow

func (c *Collection) GetServiceForWorkflow(workflow *operatorapi.SonataFlow) *corev1.Service

GetServiceForWorkflow returns a user Service for the given workflow.

func (*Collection) HasDeployment

func (c *Collection) HasDeployment(filter func(*appsv1.Deployment) bool) bool

HasDeployment returns true if a deployment matching the given condition is present.

func (*Collection) Items

func (c *Collection) Items() []ctrl.Object

Items returns all resources belonging to the collection.

func (*Collection) Remove

func (c *Collection) Remove(selector func(runtime.Object) bool) runtime.Object

Remove removes the given element from the collection and returns it.

func (*Collection) RemoveConfigMap

func (c *Collection) RemoveConfigMap(filter func(*corev1.ConfigMap) bool) *corev1.ConfigMap

RemoveConfigMap removes and returns a ConfigMap that matches the given function.

func (*Collection) RemoveDeployment

func (c *Collection) RemoveDeployment(filter func(*appsv1.Deployment) bool) *appsv1.Deployment

RemoveDeployment removes and returns a Deployment that matches the given function.

func (*Collection) Size

func (c *Collection) Size() int

Size returns the number of resources belonging to the collection.

func (*Collection) Visit

func (c *Collection) Visit(visitor func(runtime.Object))

Visit executes the visitor function on all resources.

func (*Collection) VisitConfigMap

func (c *Collection) VisitConfigMap(visitor func(*corev1.ConfigMap))

VisitConfigMap executes the visitor function on all ConfigMap resources.

func (*Collection) VisitContainer

func (c *Collection) VisitContainer(visitor func(container *corev1.Container))

VisitContainer executes the visitor function on all Containers inside deployments or other resources.

func (*Collection) VisitCronJob

func (c *Collection) VisitCronJob(visitor func(*batchv1.CronJob))

VisitCronJob executes the visitor function on all CronJob resources.

func (*Collection) VisitCronJobE

func (c *Collection) VisitCronJobE(visitor func(*batchv1.CronJob) error) error

VisitCronJobE executes the visitor function on all CronJob resources.

func (*Collection) VisitDeployment

func (c *Collection) VisitDeployment(visitor func(*appsv1.Deployment))

VisitDeployment executes the visitor function on all Deployment resources.

func (*Collection) VisitDeploymentE

func (c *Collection) VisitDeploymentE(visitor func(*appsv1.Deployment) error) error

VisitDeploymentE executes the visitor function on all Deployment resources.

func (*Collection) VisitE

func (c *Collection) VisitE(visitor func(runtime.Object) error) error

VisitE executes the visitor function on all resources breaking if the visitor function returns an error.

func (*Collection) VisitMetaObject

func (c *Collection) VisitMetaObject(visitor func(metav1.Object))

VisitMetaObject executes the visitor function on all meta.Object resources.

func (*Collection) VisitPodMonitor

func (c *Collection) VisitPodMonitor(visitor func(*monitoringv1.PodMonitor))

func (*Collection) VisitPodSpec

func (c *Collection) VisitPodSpec(visitor func(container *corev1.PodSpec))

VisitPodSpec executes the visitor function on all PodSpec inside deployments or other resources.

func (*Collection) VisitPodTemplateMeta

func (c *Collection) VisitPodTemplateMeta(visitor func(meta *metav1.ObjectMeta))

VisitPodTemplateMeta executes the visitor function on all PodTemplate metadata inside deployments or other resources.

func (*Collection) VisitRoute

func (c *Collection) VisitRoute(visitor func(*routev1.Route))

VisitRoute executes the visitor function on all Route resources.

func (*Collection) VisitService

func (c *Collection) VisitService(visitor func(*corev1.Service))

VisitService executes the visitor function on all Service resources.

type DeploymentUnavailabilityReader

type DeploymentUnavailabilityReader interface {
	// ReasonMessage returns the reason message in string format fetched from the culprit resource. For example, a Container status.
	ReasonMessage() (string, error)
}

DeploymentUnavailabilityReader implementations find the reason behind a deployment failure

func DeploymentTroubleshooter

func DeploymentTroubleshooter(client client.Client, deployment *v1.Deployment, container string) DeploymentUnavailabilityReader

DeploymentTroubleshooter creates a new DeploymentUnavailabilityReader for finding out why a deployment failed

Jump to

Keyboard shortcuts

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