From 68ea6bb0d3b7ca3b11b29356d3b0cdc4c651db45 Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Tue, 11 Jun 2024 10:33:04 +0200 Subject: [PATCH] add-delete-if-mimir-enabled to generic resource (#1651) --- CHANGELOG.md | 1 + service/controller/resource/generic/create.go | 3 ++ .../controller/resource/generic/resource.go | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 107f41371..f3072f32f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Internal rework to remove the use generic resource to ease out the migration to Mimir. +- Update generic resource so we can delete resources if mimir is enabled. - Remove unused scrape_timeout inhibition. ## [4.76.0] - 2024-06-03 diff --git a/service/controller/resource/generic/create.go b/service/controller/resource/generic/create.go index d8e2b6629..0460297d1 100644 --- a/service/controller/resource/generic/create.go +++ b/service/controller/resource/generic/create.go @@ -11,6 +11,9 @@ import ( ) func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error { + if r.deleteIfMimirEnabled { + return r.EnsureDeleted(ctx, obj) + } desired, err := r.getDesiredObject(ctx, obj) if err != nil { return microerror.Mask(err) diff --git a/service/controller/resource/generic/resource.go b/service/controller/resource/generic/resource.go index d3918a51e..d2d01cb28 100644 --- a/service/controller/resource/generic/resource.go +++ b/service/controller/resource/generic/resource.go @@ -42,15 +42,18 @@ type Config struct { // the given resource and returns true if there is a difference between // them and therefore state needs to be reconciled to match the desired. HasChangedFunc func(metav1.Object, metav1.Object) bool + + DeleteIfMimirEnabled bool } type Resource struct { - clientFunc func(string) Interface - logger micrologger.Logger - name string - getObjectMeta func(context.Context, interface{}) (metav1.ObjectMeta, error) - getDesiredObject func(context.Context, interface{}) (metav1.Object, error) - hasChangedFunc func(metav1.Object, metav1.Object) bool + clientFunc func(string) Interface + logger micrologger.Logger + name string + getObjectMeta func(context.Context, interface{}) (metav1.ObjectMeta, error) + getDesiredObject func(context.Context, interface{}) (metav1.Object, error) + hasChangedFunc func(metav1.Object, metav1.Object) bool + deleteIfMimirEnabled bool } func New(config Config) (*Resource, error) { @@ -74,12 +77,13 @@ func New(config Config) (*Resource, error) { } r := &Resource{ - clientFunc: config.ClientFunc, - logger: config.Logger, - name: config.Name, - getObjectMeta: config.GetObjectMeta, - getDesiredObject: config.GetDesiredObject, - hasChangedFunc: config.HasChangedFunc, + clientFunc: config.ClientFunc, + logger: config.Logger, + name: config.Name, + getObjectMeta: config.GetObjectMeta, + getDesiredObject: config.GetDesiredObject, + hasChangedFunc: config.HasChangedFunc, + deleteIfMimirEnabled: config.DeleteIfMimirEnabled, } return r, nil