Kubernetes

6 min read

Answer the questions about any Kubernetes object that every controller asks: its conditions and their reasons, whether it is ready, synced, terminating or exists, and the fields of its spec and status, read safely.

Reference

FunctionDescription
annotationsReturns the metadata.annotations map.
conditionMessageReturns the message field of a named condition.
conditionReasonReturns the reason field of a named condition.
conditionsHealthyReports whether an object’s standard conditions say it is healthy, for any kind that reports them: Flux, cert-manager, Crossplane, Argo and most operators.
generationReturns metadata.generation as int64.
getNavigates a nested path through a Kubernetes object using variadic string segments.
getAnnotationReturns the value of a single annotation key from metadata.annotations.
getAnnotationIntReturns an annotation value parsed as int64.
getLabelReturns the value of a single label key from metadata.labels.
getLabelIntReturns a label value parsed as int64.
getStatusReturns the string value of a specific key from status.
hasAnnotationReturns true when the object has the given annotation key with a non-empty value.
hasConditionReturns true if status.conditions contains a condition of the given type with status: "True".
hasLabelReturns true when the object has the given label key with a non-empty value.
hasStatusReturns true when the given status field exists and is non-empty.
isSyncedReturns true when metadata.generation == status.observedGeneration, meaning the controller has fully processed the current spec.
isTerminatingReturns true when metadata.deletionTimestamp is set — the object exists but is being deleted.
labelMatchesReturns true when the object’s labels contain every key/value pair given as arguments.
labelsReturns the metadata.labels map.
metaReturns the metadata map of a Kubernetes object.
nameReturns metadata.name or an empty string.
namespaceReturns metadata.namespace or an empty string.
observedGenerationReturns status.observedGeneration as int64.
ownerKindReturns the kind of the first ownerReference.
ownerNameReturns the name of the first ownerReference.
phaseReturns status.phase as a string.
resourceCPUReturns spec.resources.requests.cpu from any object.
resourceExistsReports whether obj is a Kubernetes object: a map with a metadata.name.
resourceMemoryReturns spec.resources.requests.memory from any object.
specReturns the spec map of a Kubernetes object.
statusReturns the status map of a Kubernetes object.

Functions

annotations

annotations returns the metadata.annotations map. Returns an empty map if absent.

{{ mapGet (annotations .deployment) "example.com/owner" }}  → "team-payments"

conditionMessage

conditionMessage returns the message field of a named condition. Returns "" when absent.

{{ conditionMessage .deployment "Available" }}  → "Deployment has minimum availability."

conditionReason

conditionReason returns the reason field of a named condition. Returns "" when absent.

{{ conditionReason .deployment "Available" }}  → "MinimumReplicasAvailable"

conditionsHealthy

conditionsHealthy reports whether an object’s standard conditions say it is healthy, for any kind that reports them: Flux, cert-manager, Crossplane, Argo and most operators. It is true when the controller has seen the latest spec and either Ready, or Available when there is no Ready, is “True”. It is false when there are no such conditions, Stalled or Reconciling is “True”, Progressing or Synced is “False”, or status.observedGeneration (or Ready’s own observedGeneration) is behind metadata.generation. For a Deployment or StatefulSet use rolloutComplete as well: Available stays “True” while a rollout is stuck on old pods.

{{ conditionsHealthy .helmRelease }}  → true
{{ conditionsHealthy .deployment }}  → true

generation

generation returns metadata.generation as int64. Increments on every spec change. Returns 0 when absent.

{{ generation .deployment }}  → 3

get

get navigates a nested path through a Kubernetes object using variadic string segments. Returns nil if any segment is missing. Nil-safe at every level.

{{ get .cronjob "status" "lastScheduleTime" }}  → "2026-05-19T10:00:00Z"

getAnnotation

getAnnotation returns the value of a single annotation key from metadata.annotations. Returns "" when the key is absent or the object has no annotations.

{{ getAnnotation .deployment "example.com/owner" }}  → "team-payments"

getAnnotationInt

