Skip to content

Commit cf42757

Browse files
authored
bootstrap: default to format=cloud-config (#355)
* 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
1 parent 8b892ad commit cf42757

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

internal/service/vmservice/bootstrap.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ func getBootstrapData(ctx context.Context, scope *scope.MachineScope) ([]byte, *
158158
return nil, nil, errors.Wrapf(err, "failed to retrieve bootstrap data secret")
159159
}
160160

161+
format := cloudinit.FormatCloudConfig
161162
f, ok := secret.Data["format"]
162-
if !ok {
163-
return nil, nil, errors.New("error retrieving format data: secret `format` key is missing")
163+
if ok {
164+
format = string(f)
164165
}
165-
format := string(f)
166+
166167
value, ok := secret.Data["value"]
167168
if !ok {
168169
return nil, nil, errors.New("error retrieving bootstrap data: secret `value` key is missing")

internal/service/vmservice/bootstrap_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,29 @@ func TestGetBootstrapData_MissingSecretValue(t *testing.T) {
169169
}
170170
require.NoError(t, client.Create(context.Background(), secret))
171171

172-
data, format, err := getBootstrapData(context.Background(), machineScope)
172+
// missing value
173+
data, _, err := getBootstrapData(context.Background(), machineScope)
173174
require.Error(t, err)
174-
require.Equal(t, err.Error(), "error retrieving format data: secret `format` key is missing")
175+
require.Equal(t, "error retrieving bootstrap data: secret `value` key is missing", err.Error())
175176
require.Nil(t, data)
176-
require.Nil(t, format)
177177

178-
// missing value
179-
secret.Data["format"] = []byte("cloud-config")
178+
secret.Data["value"] = []byte("notdata")
179+
require.NoError(t, client.Update(context.Background(), secret))
180+
181+
// test defaulting of format to cloud-config
182+
data, format, err := getBootstrapData(context.Background(), machineScope)
183+
require.Equal(t, cloudinit.FormatCloudConfig, ptr.Deref(format, ""))
184+
require.Equal(t, []byte("notdata"), data)
185+
require.Nil(t, err)
186+
187+
// test explicitly setting format to ignition
188+
secret.Data["format"] = []byte(ignition.FormatIgnition)
180189
require.NoError(t, client.Update(context.Background(), secret))
181190

182191
data, format, err = getBootstrapData(context.Background(), machineScope)
183-
require.Error(t, err)
184-
require.Equal(t, err.Error(), "error retrieving bootstrap data: secret `value` key is missing")
185-
require.Nil(t, data)
186-
require.Nil(t, format)
192+
require.Equal(t, ignition.FormatIgnition, ptr.Deref(format, ""))
193+
require.Equal(t, []byte("notdata"), data)
194+
require.Nil(t, err)
187195
}
188196

189197
func TestGetNetworkConfigDataForDevice_MissingIPAddress(t *testing.T) {

0 commit comments

Comments
 (0)