Skip to content

Commit

Permalink
[manager] Update manager initialisation for CR update
Browse files Browse the repository at this point in the history
This change updates the manager intialisation to comply with the new
controller-runtime schema.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Feb 14, 2024
1 parent e2e053a commit fc17c6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
31 changes: 13 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/webhook"

metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
Expand Down Expand Up @@ -91,23 +94,18 @@ func main() {
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "c3c8b535.openstack.org",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "c8c223a1.openstack.org",
WebhookServer: webhook.NewServer(
webhook.Options{
Port: 9443,
TLSOpts: []func(config *tls.Config){disableHTTP2},
}),
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -172,9 +170,6 @@ func main() {
checker := healthz.Ping
// Setup webhooks if requested
if strings.ToLower(os.Getenv("ENABLE_WEBHOOKS")) != "false" {
// overriding the default values
srv := mgr.GetWebhookServer()
srv.TLSOpts = []func(config *tls.Config){disableHTTP2}

if err = (&heatv1beta1.Heat{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Heat")
Expand Down
21 changes: 13 additions & 8 deletions tests/functional/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/webhook"

metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

heatv1 "github.com/openstack-k8s-operators/heat-operator/api/v1beta1"
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
Expand Down Expand Up @@ -136,14 +139,16 @@ var _ = BeforeSuite(func() {
webhookInstallOptions := &testEnv.WebhookInstallOptions
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
// NOTE(gibi): disable metrics reporting in test to allow
// parallel test execution. Otherwise each instance would like to
// bind to the same port
MetricsBindAddress: "0",
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
Metrics: metricsserver.Options{
BindAddress: "0",
},
WebhookServer: webhook.NewServer(
webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
})
Expect(err).ToNot(HaveOccurred())

Expand Down

0 comments on commit fc17c6b

Please sign in to comment.