cloud/agent: default to detected NetworkConfig installing OS

The agent should pick the detected NetworkConfig if the OSInstallRequest
does not contain a NetworkConfig

Change-Id: I27f75735907b7c993dcd7002a863cd8fe00699fa
Reviewed-on: https://review.monogon.dev/c/monogon/+/1602
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/cloud/agent/BUILD.bazel b/cloud/agent/BUILD.bazel
index e1febb6..9d8174e 100644
--- a/cloud/agent/BUILD.bazel
+++ b/cloud/agent/BUILD.bazel
@@ -25,6 +25,7 @@
         "//metropolis/pkg/scsi",
         "//metropolis/pkg/smbios",
         "//metropolis/pkg/supervisor",
+        "//net/proto",
         "@com_github_cenkalti_backoff_v4//:backoff",
         "@com_github_mdlayher_ethtool//:ethtool",
         "@com_github_vishvananda_netlink//:netlink",
diff --git a/cloud/agent/agent.go b/cloud/agent/agent.go
index a339794..ca2bd0c 100644
--- a/cloud/agent/agent.go
+++ b/cloud/agent/agent.go
@@ -156,7 +156,7 @@
 			installationReport = &bpb.OSInstallationReport{
 				Generation: res.InstallationRequest.Generation,
 			}
-			if err := install(res.InstallationRequest, l, isEFIBoot); err != nil {
+			if err := install(res.InstallationRequest, agentInit.NetworkConfig, l, isEFIBoot); err != nil {
 				l.Errorf("Installation failed: %v", err)
 				installationReport.Result = &bpb.OSInstallationReport_Error_{
 					Error: &bpb.OSInstallationReport_Error{
diff --git a/cloud/agent/install.go b/cloud/agent/install.go
index 17ec098..e05a57c 100644
--- a/cloud/agent/install.go
+++ b/cloud/agent/install.go
@@ -15,23 +15,31 @@
 	"source.monogon.dev/metropolis/node/build/mkimage/osimage"
 	"source.monogon.dev/metropolis/pkg/efivarfs"
 	"source.monogon.dev/metropolis/pkg/logtree"
+	npb "source.monogon.dev/net/proto"
 )
 
 // install dispatches OSInstallationRequests to the appropriate installer
 // method
-func install(req *bpb.OSInstallationRequest, l logtree.LeveledLogger, isEFIBoot bool) error {
+func install(req *bpb.OSInstallationRequest, netConfig *npb.Net, l logtree.LeveledLogger, isEFIBoot bool) error {
 	switch reqT := req.Type.(type) {
 	case *bpb.OSInstallationRequest_Metropolis:
-		return installMetropolis(reqT.Metropolis, l, isEFIBoot)
+		return installMetropolis(reqT.Metropolis, netConfig, l, isEFIBoot)
 	default:
 		return errors.New("unknown installation request type")
 	}
 }
 
-func installMetropolis(req *bpb.MetropolisInstallationRequest, l logtree.LeveledLogger, isEFIBoot bool) error {
+func installMetropolis(req *bpb.MetropolisInstallationRequest, netConfig *npb.Net, l logtree.LeveledLogger, isEFIBoot bool) error {
 	if !isEFIBoot {
 		return errors.New("Monogon OS can only be installed on EFI-booted machines, this one is not")
 	}
+
+	// Override the NodeParameters.NetworkConfig with the current NetworkConfig
+	// if it's missing.
+	if req.NodeParameters.NetworkConfig == nil {
+		req.NodeParameters.NetworkConfig = netConfig
+	}
+
 	// Download into a buffer as ZIP files cannot efficiently be read from
 	// HTTP in Go as the ReaderAt has no way of indicating continuous sections,
 	// thus a ton of small range requests would need to be used, causing