From 68b8532e1493156e90c52c238193789f5120766c Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Tue, 28 May 2024 13:28:03 +0200 Subject: [PATCH] fix finalizer removal (#31) * fix finalizer removal * Remove finalizer on cm and secrets --- CHANGELOG.md | 8 ++++-- pkg/monitoring/prometheusagent/config.go | 4 --- pkg/monitoring/prometheusagent/secret.go | 5 ---- pkg/monitoring/prometheusagent/service.go | 30 +++++------------------ 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b91698..6dac0ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Do nothing if mimir is disabled to avoid deleting prometheus-meta-operator managed resources. + ### Fixed - Fix mimir heartbeat priority. -### Changed +### Removed -- Do nothing if mimir is disabled to avoid deleting prometheus-meta-operator managed resources. +- Finalizer on operator managed resources (configmap and secrets) as no other operator is touching them. ## [0.0.3] - 2024-05-24 diff --git a/pkg/monitoring/prometheusagent/config.go b/pkg/monitoring/prometheusagent/config.go index 0ce7100a..acae6e80 100644 --- a/pkg/monitoring/prometheusagent/config.go +++ b/pkg/monitoring/prometheusagent/config.go @@ -13,7 +13,6 @@ import ( "sigs.k8s.io/yaml" "github.com/giantswarm/observability-operator/pkg/common" - "github.com/giantswarm/observability-operator/pkg/monitoring" "github.com/giantswarm/observability-operator/pkg/monitoring/mimir/querier" "github.com/giantswarm/observability-operator/pkg/monitoring/prometheusagent/shards" ) @@ -74,9 +73,6 @@ func (pas PrometheusAgentService) buildRemoteWriteConfig(ctx context.Context, ObjectMeta: metav1.ObjectMeta{ Name: getPrometheusAgentRemoteWriteConfigName(cluster), Namespace: cluster.Namespace, - Finalizers: []string{ - monitoring.MonitoringFinalizer, - }, }, Data: map[string]string{ "values": string(config), diff --git a/pkg/monitoring/prometheusagent/secret.go b/pkg/monitoring/prometheusagent/secret.go index 3ee949b9..98ba1548 100644 --- a/pkg/monitoring/prometheusagent/secret.go +++ b/pkg/monitoring/prometheusagent/secret.go @@ -9,8 +9,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/yaml" - - "github.com/giantswarm/observability-operator/pkg/monitoring" ) func getPrometheusAgentRemoteWriteSecretName(cluster *clusterv1.Cluster) string { @@ -57,9 +55,6 @@ func (pas PrometheusAgentService) buildRemoteWriteSecret( ObjectMeta: metav1.ObjectMeta{ Name: getPrometheusAgentRemoteWriteSecretName(cluster), Namespace: cluster.Namespace, - Finalizers: []string{ - monitoring.MonitoringFinalizer, - }, }, Data: map[string][]byte{ "values": marshalledValues, diff --git a/pkg/monitoring/prometheusagent/service.go b/pkg/monitoring/prometheusagent/service.go index 4eb5b9a4..b0af1d3a 100644 --- a/pkg/monitoring/prometheusagent/service.go +++ b/pkg/monitoring/prometheusagent/service.go @@ -10,13 +10,11 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" "github.com/giantswarm/observability-operator/pkg/common" "github.com/giantswarm/observability-operator/pkg/common/organization" "github.com/giantswarm/observability-operator/pkg/common/password" - "github.com/giantswarm/observability-operator/pkg/monitoring" ) type PrometheusAgentService struct { @@ -178,9 +176,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 @@ -188,15 +186,7 @@ func (pas PrometheusAgentService) deleteConfigMap(ctx context.Context, cluster * return errors.WithStack(err) } - // Delete the finalizer - desired := current.DeepCopy() - controllerutil.RemoveFinalizer(desired, monitoring.MonitoringFinalizer) - err = pas.Client.Patch(ctx, desired, client.MergeFrom(current)) - 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 +198,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 @@ -218,15 +208,7 @@ func (pas PrometheusAgentService) deleteSecret(ctx context.Context, cluster *clu return errors.WithStack(err) } - // Delete the finalizer - desired := current.DeepCopy() - controllerutil.RemoveFinalizer(desired, monitoring.MonitoringFinalizer) - err = pas.Client.Patch(ctx, current, client.MergeFrom(desired)) - 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) }