Skip to content

Commit

Permalink
fixup: use constant when checking kubeadmconfig format
Browse files Browse the repository at this point in the history
  • Loading branch information
davidumea committed Jan 24, 2025
1 parent b7c575a commit 0484cdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions bootstrap/kubeadm/internal/webhooks/kubeadmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ 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))
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,8 +78,8 @@ 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))
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 Down
6 changes: 3 additions & 3 deletions bootstrap/kubeadm/internal/webhooks/kubeadmconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func TestKubeadmConfigValidate(t *testing.T) {
},
expectErr: true,
},
"bootCommands configured with ignition format": {
"bootCommands configured with Ignition format": {
enableIgnitionFeature: true,
in: &bootstrapv1.KubeadmConfig{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -473,14 +473,14 @@ func TestKubeadmConfigValidate(t *testing.T) {
},
expectErr: true,
},
"bootCommands configured with cloud-config format": {
"bootCommands configured with CloudConfig format": {
in: &bootstrapv1.KubeadmConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "baz",
Namespace: metav1.NamespaceDefault,
},
Spec: bootstrapv1.KubeadmConfigSpec{
Format: "cloud-config",
Format: bootstrapv1.CloudConfig,
BootCommands: []bootstrapv1.BootCommand{
{"echo", "$(date) hello BootCommands!"},
},
Expand Down

0 comments on commit 0484cdc

Please sign in to comment.