Skip to content

Commit

Permalink
fix finalizer removal (#31)
Browse files Browse the repository at this point in the history
* fix finalizer removal

* Remove finalizer on cm and secrets
  • Loading branch information
QuentinBisson authored May 28, 2024
1 parent 5446950 commit 68b8532
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 35 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions pkg/monitoring/prometheusagent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 0 additions & 5 deletions pkg/monitoring/prometheusagent/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 6 additions & 24 deletions pkg/monitoring/prometheusagent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -178,25 +176,17 @@ 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
} else if err != nil {
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)
}
Expand All @@ -208,25 +198,17 @@ 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
} else if err != nil {
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)
}
Expand Down

0 comments on commit 68b8532

Please sign in to comment.