@@ -28,22 +28,22 @@ kubebuilder create api --group <theirgroup> --version <theirversion> --kind <the
2828For example, if you're managing Certificates from Cert Manager:
2929
3030``` shell
31- kubebuilder create api --group certmanager --version v1 --kind Certificate --controller=true --resource=false --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 --external-api-domain=cert-manager.io
31+ kubebuilder create api --group cert-manager.io --version v1 --kind Certificate --controller=true --resource=false --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1
3232```
3333
34- See the RBAC markers generated for this:
34+ See the RBAC [ markers] [ markers-rbac ] generated for this:
3535
3636``` go
37- // +kubebuilder:rbac:groups=certmanager. cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete
38- // +kubebuilder:rbac:groups=certmanager. cert-manager.io,resources=certificates/status,verbs=get;update;patch
39- // +kubebuilder:rbac:groups=certmanager. cert-manager.io,resources=certificates/finalizers,verbs=update
37+ // +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete
38+ // +kubebuilder:rbac:groups=cert-manager.io,resources=certificates/status,verbs=get;update;patch
39+ // +kubebuilder:rbac:groups=cert-manager.io,resources=certificates/finalizers,verbs=update
4040```
4141
4242Also, the RBAC role:
4343
4444``` ymal
4545- apiGroups:
46- - certmanager. cert-manager.io
46+ - cert-manager.io
4747 resources:
4848 - certificates
4949 verbs:
@@ -55,7 +55,7 @@ Also, the RBAC role:
5555 - update
5656 - watch
5757- apiGroups:
58- - certmanager. cert-manager.io
58+ - cert-manager.io
5959 resources:
6060 - certificates/finalizers
6161 verbs:
@@ -70,6 +70,50 @@ Also, the RBAC role:
7070 - update
7171```
7272
73+ However, if we are scaffolding an API that has a domain defined, we need to explicitly set the domain using the ` --external-api-domain `
74+ flag in the Kubebuilder command. For example, if we want to scaffold a controller for the ServiceMonitor
75+ API provided and defined in the [ Prometheus Operator] [ prometheus-operator ] , we would scaffold it as follows:
76+
77+ ``` shell
78+ kubebuilder create api --group " monitoring" --version v1 --kind ServiceMonitor --controller=true --resource=false --make=false --external-api-path=github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1 --external-api-domain=coreos.com
79+ ```
80+
81+ In this case:
82+
83+ - The ** group** is ` "monitoring" ` .
84+ - The ** domain** is ` "coreos.com" ` , as indicated by ` --external-api-domain=coreos.com ` .
85+
86+ This structure ensures that the API group and domain are correctly applied to generate the
87+ [ markers] [ markers-rbac ] and scaffolds accordingly.
88+
89+ In this scenario, the [ markers] [ markers-rbac ] scaffolded in the controller will look like this:
90+
91+ ``` go
92+ // +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors,verbs=get;list;watch;create;update;patch;delete
93+ // +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors/status,verbs=get;update;patch
94+ // +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors/finalizers,verbs=update
95+
96+ ```
97+
98+ These [ markers] [ markers-rbac ] will generate the corresponding permissions under config/rbac/, such as:
99+
100+ ``` ymal
101+ - apiGroups:
102+ - monitoring.coreos.com
103+ resources:
104+ - servicemonitors/finalizers
105+ verbs:
106+ - update
107+ - apiGroups:
108+ - monitoring.coreos.com
109+ resources:
110+ - servicemonitors/status
111+ verbs:
112+ - get
113+ - patch
114+ - update
115+ ```
116+
73117This scaffolds a controller for the external type but skips creating new resource
74118definitions since the type is defined in an external project.
75119
@@ -118,15 +162,15 @@ For instance, to create a controller to manage Deployment the command would be l
118162create api --group apps --version v1 --kind Deployment --controller=true --resource=false
119163```
120164
121- See the RBAC markers generated for this:
165+ See the RBAC [ markers] [ markers-rbac ] generated for this:
122166
123167``` go
124168// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
125169// +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;update;patch
126170// +kubebuilder:rbac:groups=apps,resources=deployments/finalizers,verbs=update
127171```
128172
129- Also, the RBAC for the above markers:
173+ Also, the RBAC for the above [ markers] [ markers-rbac ] :
130174
131175``` yaml
132176- apiGroups :
@@ -170,3 +214,5 @@ Webhook support for Core Types is not currently automated by the tool. However,
170214</aside>
171215
172216[webhook-for-core-types] : ./webhook-for-core-types.md
217+ [prometheus-operator] : https://github.com/prometheus-operator/prometheus-operator
218+ [markers-rbac] : ./markers/rbac.md
0 commit comments