Bird
0
0

Given this Operator controller snippet watching a custom resource, what will happen when a new resource instance is created?

medium📝 Command Output Q13 of 15
Kubernetes - Operators and Custom Resources
Given this Operator controller snippet watching a custom resource, what will happen when a new resource instance is created?
func (r *MyOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
    var app MyApp
    if err := r.Get(ctx, req.NamespacedName, &app); err != nil {
        return ctrl.Result{}, client.IgnoreNotFound(err)
    }
    // Logic to create or update deployment based on app spec
    return ctrl.Result{}, nil
}
AThe Operator will crash due to missing deployment code
BThe Operator will delete the custom resource immediately
CThe Operator will ignore the new resource and do nothing
DThe Operator will create or update a deployment matching the custom resource spec
Step-by-Step Solution
Solution:
  1. Step 1: Analyze Reconcile function behavior

    The function fetches the custom resource and applies logic to create or update a deployment accordingly.
  2. Step 2: Understand Operator reaction to resource creation

    When a new resource instance is created, the Operator reconciles state by creating/updating deployments to match spec.
  3. Final Answer:

    The Operator will create or update a deployment matching the custom resource spec -> Option D
  4. Quick Check:

    Reconcile creates/updates deployment = A [OK]
Quick Trick: Reconcile syncs resources to desired state [OK]
Common Mistakes:
  • Thinking Operator deletes resource on creation
  • Assuming Operator ignores new resources
  • Believing missing code causes crash here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes