Skip to content

Commit 1256310

Browse files
doc: improve manager info
1 parent 03f70fb commit 1256310

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ package main
2727

2828
import (
2929
"flag"
30+
"fmt"
3031
"os"
32+
"sigs.k8s.io/controller-runtime/pkg/cache"
3133

3234
"k8s.io/apimachinery/pkg/runtime"
3335
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
@@ -72,6 +74,7 @@ pod termination.
7274
While we don't have anything to run just yet, remember where that
7375
`+kubebuilder:scaffold:builder` comment is -- things'll get interesting there
7476
soon.
77+
7578
*/
7679

7780
func main() {
@@ -89,6 +92,38 @@ func main() {
8992
os.Exit(1)
9093
}
9194

95+
96+
/*
97+
Note that the Manager can restrict the namespace that all controllers will watch for resources by:
98+
*/
99+
100+
mgr, err = ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
101+
Scheme: scheme,
102+
Namespace: namespace,
103+
MetricsBindAddress: metricsAddr,
104+
})
105+
106+
/*
107+
The above example will change the scope of your project to a single Namespace. In this scenario,
108+
it is also suggested to restrict the provided authorization to this namespace by replacing the default
109+
ClusterRole and ClusterRoleBinding to Role and RoleBinding respectively
110+
For further information see the kubernetes documentation about Using [RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).
111+
112+
Also, it is possible to use the MultiNamespacedCacheBuilder to watch a specific set of namespaces:
113+
*/
114+
115+
var namespaces []string // List of Namespaces
116+
117+
mgr, err = ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
118+
Scheme: scheme,
119+
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
120+
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
121+
})
122+
123+
/*
124+
For further information see [MultiNamespacedCacheBuilder](https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder)
125+
*/
126+
92127
// +kubebuilder:scaffold:builder
93128

94129
setupLog.Info("starting manager")

0 commit comments

Comments
 (0)