Skip to content

Commit ac27129

Browse files
committed
fix: provide minimal platform metadata always
Fixes #12097 This is same change as #12134, but adapted to release-1.11 code around platform network config. Revert "fix: provide nocloud metadata with missing network config" This reverts commit 0fbb0b0. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent 1946332 commit ac27129

File tree

4 files changed

+45
-43
lines changed

4 files changed

+45
-43
lines changed

internal/app/machined/pkg/controllers/network/platform_config.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ func (ctrl *PlatformConfigController) Run(ctx context.Context, r controller.Runt
176176
ctrl.networkConfigToPersist = networkConfig
177177
}
178178

179-
if ctrl.activeNetworkConfig != nil {
180-
if err := ctrl.apply(ctx, r); err != nil {
181-
return err
182-
}
179+
if err := ctrl.apply(ctx, r); err != nil {
180+
return err
183181
}
184182

185183
// we either need to save new network config, or we don't have any and we need to load cached config
@@ -257,6 +255,14 @@ func (ctrl *PlatformConfigController) loadStore() func(
257255
func (ctrl *PlatformConfigController) apply(ctx context.Context, r controller.Runtime) error {
258256
networkConfig := ctrl.activeNetworkConfig
259257

258+
if networkConfig == nil {
259+
networkConfig = &v1alpha1runtime.PlatformNetworkConfig{
260+
Metadata: &runtimeres.PlatformMetadataSpec{
261+
Platform: ctrl.V1alpha1Platform.Name(),
262+
},
263+
}
264+
}
265+
260266
metadataLength := 0
261267

262268
if networkConfig.Metadata != nil {

internal/app/machined/pkg/controllers/network/platform_config_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,24 @@ func (suite *PlatformConfigSuite) TestLoadConfig() {
417417
}, rtestutils.WithNamespace(network.ConfigNamespaceName))
418418
}
419419

420+
func (suite *PlatformConfigSuite) TestNoNetworkConfig() {
421+
suite.Require().NoError(
422+
suite.Runtime().RegisterController(
423+
&netctrl.PlatformConfigController{
424+
V1alpha1Platform: &platformMock{
425+
noData: true,
426+
},
427+
PlatformState: suite.State(),
428+
},
429+
),
430+
)
431+
432+
ctest.AssertResource(suite, runtimeres.PlatformMetadataID,
433+
func(r *runtimeres.PlatformMetadata, asrt *assert.Assertions) {
434+
asrt.Equal("mock", r.TypedSpec().Platform)
435+
})
436+
}
437+
420438
func TestPlatformConfigSuite(t *testing.T) {
421439
t.Parallel()
422440

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

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

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)
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
7672
}
73+
default:
74+
return nil, false, fmt.Errorf("network-config metadata version=%d is not supported", unmarshalledNetworkConfig.Version)
7775
}
7876

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

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

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

155154
// 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: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/stretchr/testify/require"
2020
"gopkg.in/yaml.v3"
2121

22-
platformruntime "github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
2322
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud"
2423
"github.com/siderolabs/talos/pkg/machinery/nethelpers"
2524
"github.com/siderolabs/talos/pkg/machinery/resources/network"
@@ -244,23 +243,3 @@ https://metadataserver3/userdata
244243
})
245244
}
246245
}
247-
248-
func TestEmptyNetworkConfig(t *testing.T) {
249-
t.Parallel()
250-
251-
n := &nocloud.Nocloud{}
252-
253-
st := state.WrapCore(namespaced.NewState(inmem.Build))
254-
255-
var md nocloud.MetadataConfig
256-
257-
networkConfig, needsReconcile, err := n.ParseMetadata(t.Context(), nil, st, &md)
258-
require.NoError(t, err)
259-
assert.False(t, needsReconcile)
260-
261-
assert.Equal(t, &platformruntime.PlatformNetworkConfig{
262-
Metadata: &runtime.PlatformMetadataSpec{
263-
Platform: "nocloud",
264-
},
265-
}, networkConfig)
266-
}

0 commit comments

Comments
 (0)