Skip to content

Commit 8193dec

Browse files
committed
Move webhooks to a separate package
1 parent 9903654 commit 8193dec

21 files changed

+718
-603
lines changed

api/v1beta1/machinehealthcheck_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"time"
21+
2022
corev1 "k8s.io/api/core/v1"
2123
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
"k8s.io/apimachinery/pkg/util/intstr"
2325
)
2426

27+
var (
28+
// DefaultNodeStartupTimeout is the time allowed for a node to start up.
29+
// Can be made longer as part of spec if required for particular provider.
30+
// 10 minutes should allow the instance to start and the node to join the
31+
// cluster on most providers.
32+
DefaultNodeStartupTimeout = metav1.Duration{Duration: 10 * time.Minute}
33+
)
34+
2535
// ANCHOR: MachineHealthCheckSpec
2636

2737
// MachineHealthCheckSpec defines the desired state of MachineHealthCheck.

api/v1beta1/zz_generated.openapi.go

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/webhook/manifests.yaml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ webhooks:
1111
service:
1212
name: webhook-service
1313
namespace: system
14-
path: /mutate-cluster-x-k8s-io-v1beta1-machine
14+
path: /mutate-cluster-x-k8s-io-v1beta1-cluster
1515
failurePolicy: Fail
1616
matchPolicy: Equivalent
17-
name: default.machine.cluster.x-k8s.io
17+
name: default.cluster.cluster.x-k8s.io
1818
rules:
1919
- apiGroups:
2020
- cluster.x-k8s.io
@@ -24,7 +24,7 @@ webhooks:
2424
- CREATE
2525
- UPDATE
2626
resources:
27-
- machines
27+
- clusters
2828
sideEffects: None
2929
- admissionReviewVersions:
3030
- v1
@@ -33,10 +33,10 @@ webhooks:
3333
service:
3434
name: webhook-service
3535
namespace: system
36-
path: /mutate-cluster-x-k8s-io-v1beta1-machinedeployment
36+
path: /mutate-cluster-x-k8s-io-v1beta1-clusterclass
3737
failurePolicy: Fail
3838
matchPolicy: Equivalent
39-
name: default.machinedeployment.cluster.x-k8s.io
39+
name: default.clusterclass.cluster.x-k8s.io
4040
rules:
4141
- apiGroups:
4242
- cluster.x-k8s.io
@@ -46,7 +46,7 @@ webhooks:
4646
- CREATE
4747
- UPDATE
4848
resources:
49-
- machinedeployments
49+
- clusterclasses
5050
sideEffects: None
5151
- admissionReviewVersions:
5252
- v1
@@ -55,10 +55,10 @@ webhooks:
5555
service:
5656
name: webhook-service
5757
namespace: system
58-
path: /mutate-cluster-x-k8s-io-v1beta1-machinehealthcheck
58+
path: /mutate-cluster-x-k8s-io-v1beta1-machine
5959
failurePolicy: Fail
6060
matchPolicy: Equivalent
61-
name: default.machinehealthcheck.cluster.x-k8s.io
61+
name: default.machine.cluster.x-k8s.io
6262
rules:
6363
- apiGroups:
6464
- cluster.x-k8s.io
@@ -68,7 +68,7 @@ webhooks:
6868
- CREATE
6969
- UPDATE
7070
resources:
71-
- machinehealthchecks
71+
- machines
7272
sideEffects: None
7373
- admissionReviewVersions:
7474
- v1
@@ -77,10 +77,10 @@ webhooks:
7777
service:
7878
name: webhook-service
7979
namespace: system
80-
path: /mutate-cluster-x-k8s-io-v1beta1-machineset
80+
path: /mutate-cluster-x-k8s-io-v1beta1-machinedeployment
8181
failurePolicy: Fail
8282
matchPolicy: Equivalent
83-
name: default.machineset.cluster.x-k8s.io
83+
name: default.machinedeployment.cluster.x-k8s.io
8484
rules:
8585
- apiGroups:
8686
- cluster.x-k8s.io
@@ -90,7 +90,7 @@ webhooks:
9090
- CREATE
9191
- UPDATE
9292
resources:
93-
- machinesets
93+
- machinedeployments
9494
sideEffects: None
9595
- admissionReviewVersions:
9696
- v1
@@ -99,10 +99,10 @@ webhooks:
9999
service:
100100
name: webhook-service
101101
namespace: system
102-
path: /mutate-cluster-x-k8s-io-v1beta1-cluster
102+
path: /mutate-cluster-x-k8s-io-v1beta1-machinehealthcheck
103103
failurePolicy: Fail
104104
matchPolicy: Equivalent
105-
name: default.cluster.cluster.x-k8s.io
105+
name: default.machinehealthcheck.cluster.x-k8s.io
106106
rules:
107107
- apiGroups:
108108
- cluster.x-k8s.io
@@ -112,7 +112,7 @@ webhooks:
112112
- CREATE
113113
- UPDATE
114114
resources:
115-
- clusters
115+
- machinehealthchecks
116116
sideEffects: None
117117
- admissionReviewVersions:
118118
- v1
@@ -121,10 +121,10 @@ webhooks:
121121
service:
122122
name: webhook-service
123123
namespace: system
124-
path: /mutate-cluster-x-k8s-io-v1beta1-clusterclass
124+
path: /mutate-cluster-x-k8s-io-v1beta1-machineset
125125
failurePolicy: Fail
126126
matchPolicy: Equivalent
127-
name: default.clusterclass.cluster.x-k8s.io
127+
name: default.machineset.cluster.x-k8s.io
128128
rules:
129129
- apiGroups:
130130
- cluster.x-k8s.io
@@ -134,7 +134,7 @@ webhooks:
134134
- CREATE
135135
- UPDATE
136136
resources:
137-
- clusterclasses
137+
- machinesets
138138
sideEffects: None
139139
- admissionReviewVersions:
140140
- v1
@@ -215,10 +215,10 @@ webhooks:
215215
service:
216216
name: webhook-service
217217
namespace: system
218-
path: /validate-cluster-x-k8s-io-v1beta1-machine
218+
path: /validate-cluster-x-k8s-io-v1beta1-cluster
219219
failurePolicy: Fail
220220
matchPolicy: Equivalent
221-
name: validation.machine.cluster.x-k8s.io
221+
name: validation.cluster.cluster.x-k8s.io
222222
rules:
223223
- apiGroups:
224224
- cluster.x-k8s.io
@@ -227,8 +227,9 @@ webhooks:
227227
operations:
228228
- CREATE
229229
- UPDATE
230+
- DELETE
230231
resources:
231-
- machines
232+
- clusters
232233
sideEffects: None
233234
- admissionReviewVersions:
234235
- v1
@@ -237,10 +238,10 @@ webhooks:
237238
service:
238239
name: webhook-service
239240
namespace: system
240-
path: /validate-cluster-x-k8s-io-v1beta1-machinedeployment
241+
path: /validate-cluster-x-k8s-io-v1beta1-clusterclass
241242
failurePolicy: Fail
242243
matchPolicy: Equivalent
243-
name: validation.machinedeployment.cluster.x-k8s.io
244+
name: validation.clusterclass.cluster.x-k8s.io
244245
rules:
245246
- apiGroups:
246247
- cluster.x-k8s.io
@@ -249,8 +250,9 @@ webhooks:
249250
operations:
250251
- CREATE
251252
- UPDATE
253+
- DELETE
252254
resources:
253-
- machinedeployments
255+
- clusterclasses
254256
sideEffects: None
255257
- admissionReviewVersions:
256258
- v1
@@ -259,10 +261,10 @@ webhooks:
259261
service:
260262
name: webhook-service
261263
namespace: system
262-
path: /validate-cluster-x-k8s-io-v1beta1-machinehealthcheck
264+
path: /validate-cluster-x-k8s-io-v1beta1-machine
263265
failurePolicy: Fail
264266
matchPolicy: Equivalent
265-
name: validation.machinehealthcheck.cluster.x-k8s.io
267+
name: validation.machine.cluster.x-k8s.io
266268
rules:
267269
- apiGroups:
268270
- cluster.x-k8s.io
@@ -272,7 +274,7 @@ webhooks:
272274
- CREATE
273275
- UPDATE
274276
resources:
275-
- machinehealthchecks
277+
- machines
276278
sideEffects: None
277279
- admissionReviewVersions:
278280
- v1
@@ -281,10 +283,10 @@ webhooks:
281283
service:
282284
name: webhook-service
283285
namespace: system
284-
path: /validate-cluster-x-k8s-io-v1beta1-machineset
286+
path: /validate-cluster-x-k8s-io-v1beta1-machinedeployment
285287
failurePolicy: Fail
286288
matchPolicy: Equivalent
287-
name: validation.machineset.cluster.x-k8s.io
289+
name: validation.machinedeployment.cluster.x-k8s.io
288290
rules:
289291
- apiGroups:
290292
- cluster.x-k8s.io
@@ -294,7 +296,7 @@ webhooks:
294296
- CREATE
295297
- UPDATE
296298
resources:
297-
- machinesets
299+
- machinedeployments
298300
sideEffects: None
299301
- admissionReviewVersions:
300302
- v1
@@ -303,10 +305,10 @@ webhooks:
303305
service:
304306
name: webhook-service
305307
namespace: system
306-
path: /validate-cluster-x-k8s-io-v1beta1-cluster
308+
path: /validate-cluster-x-k8s-io-v1beta1-machinehealthcheck
307309
failurePolicy: Fail
308310
matchPolicy: Equivalent
309-
name: validation.cluster.cluster.x-k8s.io
311+
name: validation.machinehealthcheck.cluster.x-k8s.io
310312
rules:
311313
- apiGroups:
312314
- cluster.x-k8s.io
@@ -315,9 +317,8 @@ webhooks:
315317
operations:
316318
- CREATE
317319
- UPDATE
318-
- DELETE
319320
resources:
320-
- clusters
321+
- machinehealthchecks
321322
sideEffects: None
322323
- admissionReviewVersions:
323324
- v1
@@ -326,10 +327,10 @@ webhooks:
326327
service:
327328
name: webhook-service
328329
namespace: system
329-
path: /validate-cluster-x-k8s-io-v1beta1-clusterclass
330+
path: /validate-cluster-x-k8s-io-v1beta1-machineset
330331
failurePolicy: Fail
331332
matchPolicy: Equivalent
332-
name: validation.clusterclass.cluster.x-k8s.io
333+
name: validation.machineset.cluster.x-k8s.io
333334
rules:
334335
- apiGroups:
335336
- cluster.x-k8s.io
@@ -338,9 +339,8 @@ webhooks:
338339
operations:
339340
- CREATE
340341
- UPDATE
341-
- DELETE
342342
resources:
343-
- clusterclasses
343+
- machinesets
344344
sideEffects: None
345345
- admissionReviewVersions:
346346
- v1

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"sigs.k8s.io/cluster-api/internal/contract"
5656
"sigs.k8s.io/cluster-api/internal/test/builder"
5757
"sigs.k8s.io/cluster-api/internal/util/ssa"
58+
"sigs.k8s.io/cluster-api/internal/webhooks"
5859
"sigs.k8s.io/cluster-api/util"
5960
"sigs.k8s.io/cluster-api/util/certs"
6061
"sigs.k8s.io/cluster-api/util/collections"
@@ -2418,7 +2419,10 @@ func createMachineNodePair(name string, cluster *clusterv1.Cluster, kcp *control
24182419
},
24192420
},
24202421
}
2421-
machine.Default()
2422+
webhook := webhooks.Machine{}
2423+
if err := webhook.Default(ctx, machine); err != nil {
2424+
panic(err)
2425+
}
24222426

24232427
node := &corev1.Node{
24242428
ObjectMeta: metav1.ObjectMeta{

internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"sigs.k8s.io/cluster-api/controllers/remote"
4747
capierrors "sigs.k8s.io/cluster-api/errors"
4848
"sigs.k8s.io/cluster-api/internal/test/builder"
49+
"sigs.k8s.io/cluster-api/internal/webhooks"
4950
"sigs.k8s.io/cluster-api/util"
5051
"sigs.k8s.io/cluster-api/util/conditions"
5152
"sigs.k8s.io/cluster-api/util/patch"
@@ -1248,7 +1249,7 @@ func TestMachineHealthCheck_Reconcile(t *testing.T) {
12481249
},
12491250
},
12501251
}
1251-
machineSet.Default()
1252+
g.Expect((&webhooks.MachineSet{}).Default(ctx, machineSet)).Should(Succeed())
12521253
g.Expect(env.Create(ctx, machineSet)).To(Succeed())
12531254

12541255
// Ensure machines have been created.

0 commit comments

Comments
 (0)