diff --git a/docs/book/src/cronjob-tutorial/testdata/emptymain.go b/docs/book/src/cronjob-tutorial/testdata/emptymain.go index c0acd4fe63..f9ab80c7f4 100644 --- a/docs/book/src/cronjob-tutorial/testdata/emptymain.go +++ b/docs/book/src/cronjob-tutorial/testdata/emptymain.go @@ -28,7 +28,6 @@ package main import ( "flag" - "fmt" "os" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) @@ -43,6 +42,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" + "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" // +kubebuilder:scaffold:imports ) @@ -104,9 +105,11 @@ func main() { ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - MetricsBindAddress: metricsAddr, - Port: 9443, + Scheme: scheme, + Metrics: server.Options{ + BindAddress: metricsAddr, + }, + WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}), HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "80807133.tutorial.kubebuilder.io", @@ -121,10 +124,16 @@ func main() { */ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - Namespace: namespace, - MetricsBindAddress: metricsAddr, - Port: 9443, + Scheme: scheme, + Cache: cache.Options{ + DefaultNamespaces: map[string]cache.Config{ + namespace: {}, + }, + }, + Metrics: server.Options{ + BindAddress: metricsAddr, + }, + WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}), HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "80807133.tutorial.kubebuilder.io", @@ -136,24 +145,33 @@ func main() { `ClusterRole` and `ClusterRoleBinding` to `Role` and `RoleBinding` respectively. For further information see the Kubernetes documentation about Using [RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/). - Also, it is possible to use the [`MultiNamespacedCacheBuilder`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder) - to watch a specific set of namespaces: + Also, it is possible to use the [`DefaultNamespaces`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options) + from `cache.Options{}` to cache objects in a specific set of namespaces: */ var namespaces []string // List of Namespaces + defaultNamespaces := make(map[string]cache.Config) + + for _, ns := range namespaces { + defaultNamespaces[ns] = cache.Config{} + } mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - NewCache: cache.MultiNamespacedCacheBuilder(namespaces), - MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort), - Port: 9443, + Scheme: scheme, + Cache: cache.Options{ + DefaultNamespaces: defaultNamespaces, + }, + Metrics: server.Options{ + BindAddress: metricsAddr, + }, + WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}), HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "80807133.tutorial.kubebuilder.io", }) /* - For further information see [`MultiNamespacedCacheBuilder`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache?tab=doc#MultiNamespacedCacheBuilder) + For further information see [`cache.Options{}`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options) */ // +kubebuilder:scaffold:builder