Skip to content

Commit

Permalink
Add heartbeat controller (#111)
Browse files Browse the repository at this point in the history
* Added heartbeat controller
  • Loading branch information
mmucek95 authored Jan 30, 2023
1 parent 54a742c commit 13185fc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
18 changes: 18 additions & 0 deletions charts/gardener-extension-cri-resmgr/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions charts/gardener-extension-cri-resmgr/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 13 additions & 8 deletions cmd/gardener-extension-cri-resmgr/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -63,18 +59,27 @@ 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!!!
if err := healthcheck.RegisterHealthChecks(mgr); err != nil {
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)
Expand Down
26 changes: 26 additions & 0 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit 13185fc

Please sign in to comment.