From 9e967922c66e61d4d78640e909ec90236910280d Mon Sep 17 00:00:00 2001 From: QuentinBisson Date: Mon, 27 May 2024 14:17:52 +0200 Subject: [PATCH] fix finalizer removal --- pkg/monitoring/prometheusagent/service.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/monitoring/prometheusagent/service.go b/pkg/monitoring/prometheusagent/service.go index 4eb5b9a4..109ffab5 100644 --- a/pkg/monitoring/prometheusagent/service.go +++ b/pkg/monitoring/prometheusagent/service.go @@ -178,9 +178,9 @@ func (pas PrometheusAgentService) deleteConfigMap(ctx context.Context, cluster * Name: getPrometheusAgentRemoteWriteConfigName(cluster), Namespace: cluster.GetNamespace(), } - current := &corev1.ConfigMap{} + configMap := &corev1.ConfigMap{} // Get the current configmap if it exists. - err := pas.Client.Get(ctx, objectKey, current) + err := pas.Client.Get(ctx, objectKey, configMap) if apierrors.IsNotFound(err) { // Ignore cases where the configmap is not found (if it was manually deleted, for instance). return nil @@ -189,14 +189,13 @@ func (pas PrometheusAgentService) deleteConfigMap(ctx context.Context, cluster * } // Delete the finalizer - desired := current.DeepCopy() - controllerutil.RemoveFinalizer(desired, monitoring.MonitoringFinalizer) - err = pas.Client.Patch(ctx, desired, client.MergeFrom(current)) + controllerutil.RemoveFinalizer(configMap, monitoring.MonitoringFinalizer) + err = pas.Client.Update(ctx, configMap) if err != nil { return errors.WithStack(err) } - err = pas.Client.Delete(ctx, desired) + err = pas.Client.Delete(ctx, configMap) if err != nil { return errors.WithStack(err) } @@ -208,9 +207,9 @@ func (pas PrometheusAgentService) deleteSecret(ctx context.Context, cluster *clu Name: getPrometheusAgentRemoteWriteSecretName(cluster), Namespace: cluster.GetNamespace(), } - current := &corev1.Secret{} + secret := &corev1.Secret{} // Get the current secret if it exists. - err := pas.Client.Get(ctx, objectKey, current) + err := pas.Client.Get(ctx, objectKey, secret) if apierrors.IsNotFound(err) { // Ignore cases where the secret is not found (if it was manually deleted, for instance). return nil @@ -219,14 +218,13 @@ func (pas PrometheusAgentService) deleteSecret(ctx context.Context, cluster *clu } // Delete the finalizer - desired := current.DeepCopy() - controllerutil.RemoveFinalizer(desired, monitoring.MonitoringFinalizer) - err = pas.Client.Patch(ctx, current, client.MergeFrom(desired)) + controllerutil.RemoveFinalizer(secret, monitoring.MonitoringFinalizer) + err = pas.Client.Update(ctx, secret) if err != nil { return errors.WithStack(err) } - err = pas.Client.Delete(ctx, desired) + err = pas.Client.Delete(ctx, secret) if err != nil { return errors.WithStack(err) }