mutators

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Overview

Package mutators contains useful functions to perform template mutations that require to retrieve live state values from the Kubernetes API. These functions adhere to the "template.TemplateMutationFunction" function signature.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDeploymentReplicas

func SetDeploymentReplicas(enforce bool) resource.TemplateMutationFunction

SetDeploymentReplicas reconciles the number of replicas of a Deployment. If "enforce" is set to true, the value in the template is enforce, overwritting the live value. If the "enforce" is set to false, the live value obtained from the Kubernetes API is used. In general, if the Deployment uses HorizontalPodAutoscaler or any other controller modifies the number of replicas, enforce needs to be "false". Example usage:

&resource.Template[*appsv1.Deployment]{
	TemplateBuilder: deployment(),
	IsEnabled:       true,
	TemplateMutations: []resource.TemplateMutationFunction{
		mutators.SetDeploymentReplicas(!hpaExists()),
	},
},

func SetServiceLiveValues

func SetServiceLiveValues() resource.TemplateMutationFunction

SetServiceLiveValues retrieves some live values of the Service spec from the Kubernetes API to avoid overwriting them. These values are typically set the by the kube-controller-manager (in some rare occasions the user might explicitly set them) and should not be modified by the reconciler. The fields that this function keeps in sync with the live state are:

  • spec.clusterIP
  • spec.ClisterIPs
  • spec.pors[*].nodePort (when the Service type is not ClusterIP)

Example usage:

&resource.Template[*corev1.Service]{
	TemplateBuilder: service(req.Namespace, instance.Spec.ServiceAnnotations),
	IsEnabled:       true,
	TemplateMutations: []resource.TemplateMutationFunction{
		mutators.SetServiceLiveValues(),
	},
}

Types

type RolloutTrigger

type RolloutTrigger struct {
	Name          string
	ConfigMapName *string
	SecretName    *string
}

func (RolloutTrigger) Add

func (trigger RolloutTrigger) Add(params ...string) resource.TemplateMutationFunction

Add adds the trigger to the Deployment/StatefulSet

func (RolloutTrigger) GetAnnotationKey

func (rt RolloutTrigger) GetAnnotationKey(annotationsDomain string) string

GetAnnotationKey returns the annotation key to be used in the Pods that read from the config source defined in the RolloutTrigger.

func (RolloutTrigger) GetHash

func (rt RolloutTrigger) GetHash(ctx context.Context, cl client.Client, namespace string) (string, error)

GetHash returns the hash of the data contained in the RolloutTrigger config source

Jump to

Keyboard shortcuts

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