Skip to content

Commit

Permalink
fix: update metrics and webhook options to latest version
Browse files Browse the repository at this point in the history
Signed-off-by: LukasAuerbeck <[email protected]>
  • Loading branch information
LukasAuerbeck committed Sep 28, 2023
1 parent dd21ea6 commit 97b59e7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 29 deletions.
27 changes: 22 additions & 5 deletions cmd/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

var (
Expand Down Expand Up @@ -138,9 +140,13 @@ var controllerCmd = &cobra.Command{

func generateManagerConfig(heistConfig *HeistConfig) ctrl.Options {
options := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: heistConfig.Operator.MetricsBindAddress,
Port: heistConfig.Operator.WebhookPort,
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: heistConfig.Operator.MetricsBindAddress,
},
WebhookServer: webhook.NewServer(webhook.Options{
Port: heistConfig.Operator.WebhookPort,
}),
HealthProbeBindAddress: heistConfig.Operator.HealthProbeBindAddress,
LeaderElection: heistConfig.Operator.LeaderElect,
LeaderElectionID: heistConfig.Operator.LeaderElectionID,
Expand All @@ -155,18 +161,29 @@ func generateManagerConfig(heistConfig *HeistConfig) ctrl.Options {
setupLog.Info("Operator Scope: multi namespace", "namespaces", namespaces)

options.NewCache = func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.Namespaces = namespaces
opts.DefaultNamespaces = getNamespacedCacheConfig(namespaces)
return cache.New(config, opts)
}

return options
default:
setupLog.Info("Operator Scope: single namespace", "namespaces", []string{watchedNamespaces})
options.Cache.Namespaces = []string{watchedNamespaces}
options.Cache.DefaultNamespaces = getNamespacedCacheConfig([]string{watchedNamespaces})
return options
}
}

func getNamespacedCacheConfig(namespaces []string) (namespaceConfig map[string]cache.Config) {
namespaceConfig = map[string]cache.Config{}

for _, namespace := range namespaces {
// leave all cache.Config fields nil to use default settings
namespaceConfig[namespace] = cache.Config{}
}

return namespaceConfig
}

func init() {
rootCmd.AddCommand(controllerCmd)

Expand Down
18 changes: 12 additions & 6 deletions pkg/agent/agent_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -124,12 +126,16 @@ func BeforeSuiteSetup() func() {
WithVaultAPI(vaultAPI).
WithRestConfig(cfg).
WithOptions(controllerruntime.Options{
Scheme: scheme.Scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme.Scheme,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
Metrics: metricsserver.Options{
BindAddress: "0",
},
}).
Register(heistv1alpha1.Component()).
Register(controllers.Component(&controllers.Config{})).
Expand Down
18 changes: 12 additions & 6 deletions pkg/agentserver/agentserver_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -132,12 +134,16 @@ func BeforeSuiteSetup() func() {
WithVaultAPI(vaultAPI).
WithRestConfig(cfg).
WithOptions(controllerruntime.Options{
Scheme: scheme.Scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme.Scheme,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
Metrics: metricsserver.Options{
BindAddress: "0",
},
}).
Register(heistv1alpha1.Component()).
Register(controllers.Component(&controllers.Config{})).
Expand Down
18 changes: 12 additions & 6 deletions pkg/apis/heist.youniqx.com/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -136,12 +138,16 @@ var _ = BeforeSuite(func() {
WithVaultAPI(vaultAPI).
WithRestConfig(cfg).
WithOptions(ctrl.Options{
Scheme: scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
Metrics: metricsserver.Options{
BindAddress: "0",
},
}).
Register(Component()).
Complete()
Expand Down
18 changes: 12 additions & 6 deletions pkg/injector/injector_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -121,12 +123,16 @@ func BeforeSuiteSetup() func() {
WithVaultAPI(vaultAPI).
WithRestConfig(cfg).
WithOptions(controllerruntime.Options{
Scheme: scheme.Scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme.Scheme,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
Metrics: metricsserver.Options{
BindAddress: "0",
},
}).
Register(heistv1alpha1.Component()).
Register(controllers.Component(&controllers.Config{})).
Expand Down

0 comments on commit 97b59e7

Please sign in to comment.