Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Move API v1beta1 webhooks to a separate package #9047

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/v1beta1/machinehealthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ limitations under the License.
package v1beta1

import (
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

var (
// DefaultNodeStartupTimeout is the time allowed for a node to start up.
// Can be made longer as part of spec if required for particular provider.
// 10 minutes should allow the instance to start and the node to join the
// cluster on most providers.
DefaultNodeStartupTimeout = metav1.Duration{Duration: 10 * time.Minute}
)

// ANCHOR: MachineHealthCheckSpec

// MachineHealthCheckSpec defines the desired state of MachineHealthCheck.
Expand Down
22 changes: 0 additions & 22 deletions api/v1beta1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 38 additions & 38 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-cluster-x-k8s-io-v1beta1-machine
path: /mutate-cluster-x-k8s-io-v1beta1-cluster
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machine.cluster.x-k8s.io
name: default.cluster.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -24,7 +24,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- machines
- clusters
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -33,10 +33,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-cluster-x-k8s-io-v1beta1-machinedeployment
path: /mutate-cluster-x-k8s-io-v1beta1-clusterclass
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machinedeployment.cluster.x-k8s.io
name: default.clusterclass.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -46,7 +46,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- machinedeployments
- clusterclasses
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -55,10 +55,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-cluster-x-k8s-io-v1beta1-machinehealthcheck
path: /mutate-cluster-x-k8s-io-v1beta1-machine
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machinehealthcheck.cluster.x-k8s.io
name: default.machine.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -68,7 +68,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- machinehealthchecks
- machines
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -77,10 +77,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-cluster-x-k8s-io-v1beta1-machineset
path: /mutate-cluster-x-k8s-io-v1beta1-machinedeployment
failurePolicy: Fail
matchPolicy: Equivalent
name: default.machineset.cluster.x-k8s.io
name: default.machinedeployment.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -90,7 +90,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- machinesets
- machinedeployments
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -99,10 +99,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-cluster-x-k8s-io-v1beta1-cluster
path: /mutate-cluster-x-k8s-io-v1beta1-machinehealthcheck
failurePolicy: Fail
matchPolicy: Equivalent
name: default.cluster.cluster.x-k8s.io
name: default.machinehealthcheck.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -112,7 +112,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- clusters
- machinehealthchecks
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -121,10 +121,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-cluster-x-k8s-io-v1beta1-clusterclass
path: /mutate-cluster-x-k8s-io-v1beta1-machineset
failurePolicy: Fail
matchPolicy: Equivalent
name: default.clusterclass.cluster.x-k8s.io
name: default.machineset.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -134,7 +134,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- clusterclasses
- machinesets
sideEffects: None
- admissionReviewVersions:
- v1
Expand Down Expand Up @@ -215,10 +215,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-cluster-x-k8s-io-v1beta1-machine
path: /validate-cluster-x-k8s-io-v1beta1-cluster
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.machine.cluster.x-k8s.io
name: validation.cluster.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -227,8 +227,9 @@ webhooks:
operations:
- CREATE
- UPDATE
- DELETE
resources:
- machines
- clusters
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -237,10 +238,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-cluster-x-k8s-io-v1beta1-machinedeployment
path: /validate-cluster-x-k8s-io-v1beta1-clusterclass
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.machinedeployment.cluster.x-k8s.io
name: validation.clusterclass.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -249,8 +250,9 @@ webhooks:
operations:
- CREATE
- UPDATE
- DELETE
resources:
- machinedeployments
- clusterclasses
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -259,10 +261,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-cluster-x-k8s-io-v1beta1-machinehealthcheck
path: /validate-cluster-x-k8s-io-v1beta1-machine
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.machinehealthcheck.cluster.x-k8s.io
name: validation.machine.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -272,7 +274,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- machinehealthchecks
- machines
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -281,10 +283,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-cluster-x-k8s-io-v1beta1-machineset
path: /validate-cluster-x-k8s-io-v1beta1-machinedeployment
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.machineset.cluster.x-k8s.io
name: validation.machinedeployment.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -294,7 +296,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- machinesets
- machinedeployments
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -303,10 +305,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-cluster-x-k8s-io-v1beta1-cluster
path: /validate-cluster-x-k8s-io-v1beta1-machinehealthcheck
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.cluster.cluster.x-k8s.io
name: validation.machinehealthcheck.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -315,9 +317,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- DELETE
resources:
- clusters
- machinehealthchecks
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -326,10 +327,10 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-cluster-x-k8s-io-v1beta1-clusterclass
path: /validate-cluster-x-k8s-io-v1beta1-machineset
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.clusterclass.cluster.x-k8s.io
name: validation.machineset.cluster.x-k8s.io
rules:
- apiGroups:
- cluster.x-k8s.io
Expand All @@ -338,9 +339,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- DELETE
resources:
- clusterclasses
- machinesets
sideEffects: None
- admissionReviewVersions:
- v1
Expand Down
6 changes: 5 additions & 1 deletion controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"sigs.k8s.io/cluster-api/internal/contract"
"sigs.k8s.io/cluster-api/internal/test/builder"
"sigs.k8s.io/cluster-api/internal/util/ssa"
"sigs.k8s.io/cluster-api/internal/webhooks"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/certs"
"sigs.k8s.io/cluster-api/util/collections"
Expand Down Expand Up @@ -2418,7 +2419,10 @@ func createMachineNodePair(name string, cluster *clusterv1.Cluster, kcp *control
},
},
}
machine.Default()
webhook := webhooks.Machine{}
if err := webhook.Default(ctx, machine); err != nil {
panic(err)
}

node := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"sigs.k8s.io/cluster-api/controllers/remote"
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/internal/test/builder"
"sigs.k8s.io/cluster-api/internal/webhooks"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -1248,7 +1249,7 @@ func TestMachineHealthCheck_Reconcile(t *testing.T) {
},
},
}
machineSet.Default()
g.Expect((&webhooks.MachineSet{}).Default(ctx, machineSet)).Should(Succeed())
g.Expect(env.Create(ctx, machineSet)).To(Succeed())

// Ensure machines have been created.
Expand Down
Loading
Loading