Skip to content

Commit

Permalink
Fix linter after moving webhooks for kubeadm to a different location
Browse files Browse the repository at this point in the history
  • Loading branch information
odvarkadaniel committed Sep 13, 2023
1 parent b1154fc commit e752c0f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
6 changes: 4 additions & 2 deletions internal/webhooks/kubeadm_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"sigs.k8s.io/cluster-api/internal/webhooks/util"
)

const namespace = "bar"

func TestKubeadmControlPlaneDefault(t *testing.T) {
g := NewWithT(t)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions internal/webhooks/kubeadmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion internal/webhooks/kubeadmconfigtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions webhooks/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ 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)
}

// 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)
}

0 comments on commit e752c0f

Please sign in to comment.