Skip to content

Commit 2af69ff

Browse files
committed
fix: provide minimal platform metadata always
Fixes #12097 Reverts "fix: provide nocloud metadata with missing network config" This reverts commit 435dcbf. The reverted commit fixes #12097, while minimal platform metadata fixes issue siderolabs/omni#1633 (reply in thread). Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent 92eeaa4 commit 2af69ff

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/cosi-project/runtime/pkg/safe"
1515
"go.uber.org/zap"
1616

17+
v1alpha1runtime "github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
1718
"github.com/siderolabs/talos/pkg/machinery/nethelpers"
1819
"github.com/siderolabs/talos/pkg/machinery/resources/network"
1920
runtimeres "github.com/siderolabs/talos/pkg/machinery/resources/runtime"
@@ -23,7 +24,9 @@ import (
2324
const externalLink = "external"
2425

2526
// PlatformConfigApplyController applies active (or cached) platform network config to the network stack.
26-
type PlatformConfigApplyController struct{}
27+
type PlatformConfigApplyController struct {
28+
V1alpha1Platform v1alpha1runtime.Platform
29+
}
2730

2831
// Name implements controller.Controller interface.
2932
func (ctrl *PlatformConfigApplyController) Name() string {
@@ -117,9 +120,13 @@ func (ctrl *PlatformConfigApplyController) Run(ctx context.Context, r controller
117120
}
118121
}
119122

120-
// if we don't have any config yet, wait...
123+
// if we don't have any config yet, populate a minimal one
124+
// to ensure that platform name is populated in the resource
121125
if platformConfig == nil {
122-
continue
126+
platformConfig = network.NewPlatformConfig(network.NamespaceName, network.PlatformConfigActiveID)
127+
platformConfig.TypedSpec().Metadata = &runtimeres.PlatformMetadataSpec{
128+
Platform: ctrl.V1alpha1Platform.Name(),
129+
}
123130
}
124131

125132
if err := ctrl.apply(ctx, r, platformConfig); err != nil {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/ctest"
1919
netctrl "github.com/siderolabs/talos/internal/app/machined/pkg/controllers/network"
20+
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/metal"
2021
"github.com/siderolabs/talos/pkg/machinery/nethelpers"
2122
"github.com/siderolabs/talos/pkg/machinery/resources/network"
2223
runtimeres "github.com/siderolabs/talos/pkg/machinery/resources/runtime"
@@ -297,6 +298,13 @@ func (suite *PlatformConfigApplySuite) TestMetadata() {
297298
})
298299
}
299300

301+
func (suite *PlatformConfigApplySuite) TestNoPlatformConfig() {
302+
ctest.AssertResource(suite, runtimeres.PlatformMetadataID,
303+
func(r *runtimeres.PlatformMetadata, asrt *assert.Assertions) {
304+
asrt.Equal("metal", r.TypedSpec().Platform)
305+
})
306+
}
307+
300308
func TestPlatformConfigApplySuite(t *testing.T) {
301309
t.Parallel()
302310

@@ -306,7 +314,9 @@ func TestPlatformConfigApplySuite(t *testing.T) {
306314
AfterSetup: func(suite *ctest.DefaultSuite) {
307315
suite.Require().NoError(
308316
suite.Runtime().RegisterController(
309-
&netctrl.PlatformConfigApplyController{},
317+
&netctrl.PlatformConfigApplyController{
318+
V1alpha1Platform: &metal.Metal{},
319+
},
310320
))
311321
},
312322
},

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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,3 @@ 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-
}

internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ func (ctrl *Controller) Run(ctx context.Context, drainer *runtime.Drainer) error
346346
&network.OperatorVIPConfigController{
347347
Cmdline: procfs.ProcCmdline(),
348348
},
349-
&network.PlatformConfigApplyController{},
349+
&network.PlatformConfigApplyController{
350+
V1alpha1Platform: ctrl.v1alpha1Runtime.State().Platform(),
351+
},
350352
&network.PlatformConfigController{
351353
V1alpha1Platform: ctrl.v1alpha1Runtime.State().Platform(),
352354
PlatformState: ctrl.v1alpha1Runtime.State().V1Alpha2().Resources(),

0 commit comments

Comments
 (0)