Kubernetes Notes

3 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.
specReturn the spec map of a Kubernetes object.
statusReturn the status map of a Kubernetes object.
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\" }}"

# 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

# 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 }}"