Skip to content

Commit

Permalink
update status
Browse files Browse the repository at this point in the history
  • Loading branch information
mandreap committed Aug 2, 2023
1 parent 2cbbb1b commit 958239a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
6 changes: 5 additions & 1 deletion controllers/secretproviderclasspodstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const (
SecretManagedLabel = "secrets-store.csi.k8s.io/managed"
SecretUsedLabel = "secrets-store.csi.k8s.io/used"
secretCreationFailedReason = "FailedToCreateSecret"

SyncSecretForbiddenWarning = "The secret operation failed with forbidden error. If you installed the CSI driver using helm, ensure syncSecret.enabled=true is set."
)

Expand Down Expand Up @@ -232,6 +231,11 @@ func (r *SecretProviderClassPodStatusReconciler) Reconcile(ctx context.Context,
return ctrl.Result{}, err
}

if len(spcPodStatus.Status.PodName) == 0 {
klog.InfoS("waiting for status to be populated", "spcps", req.NamespacedName.String())
return ctrl.Result{RequeueAfter: 5 * time.Millisecond}, nil
}

// Obtain the full pod metadata. An object reference is needed for sending
// events and the UID is helpful for validating the SPCPS TargetPath.
pod := &corev1.Pod{}
Expand Down
27 changes: 19 additions & 8 deletions pkg/secrets-store/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func createOrUpdateSecretProviderClassPodStatus(ctx context.Context, c client.Cl
Namespace: namespace,
Labels: map[string]string{secretsstorev1.InternalNodeLabel: nodeID},
},
Status: secretsstorev1.SecretProviderClassPodStatusStatus{
PodName: podname,
TargetPath: targetPath,
Mounted: mounted,
SecretProviderClassName: spcName,
Objects: o,
},
}
var status = secretsstorev1.SecretProviderClassPodStatusStatus{
PodName: podname,
TargetPath: targetPath,
Mounted: mounted,
SecretProviderClassName: spcName,
Objects: o,
}

// Set owner reference to the pod as the mapping between secret provider class pod status and
Expand All @@ -127,6 +127,12 @@ func createOrUpdateSecretProviderClassPodStatus(ctx context.Context, c client.Cl
})

if err = c.Create(ctx, spcPodStatus); err == nil || !apierrors.IsAlreadyExists(err) {
if err != nil {
return err
}
klog.InfoS("created secret provider class pod status", "spcPodStatus", klog.ObjectRef{Name: spcPodStatus.Name, Namespace: spcPodStatus.Namespace})
spcPodStatus.Status = status
err = c.Status().Update(ctx, spcPodStatus)
return err
}
klog.InfoS("secret provider class pod status already exists, updating it", "spcps", klog.ObjectRef{Name: spcPodStatus.Name, Namespace: spcPodStatus.Namespace})
Expand All @@ -146,9 +152,14 @@ func createOrUpdateSecretProviderClassPodStatus(ctx context.Context, c client.Cl

// update the labels of the secret provider class pod status to match the node label
spcps.Labels[secretsstorev1.InternalNodeLabel] = nodeID
spcps.Status = spcPodStatus.Status
spcps.OwnerReferences = spcPodStatus.OwnerReferences

spcps.Status = status
err = c.Status().Update(ctx, spcps)
if err != nil {
return err
}

return c.Update(ctx, spcps)
}

Expand Down

0 comments on commit 958239a

Please sign in to comment.