m/node: implement static network config
Allows using a static network configuration in Monogon OS.
This plumbs in support for the new static network configuration mode of
the network service into Monogon OS. It introduces a new NodeParameter
field as well as an ESP file to persistently hold this configuration.
The file is not sealed or encrypted to allow recovery of nodes with
broken network configuration.
Change-Id: Ia398368a8d1c0eef4bca53bb279a97a144bdbd20
Reviewed-on: https://review.monogon.dev/c/monogon/+/1403
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/core/main.go b/metropolis/node/core/main.go
index bd7f475..a9bdc98 100644
--- a/metropolis/node/core/main.go
+++ b/metropolis/node/core/main.go
@@ -137,8 +137,26 @@
if err := root.Start(ctx); err != nil {
return fmt.Errorf("cannot start root FS: %w", err)
}
- if err := supervisor.Run(ctx, "network", networkSvc.Run); err != nil {
- return fmt.Errorf("when starting network: %w", err)
+ nodeParams, err := getNodeParams(ctx, root)
+ if err != nil {
+ return fmt.Errorf("cannot get node parameters: %w", err)
+ }
+ if nodeParams.NetworkConfig != nil {
+ networkSvc.StaticConfig = nodeParams.NetworkConfig
+ if err := root.ESP.Metropolis.NetworkConfiguration.Marshal(nodeParams.NetworkConfig); err != nil {
+ logger.Errorf("Error writing back network_config from NodeParameters: %v", err)
+ }
+ }
+ if networkSvc.StaticConfig == nil {
+ staticConfig, err := root.ESP.Metropolis.NetworkConfiguration.Unmarshal()
+ if err == nil {
+ networkSvc.StaticConfig = staticConfig
+ } else {
+ logger.Errorf("Unable to load static config, proceeding without it: %v", err)
+ }
+ if err := supervisor.Run(ctx, "network", networkSvc.Run); err != nil {
+ return fmt.Errorf("when starting network: %w", err)
+ }
}
if err := supervisor.Run(ctx, "time", timeSvc.Run); err != nil {
return fmt.Errorf("when starting time: %w", err)
@@ -166,7 +184,7 @@
// Start cluster manager. This kicks off cluster membership machinery,
// which will either start a new cluster, enroll into one or join one.
- m := cluster.NewManager(root, networkSvc, rs)
+ m := cluster.NewManager(root, networkSvc, rs, nodeParams)
return m.Run(ctx)
}