Skip to content

Commit 8571238

Browse files
authored
Merge pull request #3664 from buraksekili/patch-1
📖 Addressing Deprecated Manager Options
2 parents ce24b89 + 9427257 commit 8571238

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

docs/book/src/cronjob-tutorial/testdata/emptymain.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ package main
2828

2929
import (
3030
"flag"
31-
"fmt"
3231
"os"
3332

3433
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
@@ -43,6 +42,8 @@ import (
4342
"sigs.k8s.io/controller-runtime/pkg/cache"
4443
"sigs.k8s.io/controller-runtime/pkg/healthz"
4544
"sigs.k8s.io/controller-runtime/pkg/log/zap"
45+
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
46+
"sigs.k8s.io/controller-runtime/pkg/webhook"
4647
// +kubebuilder:scaffold:imports
4748
)
4849

@@ -104,9 +105,11 @@ func main() {
104105
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
105106

106107
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
107-
Scheme: scheme,
108-
MetricsBindAddress: metricsAddr,
109-
Port: 9443,
108+
Scheme: scheme,
109+
Metrics: server.Options{
110+
BindAddress: metricsAddr,
111+
},
112+
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
110113
HealthProbeBindAddress: probeAddr,
111114
LeaderElection: enableLeaderElection,
112115
LeaderElectionID: "80807133.tutorial.kubebuilder.io",
@@ -121,10 +124,16 @@ func main() {
121124
*/
122125

123126
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
124-
Scheme: scheme,
125-
Namespace: namespace,
126-
MetricsBindAddress: metricsAddr,
127-
Port: 9443,
127+
Scheme: scheme,
128+
Cache: cache.Options{
129+
DefaultNamespaces: map[string]cache.Config{
130+
namespace: {},
131+
},
132+
},
133+
Metrics: server.Options{
134+
BindAddress: metricsAddr,
135+
},
136+
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
128137
HealthProbeBindAddress: probeAddr,
129138
LeaderElection: enableLeaderElection,
130139
LeaderElectionID: "80807133.tutorial.kubebuilder.io",
@@ -136,24 +145,33 @@ func main() {
136145
`ClusterRole` and `ClusterRoleBinding` to `Role` and `RoleBinding` respectively.
137146
For further information see the Kubernetes documentation about Using [RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).
138147
139-
Also, it is possible to use the [`MultiNamespacedCacheBuilder`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder)
140-
to watch a specific set of namespaces:
148+
Also, it is possible to use the [`DefaultNamespaces`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options)
149+
from `cache.Options{}` to cache objects in a specific set of namespaces:
141150
*/
142151

143152
var namespaces []string // List of Namespaces
153+
defaultNamespaces := make(map[string]cache.Config)
154+
155+
for _, ns := range namespaces {
156+
defaultNamespaces[ns] = cache.Config{}
157+
}
144158

145159
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
146-
Scheme: scheme,
147-
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
148-
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
149-
Port: 9443,
160+
Scheme: scheme,
161+
Cache: cache.Options{
162+
DefaultNamespaces: defaultNamespaces,
163+
},
164+
Metrics: server.Options{
165+
BindAddress: metricsAddr,
166+
},
167+
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
150168
HealthProbeBindAddress: probeAddr,
151169
LeaderElection: enableLeaderElection,
152170
LeaderElectionID: "80807133.tutorial.kubebuilder.io",
153171
})
154172

155173
/*
156-
For further information see [`MultiNamespacedCacheBuilder`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache?tab=doc#MultiNamespacedCacheBuilder)
174+
For further information see [`cache.Options{}`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options)
157175
*/
158176

159177
// +kubebuilder:scaffold:builder

0 commit comments

Comments
 (0)