diff --git a/internal/webhooks/kubeadm_control_plane_test.go b/internal/webhooks/kubeadm_control_plane_test.go index 2787db40e94b..fa0d5912d3db 100644 --- a/internal/webhooks/kubeadm_control_plane_test.go +++ b/internal/webhooks/kubeadm_control_plane_test.go @@ -34,6 +34,8 @@ import ( "sigs.k8s.io/cluster-api/internal/webhooks/util" ) +const namespace = "bar" + func TestKubeadmControlPlaneDefault(t *testing.T) { g := NewWithT(t) @@ -111,7 +113,7 @@ func TestKubeadmControlPlaneValidateCreate(t *testing.T) { stringMaxSurge.Spec.RolloutStrategy.RollingUpdate.MaxSurge = &val invalidNamespace := valid.DeepCopy() - invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = "bar" + invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = namespace missingReplicas := valid.DeepCopy() missingReplicas.Spec.Replicas = nil @@ -447,7 +449,7 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { scaleToEven.Spec.Replicas = pointer.Int32(2) invalidNamespace := before.DeepCopy() - invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = "bar" + invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = namespace missingReplicas := before.DeepCopy() missingReplicas.Spec.Replicas = nil diff --git a/internal/webhooks/kubeadmconfig.go b/internal/webhooks/kubeadmconfig.go index a6ad8e58011e..33b1526e6f8e 100644 --- a/internal/webhooks/kubeadmconfig.go +++ b/internal/webhooks/kubeadmconfig.go @@ -52,7 +52,7 @@ func (webhook *KubeadmConfig) SetupWebhookWithManager(mgr ctrl.Manager) error { // +kubebuilder:webhook:verbs=create;update,path=/mutate-bootstrap-cluster-x-k8s-io-v1beta1-kubeadmconfig,mutating=true,failurePolicy=fail,groups=bootstrap.cluster.x-k8s.io,resources=kubeadmconfigs,versions=v1beta1,name=default.kubeadmconfig.bootstrap.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 // +kubebuilder:webhook:verbs=create;update,path=/validate-bootstrap-cluster-x-k8s-io-v1beta1-kubeadmconfig,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=bootstrap.cluster.x-k8s.io,resources=kubeadmconfigs,versions=v1beta1,name=validation.kubeadmconfig.bootstrap.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 -// KubeadmControlPlaneTemplate implements a validation and defaulting webhook for KubeadmControlPlaneTemplate. +// KubeadmConfig implements a validation and defaulting webhook for KubeadmConfig. type KubeadmConfig struct{} var _ webhook.CustomValidator = &KubeadmConfig{} @@ -273,16 +273,6 @@ func validateIgnition(c bootstrapv1.KubeadmConfigSpec, pathPrefix *field.Path) f } } - if c.UseExperimentalRetryJoin { - allErrs = append( - allErrs, - field.Forbidden( - pathPrefix.Child("useExperimentalRetryJoin"), - cannotUseWithIgnition, - ), - ) - } - for i, file := range c.Files { if file.Encoding == bootstrapv1.Gzip || file.Encoding == bootstrapv1.GzipBase64 { allErrs = append( diff --git a/internal/webhooks/kubeadmconfigtemplate.go b/internal/webhooks/kubeadmconfigtemplate.go index 8e7fa5eb8e01..5975d6c8de30 100644 --- a/internal/webhooks/kubeadmconfigtemplate.go +++ b/internal/webhooks/kubeadmconfigtemplate.go @@ -23,9 +23,10 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" - bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + + bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" ) func (webhook *KubeadmConfigTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error { @@ -39,6 +40,7 @@ func (webhook *KubeadmConfigTemplate) SetupWebhookWithManager(mgr ctrl.Manager) // +kubebuilder:webhook:verbs=create;update,path=/mutate-bootstrap-cluster-x-k8s-io-v1beta1-kubeadmconfigtemplate,mutating=true,failurePolicy=fail,groups=bootstrap.cluster.x-k8s.io,resources=kubeadmconfigtemplates,versions=v1beta1,name=default.kubeadmconfigtemplate.bootstrap.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 // +kubebuilder:webhook:verbs=create;update,path=/validate-bootstrap-cluster-x-k8s-io-v1beta1-kubeadmconfigtemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=bootstrap.cluster.x-k8s.io,resources=kubeadmconfigtemplates,versions=v1beta1,name=validation.kubeadmconfigtemplate.bootstrap.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 +// KubeadmConfigTemplate implements a validation and defaulting webhook for KubeadmConfigTemplate. type KubeadmConfigTemplate struct{} // Default implements webhook.Defaulter so a webhook will be registered for the type. diff --git a/webhooks/alias.go b/webhooks/alias.go index cf78db778d90..68d57acff29b 100644 --- a/webhooks/alias.go +++ b/webhooks/alias.go @@ -103,7 +103,7 @@ func (webhook *KubeadmControlPlaneTemplate) SetupWebhookWithManager(mgr ctrl.Man // KubeadmConfig implements a validating and defaulting webhook for KubeadmConfig. type KubeadmConfig struct{} -// KubeadmConfig sets up KubeadmConfig webhooks. +// SetupWebhookWithManager sets up KubeadmConfig webhooks. func (webhook *KubeadmConfig) SetupWebhookWithManager(mgr ctrl.Manager) error { return (&webhooks.KubeadmConfig{}).SetupWebhookWithManager(mgr) } @@ -111,7 +111,7 @@ func (webhook *KubeadmConfig) SetupWebhookWithManager(mgr ctrl.Manager) error { // KubeadmConfigTemplate implements a validating and defaulting webhook for KubeadmConfigTemplate. type KubeadmConfigTemplate struct{} -// SetupWebhookWithManager sets up KubeadmControlPlaneTemplate webhooks. +// SetupWebhookWithManager sets up KubeadmConfigTemplate webhooks. func (webhook *KubeadmConfigTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error { return (&webhooks.KubeadmConfigTemplate{}).SetupWebhookWithManager(mgr) }