From 8167abb502b53d80a328e01f8ae75a8e8061688c Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Wed, 25 Sep 2024 10:12:57 +0200 Subject: [PATCH] fix extension type name --- .../app/app.go | 16 ++++++++-- pkg/constants/constants.go | 2 +- pkg/controller/lifecycle/actuator.go | 31 +++++++------------ pkg/controller/lifecycle/add.go | 5 ++- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/cmd/gardener-extension-shoot-kubecost/app/app.go b/cmd/gardener-extension-shoot-kubecost/app/app.go index fbf94566..92c659e0 100644 --- a/cmd/gardener-extension-shoot-kubecost/app/app.go +++ b/cmd/gardener-extension-shoot-kubecost/app/app.go @@ -10,6 +10,7 @@ import ( extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller" "github.com/gardener/gardener/extensions/pkg/util" + "github.com/gardener/gardener/pkg/logger" "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle" "github.com/spf13/cobra" @@ -17,6 +18,7 @@ import ( componentbaseconfig "k8s.io/component-base/config" "k8s.io/component-base/version/verflag" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" ) @@ -47,6 +49,13 @@ func NewServiceControllerCommand() *cobra.Command { } func (o *Options) run(ctx context.Context) error { + + log, err := logger.NewZapLogger(logger.InfoLevel, logger.FormatJSON) + if err != nil { + return fmt.Errorf("error instantiating zap logger: %w", err) + } + logf.SetLogger(log) + // TODO: Make these flags configurable via command line parameters or component config file. util.ApplyClientConnectionConfigurationToRESTConfig(&componentbaseconfig.ClientConnectionConfiguration{ QPS: 100.0, @@ -58,9 +67,10 @@ func (o *Options) run(ctx context.Context) error { // do not enable a metrics server for the quick start mgrOpts.Metrics.BindAddress = "0" - mgrOpts.Client.Cache = &client.CacheOptions{} - mgrOpts.Client.Cache.DisableFor = []client.Object{ - &corev1.Secret{}, // applied for ManagedResources + mgrOpts.Client.Cache = &client.CacheOptions{ + DisableFor: []client.Object{ + &corev1.Secret{}, // applied for ManagedResources + }, } mgr, err := manager.New(o.restOptions.Completed().Config, mgrOpts) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 4ae14a2c..7ceeb8a7 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -2,7 +2,7 @@ package constants const ( // ExtensionType is the name of the extension type. - ExtensionType = "shoot-flux" + ExtensionType = "shoot-kubecost" // ServiceName is the name of the service. ServiceName = ExtensionType diff --git a/pkg/controller/lifecycle/actuator.go b/pkg/controller/lifecycle/actuator.go index c24d9112..d0306dc1 100644 --- a/pkg/controller/lifecycle/actuator.go +++ b/pkg/controller/lifecycle/actuator.go @@ -21,16 +21,23 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" ) // NewActuator returns an actuator responsible for Extension resources. -func NewActuator() extension.Actuator { +func NewActuator(client client.Client) extension.Actuator { + clientGardenlet := client + clientInterface, err := gardenclient.NewClientFromSecret(context.Background(), client, "garden", "gardenlet-kubeconfig") + if err == nil { + clientInterface.Start(context.Background()) + clientGardenlet = clientInterface.Client() + } return &actuator{ - logger: log.Log.WithName("FirstLogger"), + client: client, + clientGardenlet: clientGardenlet, + logger: log.Log.WithName("FirstLogger"), } } @@ -43,7 +50,6 @@ type actuator struct { // 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) @@ -51,6 +57,7 @@ func (a *actuator) Reconcile(ctx context.Context, logger logr.Logger, ex *extens return err } projectNamespace := shoot.GetNamespace() + a.logger.Info("reconciling", "extension ns", extensionNamespace, "project ns", projectNamespace) // fetch the secret holding the per-project configuration for the shoot-kubecost installation kubeCostSecret := corev1.Secret{} @@ -111,19 +118,3 @@ func getKubeCostApiKey(secretData map[string][]byte) (string, error) { func createShootResourceKubeCostInstall(apiKey string) (map[string][]byte, error) { return nil, nil } - -func (a *actuator) InjectClient(client client.Client) error { - a.client = client - clientInterface, err := gardenclient.NewClientFromSecret(context.Background(), a.client, "garden", "gardenlet-kubeconfig") - if err != nil { - return err - } - clientInterface.Start(context.Background()) - 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 e04cc79e..d1354d3b 100644 --- a/pkg/controller/lifecycle/add.go +++ b/pkg/controller/lifecycle/add.go @@ -28,12 +28,11 @@ type AddOptions struct { // AddToManager adds a shoot-kubecost Lifecycle controller to the given Controller Manager. func AddToManager(ctx context.Context, mgr manager.Manager) error { return extension.Add(ctx, mgr, extension.AddArgs{ - Actuator: NewActuator(), + Actuator: NewActuator(mgr.GetClient()), ControllerOptions: DefaultAddOptions.ControllerOptions, Name: "shoot_kubecost_lifecycle_controller", FinalizerSuffix: constants.ExtensionType, - Resync: 60 * time.Minute, - Predicates: extension.DefaultPredicates(ctx, mgr, DefaultAddOptions.IgnoreOperationAnnotation), + Resync: 1 * time.Minute, Type: constants.ExtensionType, }) }