reservedkeys

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractOutdated

func ExtractOutdated(currentSpec, existing map[string]string) (map[string]string, error)

ExtractOutdated returns the subset of the last-applied annotations encoded in existing[consts.AnnotationLastAppliedAnnotations] whose keys are no longer present in currentSpec, i.e. annotations that were set by a previous reconcile (via MergeAnnotationsTracked) but have since been removed from the spec and so must be deleted from the live object.

func Filter

func Filter(
	logger logr.Logger, metadataType MetadataType, keys map[string]string, isReserved IsReservedFunc,
) map[string]string

Filter drops any key from keys for which isReserved returns true, logging an Info message for each one dropped so it's clear why a user-provided label/annotation didn't take effect. metadataType is only used to label the log line ("label" vs "annotation").

This is logged at Info rather than Error level: it's an expected, routine situation (not a bug), and controller-runtime's zap logger attaches a full stack trace to every Error-level log line in production mode, which would otherwise spam the logs on every reconcile of an object whose spec sets a reserved key.

func Merge

func Merge(base, additions map[string]string) map[string]string

Merge returns a new map with base's entries overlaid by additions. It never mutates base, so it's safe to call even when base is shared with another object (e.g. a Deployment's labels map reused for its Pod template).

func MergeAnnotationsTracked

func MergeAnnotationsTracked(base, additions map[string]string) map[string]string

MergeAnnotationsTracked behaves like Merge, but also records additions (JSON-encoded) under consts.AnnotationLastAppliedAnnotations.

Reconcilers that patch an existing object directly (rather than relying on Server-Side Apply to relinquish removed fields automatically) need this so that a later call comparing the current spec against this tracked value can detect keys that were removed from the spec since the previous reconcile, and delete them from the live object instead of leaving them there forever.

Types

type IsReservedFunc

type IsReservedFunc func(key string) bool

IsReservedFunc reports whether a label/annotation key is reserved for internal operator or Kubernetes use and must be dropped from any user-supplied labels/annotations.

func NewChecker

func NewChecker(extraExact ...string) IsReservedFunc

NewChecker returns an IsReservedFunc that reserves any key carrying the operator's common label prefix (consts.OperatorLabelPrefix), plus any of the exact keys passed in extraExact (e.g. a hardcoded selector label such as "app", or Kubernetes-managed keys such as "deployment.kubernetes.io/revision").

type MetadataType

type MetadataType string

MetadataType identifies whether a set of keys being filtered are labels or annotations, for logging purposes.

const (
	// MetadataTypeLabel identifies a map of Kubernetes labels.
	MetadataTypeLabel MetadataType = "label"
	// MetadataTypeAnnotation identifies a map of Kubernetes annotations.
	MetadataTypeAnnotation MetadataType = "annotation"
)

func (MetadataType) String

func (m MetadataType) String() string

Jump to

Keyboard shortcuts

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