Skip to content

Commit

Permalink
add-delete-if-mimir-enabled to generic resource (#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson authored Jun 11, 2024
1 parent f261293 commit 68ea6bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions service/controller/resource/generic/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions service/controller/resource/generic/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 68ea6bb

Please sign in to comment.