getAnnotationInt returns an annotation value parsed as int64. Returns 0 when the key is absent or the value is non-numeric. Use with autoscale targets and thresholds stored in annotations.

{{ getAnnotationInt .deployment "deployment.kubernetes.io/revision" }}  → 2

getLabel

getLabel returns the value of a single label key from metadata.labels. Returns "" when the key is absent or the object has no labels.

{{ getLabel .deployment "app" }}                     → "web"
{{ getLabel .deployment "profile" | default "medium" }}  → "medium"

getLabelInt

getLabelInt returns a label value parsed as int64. Returns 0 when the key is absent or the value is non-numeric.

{{ getLabelInt .deployment "example.com/shards" }}  → 4

getStatus

getStatus returns the string value of a specific key from status. Numeric and boolean values are converted to their string form. Returns "" when the field is absent, nil, or a structured value (map, slice) — use get or status for those.

{{ getStatus .pod "phase" }}  → "Running"

hasAnnotation

hasAnnotation returns true when the object has the given annotation key with a non-empty value.

{{ hasAnnotation .deployment "example.com/owner" }}  → true

hasCondition

hasCondition returns true if status.conditions contains a condition of the given type with status: "True".

{{ hasCondition .deployment "Available" }}  → true

hasLabel

hasLabel returns true when the object has the given label key with a non-empty value.

{{ hasLabel .deployment "app" }}  → true

hasStatus

hasStatus returns true when the given status field exists and is non-empty. Works for both scalar and structured (map, slice) fields.

{{ hasStatus .service "loadBalancer" }}  → true

isSynced

isSynced returns true when metadata.generation == status.observedGeneration, meaning the controller has fully processed the current spec. Returns true for resources without generation tracking (both 0).

{{ isSynced .deployment }}  → true

isTerminating

isTerminating returns true when metadata.deletionTimestamp is set — the object exists but is being deleted.

{{ isTerminating .deployment }}  → false

labelMatches

labelMatches returns true when the object’s labels contain every key/value pair given as arguments. Extra labels on the object are ignored. Useful for checking if a resource would be selected by a label selector.

{{ labelMatches .deployment "app" "web" "tier" "frontend" }}  → true

labels

labels returns the metadata.labels map. Returns an empty map if absent.

{{ mapGet (labels .deployment) "tier" }}  → "frontend"

meta

meta returns the metadata map of a Kubernetes object. Returns an empty map if metadata is absent — never nil.

{{ (meta .deployment).name }}  → "web"

name

name returns metadata.name or an empty string.

{{ name .deployment }}  → "web"

namespace

namespace returns metadata.namespace or an empty string.

{{ namespace .deployment }}  → "payments"

observedGeneration

observedGeneration returns status.observedGeneration as int64. This is the generation the controller last acted on.

{{ observedGeneration .deployment }}  → 3

ownerKind

ownerKind returns the kind of the first ownerReference.

{{ ownerKind .replicaset }}  → "Deployment"

ownerName

ownerName returns the name of the first ownerReference.

{{ ownerName .replicaset }}  → "web"

phase

phase returns status.phase as a string. Returns "" when absent.

{{ phase .pod }}  → "Running"

resourceCPU

resourceCPU returns spec.resources.requests.cpu from any object. Returns "" when spec, resources, requests, or cpu is absent — no nil pointer panic at any level.

{{ resourceCPU . }}  → "250m"
{{ resourceCPU .pod | default "100m" }}  → "100m"

resourceExists

resourceExists reports whether obj is a Kubernetes object: a map with a metadata.name. A child that was never created, a nil, or an empty map is not.

{{ resourceExists .deployment }}  → true
{{ resourceExists .missing }}     → false

resourceMemory

resourceMemory returns spec.resources.requests.memory from any object. Returns "" when any level is absent.

{{ resourceMemory . }}  → "256Mi"

spec

spec returns the spec map of a Kubernetes object. Returns an empty map if absent.

{{ (spec .cronjob).schedule }}  → "0 * * * *"

status

status returns the status map of a Kubernetes object. Returns an empty map if absent.

{{ (status .deployment).readyReplicas }}  → 3