Skip to content

Commit 3e2c6d5

Browse files
committed
fix: skip pods in succeeded or failed phase
1 parent 9e70aa6 commit 3e2c6d5

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

controllers/secretproviderclasspodstatus_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ func (r *SecretProviderClassPodStatusReconciler) Reconcile(req ctrl.Request) (ct
219219
}
220220
return ctrl.Result{}, err
221221
}
222-
// pod is being terminated so don't reconcile
223-
if !pod.GetDeletionTimestamp().IsZero() {
224-
klog.InfoS("pod is being terminated, skipping reconcile", "pod", klog.KObj(pod))
222+
// skip reconcile if the pod is being terminated
223+
// or the pod is in succeeded state (for jobs that complete aren't gc yet)
224+
// or the pod is in a failed state (all containers get terminated)
225+
if !pod.GetDeletionTimestamp().IsZero() || pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed {
226+
klog.V(5).InfoS("pod is being terminated, skipping reconcile", "pod", klog.KObj(pod))
225227
return ctrl.Result{}, nil
226228
}
227229

pkg/rotation/reconciler.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
179179
errorReason = internalerrors.PodNotFound
180180
return fmt.Errorf("failed to get pod %s/%s, err: %+v", podNamespace, podName, err)
181181
}
182-
// if the pod is being terminated, then skip rotation
182+
// skip rotation if the pod is being terminated
183+
// or the pod is in succeeded state (for jobs that complete aren't gc yet)
184+
// or the pod is in a failed state (all containers get terminated).
183185
// the spcps will be gc when the pod is deleted and will not show up in the next rotation cycle
184-
if !pod.GetDeletionTimestamp().IsZero() {
185-
klog.InfoS("pod is being terminated, skipping rotation", "pod", klog.KObj(pod))
186+
if !pod.GetDeletionTimestamp().IsZero() || pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed {
187+
klog.V(5).InfoS("pod is being terminated, skipping rotation", "pod", klog.KObj(pod))
186188
return nil
187189
}
188190

pkg/rotation/reconciler_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,18 @@ func TestReconcileNoError(t *testing.T) {
607607

608608
err = testReconciler.reconcile(context.TODO(), secretProviderClassPodStatusToProcess)
609609
g.Expect(err).NotTo(HaveOccurred())
610+
611+
// test with pod being in succeeded phase
612+
podToAdd.DeletionTimestamp = nil
613+
podToAdd.Status.Phase = v1.PodSucceeded
614+
kubeClient = fake.NewSimpleClientset(podToAdd, secretToAdd)
615+
testReconciler, err = newTestReconciler(scheme, kubeClient, crdClient, ctrlClient, 60*time.Second, socketPath)
616+
g.Expect(err).NotTo(HaveOccurred())
617+
err = testReconciler.store.Run(wait.NeverStop)
618+
g.Expect(err).NotTo(HaveOccurred())
619+
620+
err = testReconciler.reconcile(context.TODO(), secretProviderClassPodStatusToProcess)
621+
g.Expect(err).NotTo(HaveOccurred())
610622
}
611623

612624
func TestPatchSecret(t *testing.T) {

0 commit comments

Comments
 (0)