Skip to content

Commit 435dcbf

Browse files
committed
fix: provide nocloud metadata with missing network config
Even if network config is missing, provide metadata always. This way `PlatformMetadata` resource is properly populated, even if it just contains the platform information. See siderolabs/omni#1633 (reply in thread) Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent ec3bd87 commit 435dcbf

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/nocloud.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ func (n *Nocloud) ParseMetadata(ctx context.Context, unmarshalledNetworkConfig *
6161
err error
6262
)
6363

64-
switch unmarshalledNetworkConfig.Version {
65-
case 1:
66-
if needsReconcile, err = n.applyNetworkConfigV1(ctx, unmarshalledNetworkConfig, st, networkConfig); err != nil {
67-
return nil, false, err
68-
}
69-
case 2:
70-
if needsReconcile, err = n.applyNetworkConfigV2(ctx, unmarshalledNetworkConfig, st, networkConfig); err != nil {
71-
return nil, false, err
64+
if unmarshalledNetworkConfig != nil {
65+
switch unmarshalledNetworkConfig.Version {
66+
case 1:
67+
if needsReconcile, err = n.applyNetworkConfigV1(ctx, unmarshalledNetworkConfig, st, networkConfig); err != nil {
68+
return nil, false, err
69+
}
70+
case 2:
71+
if needsReconcile, err = n.applyNetworkConfigV2(ctx, unmarshalledNetworkConfig, st, networkConfig); err != nil {
72+
return nil, false, err
73+
}
74+
default:
75+
return nil, false, fmt.Errorf("network-config metadata version=%d is not supported", unmarshalledNetworkConfig.Version)
7276
}
73-
default:
74-
return nil, false, fmt.Errorf("network-config metadata version=%d is not supported", unmarshalledNetworkConfig.Version)
7577
}
7678

7779
networkConfig.Metadata = &runtimeres.PlatformMetadataSpec{
@@ -141,14 +143,13 @@ func (n *Nocloud) NetworkConfiguration(ctx context.Context, st state.State, ch c
141143
return err
142144
}
143145

144-
if metadataNetworkConfigDl == nil {
145-
// no data, use cached network configuration if available
146-
return nil
147-
}
146+
var unmarshalledNetworkConfig *NetworkConfig
148147

149-
unmarshalledNetworkConfig, err := DecodeNetworkConfig(metadataNetworkConfigDl)
150-
if err != nil {
151-
return err
148+
if metadataNetworkConfigDl != nil {
149+
unmarshalledNetworkConfig, err = DecodeNetworkConfig(metadataNetworkConfigDl)
150+
if err != nil {
151+
return err
152+
}
152153
}
153154

154155
// do a loop to retry network config remap in case of missing links

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/nocloud_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,23 @@ https://metadataserver3/userdata
243243
})
244244
}
245245
}
246+
247+
func TestEmptyNetworkConfig(t *testing.T) {
248+
t.Parallel()
249+
250+
n := &nocloud.Nocloud{}
251+
252+
st := state.WrapCore(namespaced.NewState(inmem.Build))
253+
254+
var md nocloud.MetadataConfig
255+
256+
networkConfig, needsReconcile, err := n.ParseMetadata(t.Context(), nil, st, &md)
257+
require.NoError(t, err)
258+
assert.False(t, needsReconcile)
259+
260+
assert.Equal(t, &network.PlatformConfigSpec{
261+
Metadata: &runtime.PlatformMetadataSpec{
262+
Platform: "nocloud",
263+
},
264+
}, networkConfig)
265+
}

0 commit comments

Comments
 (0)