Skip to content

Commit

Permalink
fixup: make sure bootCommands is not configured when ignition format …
Browse files Browse the repository at this point in the history
…is used
  • Loading branch information
davidumea committed Jan 13, 2025
1 parent 03cbf01 commit b7c575a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bootstrap/kubeadm/internal/webhooks/kubeadmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ 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 != "cloud-config" {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected config format to be cloud-config when using bootCommands, got %T", c.Spec.Format))
}

return nil, webhook.validate(c.Spec, c.Name)
}
Expand All @@ -75,6 +78,9 @@ 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 != "cloud-config" {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected config format to be cloud-config when using bootCommands, got %T", newC.Spec.Format))
}

return nil, webhook.validate(newC.Spec, newC.Name)
}
Expand Down
30 changes: 30 additions & 0 deletions bootstrap/kubeadm/internal/webhooks/kubeadmconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,36 @@ func TestKubeadmConfigValidate(t *testing.T) {
},
expectErr: true,
},
"bootCommands configured with ignition format": {
enableIgnitionFeature: true,
in: &bootstrapv1.KubeadmConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "baz",
Namespace: metav1.NamespaceDefault,
},
Spec: bootstrapv1.KubeadmConfigSpec{
Format: bootstrapv1.Ignition,
BootCommands: []bootstrapv1.BootCommand{
{"echo", "$(date) hello BootCommands!"},
},
},
},
expectErr: true,
},
"bootCommands configured with cloud-config format": {
in: &bootstrapv1.KubeadmConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "baz",
Namespace: metav1.NamespaceDefault,
},
Spec: bootstrapv1.KubeadmConfigSpec{
Format: "cloud-config",
BootCommands: []bootstrapv1.BootCommand{
{"echo", "$(date) hello BootCommands!"},
},
},
},
},
}

for name, tt := range cases {
Expand Down

0 comments on commit b7c575a

Please sign in to comment.