CodeBlanks Logo Icon CodeBlanks

Custom resource management

Learn how an Operator manages custom resources.

Managing custom resources

An operator turns the custom resource the user writes into child objects and reports the result in status. The user only interacts with the custom resource; they shouldn't touch the child objects by hand, because the operator reverts them in the next reconciliation:

$ kubectl get yedek magaza-gece -n magaza -o yaml | tail -8
status:
  conditions:
    - type: Ready
      status: "True"
      reason: CronJobOlusturuldu
  observedGeneration: 3
  sonYedek: "2026-11-03T03:00:12Z"

Conditions

The conditions list in the status gives the state in a machine-readable form. kubectl wait can wait on these conditions; that way CI pipelines wait for the custom resource to be ready:

kubectl wait --for=condition=Ready yedek/magaza-gece -n magaza --timeout=120s
yedek.ornek.com/magaza-gece condition met
kubectl get yd -A -o custom-columns=AD:.metadata.name,HAZIR:.status.conditions[0].status

Practice Update the custom resource and wait

Write three commands: apply the patch {"spec":{"saklamaGun":30}} to the magaza-gece Yedek in magaza with --type=merge; wait for the Ready condition with a 120-second timeout; print the Yedek's observedGeneration with jsonpath='{.status.observedGeneration}'.

Starter code

terminal
# buraya yaz

Sample solution

terminal
kubectl patch yedek magaza-gece -n magaza --type=merge -p '{"spec":{"saklamaGun":30}}'
kubectl wait --for=condition=Ready yedek/magaza-gece -n magaza --timeout=120s
kubectl get yedek magaza-gece -n magaza -o jsonpath='{.status.observedGeneration}'

Expected output

yedek.ornek.com/magaza-gece patched
yedek.ornek.com/magaza-gece condition met
4

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What happens if you change the schedule of the CronJob the operator created by hand?

  • The custom resource is updated
  • The operator pulls it back to the custom resource's value at the next reconciliation Correct answer
  • The change stays
  • The operator crashes

Explanation: The right way is to change the custom resource's spec.

2 Wait for the custom resource's ready condition.

Question
kubectl wait --for=condition=____ yedek/magaza-gece -n magaza
Answer
kubectl wait --for=condition=Ready yedek/magaza-gece -n magaza

Explanation: Ready is a common condition type.

3 Match.

Term Meaning
spec The user's request
status.conditions Machine-readable state
observedGeneration Processed version
kubectl wait Wait for a condition

All lessons in Expert