Skip to content

Commit

Permalink
fixup: add bootcommands check to validateIgnition function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidumea committed Jan 24, 2025
1 parent 0484cdc commit 3db48fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 10 additions & 0 deletions bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ func (c *KubeadmConfigSpec) validateIgnition(pathPrefix *field.Path) field.Error
}
}

if c.BootCommands != nil {
allErrs = append(
allErrs,
field.Forbidden(
pathPrefix.Child("bootCommands"),
cannotUseWithIgnition,
),
)
}

if c.DiskSetup == nil {
return allErrs
}
Expand Down
10 changes: 4 additions & 6 deletions bootstrap/kubeadm/internal/webhooks/kubeadmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ func (webhook *KubeadmConfig) ValidateCreate(_ context.Context, obj runtime.Obje
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a KubeadmConfig but got a %T", obj))
}
if c.Spec.BootCommands != nil && c.Spec.Format != bootstrapv1.CloudConfig {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected config format to be CloudConfig when using bootCommands, got %T", c.Spec.Format))
}

return nil, webhook.validate(c.Spec, c.Name)
}
Expand All @@ -78,9 +75,6 @@ func (webhook *KubeadmConfig) ValidateUpdate(_ context.Context, _, newObj runtim
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a KubeadmConfig but got a %T", newObj))
}
if newC.Spec.BootCommands != nil && newC.Spec.Format != bootstrapv1.CloudConfig {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected config format to be CloudConfig when using bootCommands, got %T", newC.Spec.Format))
}

return nil, webhook.validate(newC.Spec, newC.Name)
}
Expand All @@ -97,5 +91,9 @@ func (webhook *KubeadmConfig) validate(c bootstrapv1.KubeadmConfigSpec, name str
return nil
}

if c.BootCommands != nil && c.Format != bootstrapv1.CloudConfig {
return apierrors.NewBadRequest(fmt.Sprintf("expected config format to be CloudConfig when using bootCommands, got %T", c.Format))
}

return apierrors.NewInvalid(bootstrapv1.GroupVersion.WithKind("KubeadmConfig").GroupKind(), name, allErrs)
}

0 comments on commit 3db48fa

Please sign in to comment.