Skip to content

Commit b97244d

Browse files
authored
Update emptymain.go
Update deprecated manager Options fields
1 parent ce24b89 commit b97244d

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ package main
2828

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

33+
"sigs.k8s.io/controller-runtime/pkg/webhook"
34+
3435
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3536
// to ensure that exec-entrypoint and run can make use of them.
3637
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -43,6 +44,7 @@ import (
4344
"sigs.k8s.io/controller-runtime/pkg/cache"
4445
"sigs.k8s.io/controller-runtime/pkg/healthz"
4546
"sigs.k8s.io/controller-runtime/pkg/log/zap"
47+
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
4648
// +kubebuilder:scaffold:imports
4749
)
4850

@@ -104,9 +106,11 @@ func main() {
104106
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
105107

106108
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
107-
Scheme: scheme,
108-
MetricsBindAddress: metricsAddr,
109-
Port: 9443,
109+
Scheme: scheme,
110+
Metrics: server.Options{
111+
BindAddress: metricsAddr,
112+
},
113+
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
110114
HealthProbeBindAddress: probeAddr,
111115
LeaderElection: enableLeaderElection,
112116
LeaderElectionID: "80807133.tutorial.kubebuilder.io",
@@ -121,10 +125,16 @@ func main() {
121125
*/
122126

123127
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
124-
Scheme: scheme,
125-
Namespace: namespace,
126-
MetricsBindAddress: metricsAddr,
127-
Port: 9443,
128+
Scheme: scheme,
129+
Cache: cache.Options{
130+
DefaultNamespaces: map[string]cache.Config{
131+
namespace: {},
132+
},
133+
},
134+
Metrics: server.Options{
135+
BindAddress: metricsAddr,
136+
},
137+
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
128138
HealthProbeBindAddress: probeAddr,
129139
LeaderElection: enableLeaderElection,
130140
LeaderElectionID: "80807133.tutorial.kubebuilder.io",
@@ -136,24 +146,33 @@ func main() {
136146
`ClusterRole` and `ClusterRoleBinding` to `Role` and `RoleBinding` respectively.
137147
For further information see the Kubernetes documentation about Using [RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).
138148
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:
149+
Also, it is possible to use the [`DefaultNamespaces`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options)
150+
from `cache.Options{}` to cache objects in a specific set of namespaces:
141151
*/
142152

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

145160
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,
161+
Scheme: scheme,
162+
Cache: cache.Options{
163+
DefaultNamespaces: defaultNamespaces,
164+
},
165+
Metrics: server.Options{
166+
BindAddress: metricsAddr,
167+
},
168+
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
150169
HealthProbeBindAddress: probeAddr,
151170
LeaderElection: enableLeaderElection,
152171
LeaderElectionID: "80807133.tutorial.kubebuilder.io",
153172
})
154173

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

159178
// +kubebuilder:scaffold:builder

0 commit comments

Comments
 (0)