From 13185fcbf9f079a0a3da561ec6207758499febc0 Mon Sep 17 00:00:00 2001 From: Marta Mucek Date: Mon, 30 Jan 2023 15:59:12 +0100 Subject: [PATCH] Add heartbeat controller (#111) * Added heartbeat controller --- .../templates/rbac.yaml | 18 +++++++++++++ .../gardener-extension-cri-resmgr/values.yaml | 3 +++ cmd/gardener-extension-cri-resmgr/app/app.go | 21 +++++++++------ pkg/options/options.go | 26 +++++++++++++++++++ 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/charts/gardener-extension-cri-resmgr/templates/rbac.yaml b/charts/gardener-extension-cri-resmgr/templates/rbac.yaml index f45a853c..dccc3bdc 100644 --- a/charts/gardener-extension-cri-resmgr/templates/rbac.yaml +++ b/charts/gardener-extension-cri-resmgr/templates/rbac.yaml @@ -81,6 +81,24 @@ rules: - watch - patch - update +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - create + - list + - watch +- apiGroups: + - coordination.k8s.io + resources: + - leases + resourceNames: + - gardener-extension-heartbeat + verbs: + - get + - update + - patch - apiGroups: - "" resources: diff --git a/charts/gardener-extension-cri-resmgr/values.yaml b/charts/gardener-extension-cri-resmgr/values.yaml index bf15b3f9..55826882 100644 --- a/charts/gardener-extension-cri-resmgr/values.yaml +++ b/charts/gardener-extension-cri-resmgr/values.yaml @@ -14,6 +14,9 @@ replicaCount: 1 +heartbeat: + renewIntervalSeconds: 30 + ### This is default value for extension image to be tested with kind-based provided local with Gardener above 1.55.0 ### If you want to overwrite it, please provide values to ControllerDeployment providerConfig.values. image: diff --git a/cmd/gardener-extension-cri-resmgr/app/app.go b/cmd/gardener-extension-cri-resmgr/app/app.go index 0b9d3e05..3e462d32 100644 --- a/cmd/gardener-extension-cri-resmgr/app/app.go +++ b/cmd/gardener-extension-cri-resmgr/app/app.go @@ -26,6 +26,7 @@ import ( // Gardener extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller" + "github.com/gardener/gardener/extensions/pkg/controller/heartbeat" resourcemanagerv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1" // Other @@ -47,12 +48,7 @@ func NewExtensionControllerCommand(ctx context.Context) *cobra.Command { return fmt.Errorf("error completing options: %s", err) } - mgrOpts := manager.Options{ - LeaderElection: false, - MetricsBindAddress: "0", - } - - mgr, err := manager.New(options.RestOptions.Completed().Config, mgrOpts) + mgr, err := manager.New(options.RestOptions.Completed().Config, options.MgrOpts.Completed().Options()) if err != nil { return fmt.Errorf("could not instantiate controller-manager: %s", err) } @@ -63,11 +59,16 @@ func NewExtensionControllerCommand(ctx context.Context) *cobra.Command { if err := resourcemanagerv1alpha1.AddToScheme(scheme); err != nil { return err } - + if err := options.OptionAggregator.Complete(); err != nil { + return err + } + if err := options.HeartbeatOpts.Validate(); err != nil { + return err + } + options.HeartbeatOpts.Completed().Apply(&heartbeat.DefaultAddOptions) // mgrOpts.ClientDisableCacheFor = []client.Object{ // &corev1.ConfigMap{}, // applied for ManagedResources // } - // Enable healthcheck. // "Registration" adds additional controller that watches over Extension/Cluster. // TODO: ENABLE before merging!!! @@ -75,6 +76,10 @@ func NewExtensionControllerCommand(ctx context.Context) *cobra.Command { return err } + if err := heartbeat.AddToManager(mgr); err != nil { + return err + } + ignoreOperationAnnotation := options.ReconcileOptions.Completed().IgnoreOperationAnnotation // if true: // predicates: only observe "generation change" predicate (oldObject.generation != newObject.generation) diff --git a/pkg/options/options.go b/pkg/options/options.go index 3e0e6b27..5ff7bc6a 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -15,13 +15,21 @@ package options import ( + "os" + controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd" + heartbeatcmd "github.com/gardener/gardener/extensions/pkg/controller/heartbeat/cmd" + "github.com/gardener/gardener/pkg/logger" + "github.com/intel/gardener-extension-cri-resmgr/pkg/consts" ) type Options struct { RestOptions *controllercmd.RESTOptions // kubeconfig / MasterURL ControllerOptions *controllercmd.ControllerOptions // MaxConcurrentReconciles ReconcileOptions *controllercmd.ReconcilerOptions // IgnoreOperationAnnotation + MgrOpts *controllercmd.ManagerOptions + HealthCheckOpts *controllercmd.ControllerOptions + HeartbeatOpts *heartbeatcmd.Options OptionAggregator controllercmd.OptionAggregator } @@ -33,12 +41,30 @@ func NewOptions() *Options { MaxConcurrentReconciles: 1, }, ReconcileOptions: &controllercmd.ReconcilerOptions{}, + MgrOpts: &controllercmd.ManagerOptions{ + LeaderElection: false, + MetricsBindAddress: "0", + LogLevel: logger.InfoLevel, + LogFormat: logger.FormatText, + }, + HealthCheckOpts: &controllercmd.ControllerOptions{ + MaxConcurrentReconciles: 5, + }, + HeartbeatOpts: &heartbeatcmd.Options{ + ExtensionName: consts.ExtensionName, + RenewIntervalSeconds: 30, + Namespace: os.Getenv("EXTENSION_CONFIGMAP_NAMESPACE"), + }, } options.OptionAggregator = controllercmd.NewOptionAggregator( options.RestOptions, options.ControllerOptions, options.ReconcileOptions, + options.MgrOpts, + controllercmd.PrefixOption("healthcheck-", options.HealthCheckOpts), + options.HeartbeatOpts, ) + return options }