Skip to content

Commit

Permalink
bootstrap: default to format=cloud-config (#355)
Browse files Browse the repository at this point in the history
* bootstrap: default to `format=cloud-config`

Not every bootstrap provider sets the `format` key and i wasn't able to find any requirement for it in the capi contract.

With this change we default to cloud-config, as it was without this check, to restore functionality with other non-kubeadm bootstrap providers.

Takes care of cases where the CAPMOX controller errored out with
```
err="failed to reconcile VM: error retrieving format data: secret `format` key is missing"
```

* make the linter happy
  • Loading branch information
pborn-ionos authored Dec 6, 2024
1 parent 8b892ad commit cf42757
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
7 changes: 4 additions & 3 deletions internal/service/vmservice/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ func getBootstrapData(ctx context.Context, scope *scope.MachineScope) ([]byte, *
return nil, nil, errors.Wrapf(err, "failed to retrieve bootstrap data secret")
}

format := cloudinit.FormatCloudConfig
f, ok := secret.Data["format"]
if !ok {
return nil, nil, errors.New("error retrieving format data: secret `format` key is missing")
if ok {
format = string(f)
}
format := string(f)

value, ok := secret.Data["value"]
if !ok {
return nil, nil, errors.New("error retrieving bootstrap data: secret `value` key is missing")
Expand Down
26 changes: 17 additions & 9 deletions internal/service/vmservice/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,29 @@ func TestGetBootstrapData_MissingSecretValue(t *testing.T) {
}
require.NoError(t, client.Create(context.Background(), secret))

data, format, err := getBootstrapData(context.Background(), machineScope)
// missing value
data, _, err := getBootstrapData(context.Background(), machineScope)
require.Error(t, err)
require.Equal(t, err.Error(), "error retrieving format data: secret `format` key is missing")
require.Equal(t, "error retrieving bootstrap data: secret `value` key is missing", err.Error())
require.Nil(t, data)
require.Nil(t, format)

// missing value
secret.Data["format"] = []byte("cloud-config")
secret.Data["value"] = []byte("notdata")
require.NoError(t, client.Update(context.Background(), secret))

// test defaulting of format to cloud-config
data, format, err := getBootstrapData(context.Background(), machineScope)
require.Equal(t, cloudinit.FormatCloudConfig, ptr.Deref(format, ""))
require.Equal(t, []byte("notdata"), data)
require.Nil(t, err)

// test explicitly setting format to ignition
secret.Data["format"] = []byte(ignition.FormatIgnition)
require.NoError(t, client.Update(context.Background(), secret))

data, format, err = getBootstrapData(context.Background(), machineScope)
require.Error(t, err)
require.Equal(t, err.Error(), "error retrieving bootstrap data: secret `value` key is missing")
require.Nil(t, data)
require.Nil(t, format)
require.Equal(t, ignition.FormatIgnition, ptr.Deref(format, ""))
require.Equal(t, []byte("notdata"), data)
require.Nil(t, err)
}

func TestGetNetworkConfigDataForDevice_MissingIPAddress(t *testing.T) {
Expand Down

0 comments on commit cf42757

Please sign in to comment.