Skip to content

Commit bb55494

Browse files
decouple webhooks from APIs dir
1 parent 6dd2130 commit bb55494

File tree

103 files changed

+1015
-7251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1015
-7251
lines changed

docs/book/src/cronjob-tutorial/testdata/project/api/v1/groupversion_info.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
// +kubebuilder:docs-gen:collapse=Apache License
17-
18-
/*
19-
First, we have some *package-level* markers that denote that there are
20-
Kubernetes objects in this package, and that this package represents the group
21-
`batch.tutorial.kubebuilder.io`. The `object` generator makes use of the
22-
former, while the latter is used by the CRD generator to generate the right
23-
metadata for the CRDs it creates from this package.
24-
*/
2516

2617
// Package v1 contains API Schema definitions for the batch v1 API group.
2718
// +kubebuilder:object:generate=true
@@ -33,13 +24,6 @@ import (
3324
"sigs.k8s.io/controller-runtime/pkg/scheme"
3425
)
3526

36-
/*
37-
Then, we have the commonly useful variables that help us set up our Scheme.
38-
Since we need to use all the types in this package in our controller, it's
39-
helpful (and the convention) to have a convenient method to add all the types to
40-
some other `Scheme`. SchemeBuilder makes this easy for us.
41-
*/
42-
4327
var (
4428
// GroupVersion is group version used to register these objects.
4529
GroupVersion = schema.GroupVersion{Group: "batch.tutorial.kubebuilder.io", Version: "v1"}

docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
// +kubebuilder:docs-gen:collapse=Apache License
1716

1817
package main
1918

@@ -41,17 +40,6 @@ import (
4140
// +kubebuilder:scaffold:imports
4241
)
4342

44-
// +kubebuilder:docs-gen:collapse=Imports
45-
46-
/*
47-
The first difference to notice is that kubebuilder has added the new API
48-
group's package (`batchv1`) to our scheme. This means that we can use those
49-
objects in our controller.
50-
51-
If we would be using any other CRD we would have to add their scheme the same way.
52-
Builtin types such as Job have their scheme added by `clientgoscheme`.
53-
*/
54-
5543
var (
5644
scheme = runtime.NewScheme()
5745
setupLog = ctrl.Log.WithName("setup")
@@ -64,14 +52,7 @@ func init() {
6452
// +kubebuilder:scaffold:scheme
6553
}
6654

67-
/*
68-
The other thing that's changed is that kubebuilder has added a block calling our
69-
CronJob controller's `SetupWithManager` method.
70-
*/
71-
7255
func main() {
73-
/*
74-
*/
7556
var metricsAddr string
7657
var enableLeaderElection bool
7758
var probeAddr string
@@ -163,27 +144,16 @@ func main() {
163144
os.Exit(1)
164145
}
165146

166-
// +kubebuilder:docs-gen:collapse=old stuff
167-
168147
if err = (&controller.CronJobReconciler{
169148
Client: mgr.GetClient(),
170149
Scheme: mgr.GetScheme(),
171150
}).SetupWithManager(mgr); err != nil {
172151
setupLog.Error(err, "unable to create controller", "controller", "CronJob")
173152
os.Exit(1)
174153
}
175-
176-
/*
177-
We'll also set up webhooks for our type, which we'll talk about next.
178-
We just need to add them to the manager. Since we might want to run
179-
the webhooks separately, or not run them when testing our controller
180-
locally, we'll put them behind an environment variable.
181-
182-
We'll just make sure to set `ENABLE_WEBHOOKS=false` when we run locally.
183-
*/
184154
// nolint:goconst
185155
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
186-
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
156+
if err = webbooksv1.SetupCronJobWebhookWithManager(mgr); err != nil {
187157
setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
188158
os.Exit(1)
189159
}
@@ -204,5 +174,4 @@ func main() {
204174
setupLog.Error(err, "problem running manager")
205175
os.Exit(1)
206176
}
207-
// +kubebuilder:docs-gen:collapse=old stuff
208177
}

docs/book/src/cronjob-tutorial/testdata/project/config/crd/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ patches:
1313

1414
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
1515
# patches here are for enabling the CA injection for each CRD
16-
- path: patches/cainjection_in_cronjobs.yaml
16+
#- path: patches/cainjection_in_cronjobs.yaml
1717
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
1818

1919
# [WEBHOOK] To enable webhook, uncomment the following section

docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ resources:
2222
# crd/kustomization.yaml
2323
- ../webhook
2424
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
25-
- ../certmanager
25+
#- ../certmanager
2626
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
27-
- ../prometheus
27+
#- ../prometheus
2828
# [METRICS] Expose the controller manager metrics service.
2929
- metrics_service.yaml
3030
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
@@ -48,104 +48,104 @@ patches:
4848
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
4949
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
5050
# 'CERTMANAGER' needs to be enabled to use ca injection
51-
- path: webhookcainjection_patch.yaml
51+
#- path: webhookcainjection_patch.yaml
5252

5353
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
5454
# Uncomment the following replacements to add the cert-manager CA injection annotations
55-
replacements:
56-
- source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
57-
kind: Certificate
58-
group: cert-manager.io
59-
version: v1
60-
name: serving-cert # this name should match the one in certificate.yaml
61-
fieldPath: .metadata.namespace # namespace of the certificate CR
62-
targets:
63-
- select:
64-
kind: ValidatingWebhookConfiguration
65-
fieldPaths:
66-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
67-
options:
68-
delimiter: '/'
69-
index: 0
70-
create: true
71-
- select:
72-
kind: MutatingWebhookConfiguration
73-
fieldPaths:
74-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
75-
options:
76-
delimiter: '/'
77-
index: 0
78-
create: true
79-
- select:
80-
kind: CustomResourceDefinition
81-
fieldPaths:
82-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
83-
options:
84-
delimiter: '/'
85-
index: 0
86-
create: true
87-
- source:
88-
kind: Certificate
89-
group: cert-manager.io
90-
version: v1
91-
name: serving-cert # this name should match the one in certificate.yaml
92-
fieldPath: .metadata.name
93-
targets:
94-
- select:
95-
kind: ValidatingWebhookConfiguration
96-
fieldPaths:
97-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
98-
options:
99-
delimiter: '/'
100-
index: 1
101-
create: true
102-
- select:
103-
kind: MutatingWebhookConfiguration
104-
fieldPaths:
105-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
106-
options:
107-
delimiter: '/'
108-
index: 1
109-
create: true
110-
- select:
111-
kind: CustomResourceDefinition
112-
fieldPaths:
113-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
114-
options:
115-
delimiter: '/'
116-
index: 1
117-
create: true
118-
- source: # Add cert-manager annotation to the webhook Service
119-
kind: Service
120-
version: v1
121-
name: webhook-service
122-
fieldPath: .metadata.name # namespace of the service
123-
targets:
124-
- select:
125-
kind: Certificate
126-
group: cert-manager.io
127-
version: v1
128-
fieldPaths:
129-
- .spec.dnsNames.0
130-
- .spec.dnsNames.1
131-
options:
132-
delimiter: '.'
133-
index: 0
134-
create: true
135-
- source:
136-
kind: Service
137-
version: v1
138-
name: webhook-service
139-
fieldPath: .metadata.namespace # namespace of the service
140-
targets:
141-
- select:
142-
kind: Certificate
143-
group: cert-manager.io
144-
version: v1
145-
fieldPaths:
146-
- .spec.dnsNames.0
147-
- .spec.dnsNames.1
148-
options:
149-
delimiter: '.'
150-
index: 1
151-
create: true
55+
#replacements:
56+
# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
57+
# kind: Certificate
58+
# group: cert-manager.io
59+
# version: v1
60+
# name: serving-cert # this name should match the one in certificate.yaml
61+
# fieldPath: .metadata.namespace # namespace of the certificate CR
62+
# targets:
63+
# - select:
64+
# kind: ValidatingWebhookConfiguration
65+
# fieldPaths:
66+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
67+
# options:
68+
# delimiter: '/'
69+
# index: 0
70+
# create: true
71+
# - select:
72+
# kind: MutatingWebhookConfiguration
73+
# fieldPaths:
74+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
75+
# options:
76+
# delimiter: '/'
77+
# index: 0
78+
# create: true
79+
# - select:
80+
# kind: CustomResourceDefinition
81+
# fieldPaths:
82+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
83+
# options:
84+
# delimiter: '/'
85+
# index: 0
86+
# create: true
87+
# - source:
88+
# kind: Certificate
89+
# group: cert-manager.io
90+
# version: v1
91+
# name: serving-cert # this name should match the one in certificate.yaml
92+
# fieldPath: .metadata.name
93+
# targets:
94+
# - select:
95+
# kind: ValidatingWebhookConfiguration
96+
# fieldPaths:
97+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
98+
# options:
99+
# delimiter: '/'
100+
# index: 1
101+
# create: true
102+
# - select:
103+
# kind: MutatingWebhookConfiguration
104+
# fieldPaths:
105+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
106+
# options:
107+
# delimiter: '/'
108+
# index: 1
109+
# create: true
110+
# - select:
111+
# kind: CustomResourceDefinition
112+
# fieldPaths:
113+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
114+
# options:
115+
# delimiter: '/'
116+
# index: 1
117+
# create: true
118+
# - source: # Add cert-manager annotation to the webhook Service
119+
# kind: Service
120+
# version: v1
121+
# name: webhook-service
122+
# fieldPath: .metadata.name # namespace of the service
123+
# targets:
124+
# - select:
125+
# kind: Certificate
126+
# group: cert-manager.io
127+
# version: v1
128+
# fieldPaths:
129+
# - .spec.dnsNames.0
130+
# - .spec.dnsNames.1
131+
# options:
132+
# delimiter: '.'
133+
# index: 0
134+
# create: true
135+
# - source:
136+
# kind: Service
137+
# version: v1
138+
# name: webhook-service
139+
# fieldPath: .metadata.namespace # namespace of the service
140+
# targets:
141+
# - select:
142+
# kind: Certificate
143+
# group: cert-manager.io
144+
# version: v1
145+
# fieldPaths:
146+
# - .spec.dnsNames.0
147+
# - .spec.dnsNames.1
148+
# options:
149+
# delimiter: '.'
150+
# index: 1
151+
# create: true

docs/book/src/cronjob-tutorial/testdata/project/config/rbac/role.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7-
- apiGroups:
8-
- batch
9-
resources:
10-
- jobs
11-
verbs:
12-
- create
13-
- delete
14-
- get
15-
- list
16-
- patch
17-
- update
18-
- watch
19-
- apiGroups:
20-
- batch
21-
resources:
22-
- jobs/status
23-
verbs:
24-
- get
257
- apiGroups:
268
- batch.tutorial.kubebuilder.io
279
resources:

docs/book/src/cronjob-tutorial/testdata/project/config/samples/batch_v1_cronjob.yaml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,4 @@ metadata:
66
app.kubernetes.io/managed-by: kustomize
77
name: cronjob-sample
88
spec:
9-
schedule: "*/1 * * * *"
10-
startingDeadlineSeconds: 60
11-
concurrencyPolicy: Allow # explicitly specify, but Allow is also default.
12-
jobTemplate:
13-
spec:
14-
template:
15-
spec:
16-
containers:
17-
- name: hello
18-
image: busybox
19-
args:
20-
- /bin/sh
21-
- -c
22-
- date; echo Hello from the Kubernetes cluster
23-
restartPolicy: OnFailure
24-
9+
# TODO(user): Add fields here

0 commit comments

Comments
 (0)