@@ -95,6 +95,7 @@ func (r *SandboxReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
9595
9696 if ! sandbox .ObjectMeta .DeletionTimestamp .IsZero () {
9797 log .Info ("Sandbox is being deleted" )
98+ sandbox .Status .Phase = sandboxv1alpha1 .SandboxPhaseTerminating
9899 return ctrl.Result {}, nil
99100 }
100101
@@ -126,6 +127,7 @@ func (r *SandboxReconciler) reconcileChildResources(ctx context.Context, sandbox
126127 nameHash := NameHash (sandbox .Name )
127128
128129 var allErrors error
130+ sandbox .Status .Phase = sandboxv1alpha1 .SandboxPhasePending
129131
130132 // Reconcile PVCs
131133 err := r .reconcilePVCs (ctx , sandbox )
@@ -172,6 +174,14 @@ func (r *SandboxReconciler) computeReadyCondition(sandbox *sandboxv1alpha1.Sandb
172174 podReady := false
173175 if pod != nil {
174176 message = "Pod exists with phase: " + string (pod .Status .Phase )
177+ switch pod .Status .Phase {
178+ case corev1 .PodRunning :
179+ sandbox .Status .Phase = sandboxv1alpha1 .SandboxPhaseRunning
180+ case corev1 .PodFailed , corev1 .PodUnknown :
181+ sandbox .Status .Phase = sandboxv1alpha1 .SandboxPhaseFailed
182+ default :
183+ sandbox .Status .Phase = sandboxv1alpha1 .SandboxPhasePending
184+ }
175185 // Check if pod Ready condition is true
176186 if pod .Status .Phase == corev1 .PodRunning {
177187 message = "Pod is Running but not Ready"
@@ -318,7 +328,14 @@ func (r *SandboxReconciler) reconcilePod(ctx context.Context, sandbox *sandboxv1
318328 if pod != nil {
319329 log .Info ("Found Pod" , "Pod.Namespace" , pod .Namespace , "Pod.Name" , pod .Name )
320330 // TODO - Do we enfore (change) spec if a pod exists ?
321- // r.Patch(ctx, pod, client.Apply, client.ForceOwnership, client.FieldOwner("sandbox-controller"))
331+ patch := client .MergeFrom (pod .DeepCopy ())
332+ if err := ctrl .SetControllerReference (sandbox , pod , r .Scheme ); err != nil {
333+ return nil , fmt .Errorf ("SetControllerReference for Pod failed: %w" , err )
334+ }
335+ if err := r .Patch (ctx , pod , patch , client .FieldOwner (sandboxControllerFieldOwner )); err != nil {
336+ log .Error (err , "Failed to patch" , "Pod.Namespace" , pod .Namespace , "Pod.Name" , pod .Name )
337+ return nil , err
338+ }
322339 return pod , nil
323340 }
324341
@@ -402,6 +419,7 @@ func (r *SandboxReconciler) reconcilePVCs(ctx context.Context, sandbox *sandboxv
402419
403420func (r * SandboxReconciler ) handleSandboxExpiry (ctx context.Context , sandbox * sandboxv1alpha1.Sandbox ) error {
404421 var allErrors error
422+ sandbox .Status .Phase = sandboxv1alpha1 .SandboxPhaseTerminating
405423 pod := & corev1.Pod {
406424 ObjectMeta : metav1.ObjectMeta {
407425 Name : sandbox .Name ,
0 commit comments