From cd1c978d18d75b1631c0e8f21342a3ba3722c266 Mon Sep 17 00:00:00 2001 From: Eddy Filip Date: Wed, 4 Jan 2023 14:05:33 +0200 Subject: [PATCH] Remove duplicated code for deleting k8s secret and handle an error --- controllers/deployment_controller.go | 4 +++- controllers/onepassworditem_controller.go | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/controllers/deployment_controller.go b/controllers/deployment_controller.go index 48e14fd..af7dd6f 100644 --- a/controllers/deployment_controller.go +++ b/controllers/deployment_controller.go @@ -110,7 +110,9 @@ func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) if utils.ContainsString(deployment.ObjectMeta.Finalizers, finalizer) { secretName := annotations[op.NameAnnotation] - r.cleanupKubernetesSecretForDeployment(secretName, deployment) + if err = r.cleanupKubernetesSecretForDeployment(secretName, deployment); err != nil { + return ctrl.Result{}, err + } // Remove the finalizer from the deployment so deletion of deployment can be completed if err := r.removeOnePasswordFinalizerFromDeployment(deployment); err != nil { diff --git a/controllers/onepassworditem_controller.go b/controllers/onepassworditem_controller.go index 23fbbb9..976dff3 100644 --- a/controllers/onepassworditem_controller.go +++ b/controllers/onepassworditem_controller.go @@ -143,7 +143,6 @@ func (r *OnePasswordItemReconciler) cleanupKubernetesSecret(onePasswordItem *one kubernetesSecret.ObjectMeta.Name = onePasswordItem.Name kubernetesSecret.ObjectMeta.Namespace = onePasswordItem.Namespace - r.Delete(context.Background(), kubernetesSecret) if err := r.Delete(context.Background(), kubernetesSecret); err != nil { if !errors.IsNotFound(err) { return err