Kubernetes Notes

4 min read

Kubernetes notes safely navigate the unstructured objects that Orkestra exposes through the template context — especially child resources available under .children.* and cross-CRD observations under .cross.*.

Reference

NoteDescription
metaReturn the metadata map of a Kubernetes object.
labelsReturn the `metadata.
annotationsReturn the `metadata.
getLabelReturn the value of a single label key from `metadata.
getLabelIntReturn a label value parsed as int64.
hasLabelReturn true when the object has the given label key with a non-empty value.
getAnnotationReturn the value of a single annotation key from `metadata.
getAnnotationIntReturn an annotation value parsed as int64.
hasAnnotationReturn true when the object has the given annotation key with a non-empty value.
labelMatchesReturn true when the object’s labels contain every key/value pair given as arguments.
specReturn the spec map of a Kubernetes object.
statusReturn the status map of a Kubernetes object.
getStatusReturn the string value of a specific key from status.
hasStatusReturn true when the given status field exists and is non-empty.
phaseReturn `status.
getNavigate a nested path through a Kubernetes object using variadic string segments.
ownerKindReturn the kind of the first ownerReference.
ownerNameReturn the name of the first ownerReference.
hasConditionReturn true if `status.
conditionReasonReturn the reason field of a named condition.
conditionMessageReturn the message field of a named condition.
resourceExistsReturn true when the object is a non-nil map[string]interface{}.
isTerminatingReturn true when `metadata.
generationReturn `metadata.
observedGenerationReturn `status.
isSyncedReturn true when `metadata.
resourceCPUReturn `spec.
resourceMemoryReturn `spec.

Examples

# meta
# value: "{{ meta .children.cronjob }}"
# Useful as an intermediate value when chaining with mapGet:
# value: "{{ mapGet (meta .children.cronjob) \"resourceVersion\" }}"

# labels
# value: "{{ mapGet (labels .children.deployment) \"app\" }}"
# {app: frontend, tier: web} → "frontend"

# annotations
# value: "{{ mapGet (annotations .children.deployment) \"orkestra.io/phase\" }}"

# getLabel
# value: "{{ getLabel .children.deployment \"app.kubernetes.io/name\" }}"
# → "my-app"

# Drive logic from a label without a spec field:
# value: '{{ getLabel . "orkestra.io/resource-profile" | default "medium" }}'

# getLabelInt
# value: "{{ getLabelInt .children.deployment \"replica-count\" }}"
# → 3

# hasLabel
# when:
#   - field: '{{ hasLabel .children.deployment "app.kubernetes.io/managed-by" }}'
#     equals: "true"

# getAnnotation
# value: '{{ getAnnotation . "autoscale/min-replicas" | default "2" }}'
# → "2"

# getAnnotationInt
# autoscale:
#   scaleDown:
#     target: '{{ getAnnotationInt . "autoscale/min-replicas" | default 2 }}'

# hasAnnotation
# when:
#   - field: '{{ hasAnnotation . "autoscale/enabled" }}'
#     equals: "true"

# labelMatches
# value: '{{ labelMatches .children.deployment "app" "frontend" "env" "prod" }}'
# → true when the deployment carries both labels

# spec
# value: "{{ mapGet (spec .children.cronjob) \"schedule\" }}"
# Equivalent to: .children.cronjob.spec.schedule

# status
# value: "{{ mapGet (status .children.deployment) \"readyReplicas\" }}"
# Equivalent to: .children.deployment.status.readyReplicas

# getStatus
# value: "{{ getStatus .children.deployment \"readyReplicas\" }}"
# → "3"

# when:
#   - field: '{{ getStatus .children.pod "phase" }}'
#     equals: "Running"

# hasStatus
# value: '{{ hasStatus .children.service "loadBalancer" }}'
# → true when loadBalancer is set in status

# when:
#   - field: '{{ hasStatus .children.deployment "readyReplicas" }}'
#     equals: "true"

# phase
# value: "{{ phase .children.pod }}"
# → "Running", "Pending", "Succeeded", "Failed", or ""

# when:
#   - field: "{{ phase .children.pod }}"
#     equals: "Running"

# get
# value: "{{ get .children.cronjob \"status\" \"lastScheduleTime\" }}"
# value: "{{ get .children.deployment \"spec\" \"template\" \"spec\" \"containers\" }}"

# ownerKind
# value: "{{ ownerKind .children.replicaset }}"
# → "Deployment"

# ownerName
# value: "{{ ownerName .children.replicaset }}"
# → "my-app"

# hasCondition
# value: "{{ hasCondition .children.deployment \"Available\" }}"
# Standard types: Available, Progressing, Degraded, Ready, Complete

# conditionReason
# value: "{{ conditionReason .children.deployment \"Available\" }}"
# → "MinimumReplicasAvailable" or ""

# conditionMessage
# value: "{{ conditionMessage .children.deployment \"Progressing\" }}"
# → "ReplicaSet has successfully progressed." or ""

# resourceExists
# value: "{{ resourceExists .children.deployment }}"

# Gate dependent resources on child existence:
# when:
#   - field: "{{ resourceExists .children.secret }}"
#     equals: "true"

# isTerminating
# Gate traffic routing away from terminating pods:
# when:
#   - field: "{{ isTerminating .children.deployment }}"
#     equals: "false"

# generation
# value: "{{ generation .children.deployment }}"
# → 3

# observedGeneration
# value: "{{ observedGeneration .children.deployment }}"
# → 3

# isSynced
# Gate dependent resources on rollout completion:
# when:
#   - field: "{{ isSynced .children.deployment }}"
#     equals: "true"
status:
  fields:
    - path: lastScheduleTime
      value: "{{ get .children.cronjob \"status\" \"lastScheduleTime\" }}"
    - path: deploymentReady
      value: "{{ hasCondition .children.deployment \"Available\" }}"
    - path: phase
      value: "{{ phase .children.pod }}"

when:
  - field: "{{ isSynced .children.deployment }}"
    equals: "true"
  - field: "{{ resourceExists .children.secret }}"
    equals: "true"

# resourceCPU
# normalize block — default resource requests without nil pointer panics
normalize:
  spec:
    resources.requests.cpu:    '{{ resourceCPU . | default "100m" }}'
    resources.requests.memory: '{{ resourceMemory . | default "128Mi" }}'

# resourceMemory
- path: memoryRequest
  value: "{{ resourceMemory .children.deployment }}"