metadata

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package metadata provides shared helpers for managing Cloud Foundry resource metadata (labels and annotations) across the provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMetadata

func BuildMetadata(mg resource.Managed, userLabels, userAnnotations map[string]*string) *cfresource.Metadata

BuildMetadata constructs a *cfresource.Metadata for a Create or Update call by merging Crossplane default labels with user-specified labels and annotations.

Default labels are obtained from resource.GetExternalTags(mg), which returns the three canonical keys (crossplane-kind, crossplane-name, crossplane-providerconfig). User-provided labels take precedence over defaults when keys collide.

The mg parameter must implement resource.Managed so that GetExternalTags can extract the GVK, name, and ProviderConfig reference.

Nil pointer values in userLabels and userAnnotations are treated as deletion markers per CF API convention: they are passed through to the resulting Metadata via RemoveLabel/RemoveAnnotation (setting the key's value to nil). On Create calls, nil values are no-ops (you cannot delete a label that does not yet exist). On Update calls, include nil values for keys you want to explicitly remove from the CF resource.

func DiffMetadata

func DiffMetadata(desiredLabels, desiredAnnotations, actualLabels, actualAnnotations map[string]*string) *cfresource.Metadata

DiffMetadata computes the metadata diff needed for an Update call. It returns nil if no metadata changes are needed, otherwise a *cfresource.Metadata containing only the keys that need to change.

The diff follows CF API merge-patch semantics:

  • Keys in desiredLabels/desiredAnnotations that are new or different from actual are included (add/update)
  • Keys with nil pointer values in desired are included as deletion markers
  • Keys in actual but absent from desired are NOT included (left unchanged on the CF server)

Callers that want to delete a key that exists on the CF resource must include it in the desired map with a nil pointer value. For example, to remove label "env" from a CF resource, set desiredLabels["env"] = nil.

Important: BuildMetadata always includes Crossplane default labels (crossplane-kind, crossplane-name, crossplane-providerconfig) in the desired set, so they are automatically maintained on every Update. Callers must ensure desiredLabels and desiredAnnotations come from BuildMetadata (or an equivalent merge) to avoid accidentally reverting default labels.

func IsMetadataUpToDate

func IsMetadataUpToDate(desiredLabels, desiredAnnotations, actualLabels, actualAnnotations map[string]*string) bool

IsMetadataUpToDate reports whether labels and annotations are in sync between the desired state and the actual state of the CF resource. It returns true only when every key in desiredLabels/desiredAnnotations is present and equal in the corresponding actual map. Extra keys in actual that are not in desired are ignored (they may be set by the CF platform or other actors).

Callers should pass the full desired set (from BuildMetadata, which includes Crossplane default labels) as desiredLabels/desiredAnnotations, not just the CR spec's user labels.

func MetadataMapContains

func MetadataMapContains(desired, actual map[string]*string) bool

MetadataMapContains reports whether all keys in desired are present and match in actual. Extra keys in actual that are not in desired are ignored. This implements a subset check: desired ⊆ actual.

Use MetadataMapContains (not MetadataMapEqual) when checking whether a CF resource's metadata is up-to-date with the desired state, because the CF resource may have extra labels or annotations set by the platform or other actors that the provider does not manage.

func MetadataMapEqual

func MetadataMapEqual(desired, actual map[string]*string) bool

MetadataMapEqual reports whether two metadata maps (labels or annotations) are semantically equal. nil and empty maps are considered equal. Pointer values are dereferenced for comparison; nil pointers indicate deletion markers and are treated as a distinct value (not equal to a non-nil pointer to an empty string).

func StripDefaultLabels

func StripDefaultLabels(labels map[string]*string) map[string]*string

StripDefaultLabels removes Crossplane default label keys from a label map. The default labels (crossplane-kind, crossplane-name, crossplane-providerconfig) are infrastructure metadata computed by the controller from the CR identity. They should not be late-initialized into spec.ForProvider.Labels because the controller recomputes them on every reconcile via BuildMetadata.

Types

This section is empty.

Jump to

Keyboard shortcuts

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