From 1c992be5690fcfd8bda7fe407f24014eb4b15f78 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 24 Sep 2024 10:55:25 +0200 Subject: [PATCH] inject schema into actuator config --- .../app/options.go | 4 ++-- pkg/controller/lifecycle/actuator.go | 18 ++++++++++++++---- pkg/controller/lifecycle/add.go | 7 ++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/gardener-extension-shoot-kubecost/app/options.go b/cmd/gardener-extension-shoot-kubecost/app/options.go index bb566952..7c5a347c 100644 --- a/cmd/gardener-extension-shoot-kubecost/app/options.go +++ b/cmd/gardener-extension-shoot-kubecost/app/options.go @@ -7,8 +7,8 @@ package app import ( "os" - "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle" controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd" + "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle" ) // ExtensionName is the name of the extension. @@ -52,7 +52,7 @@ func NewOptions() *Options { }, reconcileOptions: &controllercmd.ReconcilerOptions{}, controllerSwitches: controllercmd.NewSwitchOptions( - controllercmd.Switch("shoot-kubecost_lifecycle_controller", lifecycle.AddToManager)), + controllercmd.Switch("shoot_kubecost_lifecycle_controller", lifecycle.AddToManager)), } options.optionAggregator = controllercmd.NewOptionAggregator( diff --git a/pkg/controller/lifecycle/actuator.go b/pkg/controller/lifecycle/actuator.go index 7d82b7d3..c24d9112 100644 --- a/pkg/controller/lifecycle/actuator.go +++ b/pkg/controller/lifecycle/actuator.go @@ -9,17 +9,20 @@ import ( _ "embed" "errors" + "github.com/go-logr/logr" + + "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/constants" + "github.com/gardener/gardener/extensions/pkg/controller/extension" extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1" gardenclient "github.com/gardener/gardener/pkg/client/kubernetes" "github.com/gardener/gardener/pkg/extensions" - "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/constants" - managedresources "github.com/gardener/gardener/pkg/utils/managedresources" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/types" - - "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -35,10 +38,12 @@ type actuator struct { logger logr.Logger // logger client client.Client // seed cluster clientGardenlet client.Client // garden cluster + decoder runtime.Decoder } // Reconcile the Extension resource. func (a *actuator) Reconcile(ctx context.Context, logger logr.Logger, ex *extensionsv1alpha1.Extension) error { + a.logger.Info("got resource to reconcile", "extension", *ex) // get the shoot and the project namespace extensionNamespace := ex.GetNamespace() shoot, err := extensions.GetShoot(ctx, a.client, extensionNamespace) @@ -117,3 +122,8 @@ func (a *actuator) InjectClient(client client.Client) error { a.clientGardenlet = clientInterface.Client() return nil } + +func (a *actuator) InjectScheme(scheme *runtime.Scheme) error { + a.decoder = serializer.NewCodecFactory(scheme, serializer.EnableStrict).UniversalDecoder() + return nil +} diff --git a/pkg/controller/lifecycle/add.go b/pkg/controller/lifecycle/add.go index ad5acddf..e04cc79e 100644 --- a/pkg/controller/lifecycle/add.go +++ b/pkg/controller/lifecycle/add.go @@ -9,6 +9,7 @@ import ( "time" "github.com/gardener/gardener/extensions/pkg/controller/extension" + "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/constants" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/manager" ) @@ -29,10 +30,10 @@ func AddToManager(ctx context.Context, mgr manager.Manager) error { return extension.Add(ctx, mgr, extension.AddArgs{ Actuator: NewActuator(), ControllerOptions: DefaultAddOptions.ControllerOptions, - Name: "shoot-kubecost_lifecycle_controller", - FinalizerSuffix: "shoot-kubecost", + Name: "shoot_kubecost_lifecycle_controller", + FinalizerSuffix: constants.ExtensionType, Resync: 60 * time.Minute, Predicates: extension.DefaultPredicates(ctx, mgr, DefaultAddOptions.IgnoreOperationAnnotation), - Type: "shoot-kubecost", + Type: constants.ExtensionType, }) }