m/node: extract network.Status to node.NetStatus
This is done to avoid nasty dependency loops involving clusternet and
the network service. The clusternet service can currently not be
included by anything also talking to the network service which will be
needed by future network work.
To make this work we pull out the critical network.Status into
node.NetStatus which itself imports nothing and is thus safe to import
everywhere.
Change-Id: I8935de02926b6e06b5211f90c0c7f9abd8699c6d
Reviewed-on: https://review.monogon.dev/c/monogon/+/4495
Tested-by: Jenkins CI
Reviewed-by: Jan Schär <jan@monogon.tech>
diff --git a/metropolis/node/BUILD.bazel b/metropolis/node/BUILD.bazel
index 1295f0b..479f4d9 100644
--- a/metropolis/node/BUILD.bazel
+++ b/metropolis/node/BUILD.bazel
@@ -13,6 +13,7 @@
"labels.go",
"net_ips.go",
"net_protocols.go",
+ "net_status.go",
"ports.go",
"validation.go",
],
diff --git a/metropolis/node/core/clusternet/BUILD.bazel b/metropolis/node/core/clusternet/BUILD.bazel
index 7ee8aa1..20a3fd0 100644
--- a/metropolis/node/core/clusternet/BUILD.bazel
+++ b/metropolis/node/core/clusternet/BUILD.bazel
@@ -15,7 +15,6 @@
"//metropolis/node/core/curator/proto/api",
"//metropolis/node/core/curator/watcher",
"//metropolis/node/core/localstorage",
- "//metropolis/node/core/network",
"//metropolis/proto/common",
"//osbase/event",
"//osbase/supervisor",
@@ -35,7 +34,6 @@
"//metropolis/node/core/curator/proto/api",
"//metropolis/node/core/localstorage",
"//metropolis/node/core/localstorage/declarative",
- "//metropolis/node/core/network",
"//metropolis/proto/common",
"//metropolis/test/util",
"//osbase/event/memory",
diff --git a/metropolis/node/core/clusternet/clusternet.go b/metropolis/node/core/clusternet/clusternet.go
index 89c5c10..6ea53f2 100644
--- a/metropolis/node/core/clusternet/clusternet.go
+++ b/metropolis/node/core/clusternet/clusternet.go
@@ -34,9 +34,9 @@
"github.com/cenkalti/backoff/v4"
"github.com/vishvananda/netlink"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/curator/watcher"
"source.monogon.dev/metropolis/node/core/localstorage"
- "source.monogon.dev/metropolis/node/core/network"
"source.monogon.dev/osbase/event"
"source.monogon.dev/osbase/supervisor"
@@ -61,7 +61,7 @@
// it knows about the local node's IPAM address assignment.
LocalKubernetesPodNetwork event.Value[*Prefixes]
// Network service used to get the local node's IP address to submit it as a /32.
- Network event.Value[*network.Status]
+ Network event.Value[*node.NetStatus]
// wg is the interface to all the low-level interactions with WireGuard (and
// kernel routing). If not set, this defaults to a production implementation.
@@ -84,7 +84,7 @@
supervisor.Logger(ctx).Infof("Wireguard setup complete, starting updaters...")
kubeC := make(chan *Prefixes)
- netC := make(chan *network.Status)
+ netC := make(chan *node.NetStatus)
if err := supervisor.RunGroup(ctx, map[string]supervisor.Runnable{
"source-kubernetes": event.Pipe(s.LocalKubernetesPodNetwork, kubeC),
"source-network": event.Pipe(s.Network, netC),
@@ -105,7 +105,7 @@
// push is the sub-runnable responsible for letting the Curator know about what
// prefixes that are originated by this node.
-func (s *Service) push(ctx context.Context, kubeC chan *Prefixes, netC chan *network.Status) error {
+func (s *Service) push(ctx context.Context, kubeC chan *Prefixes, netC chan *node.NetStatus) error {
supervisor.Signal(ctx, supervisor.SignalHealthy)
var kubePrefixes *Prefixes
diff --git a/metropolis/node/core/clusternet/clusternet_test.go b/metropolis/node/core/clusternet/clusternet_test.go
index 9747e63..741bc24 100644
--- a/metropolis/node/core/clusternet/clusternet_test.go
+++ b/metropolis/node/core/clusternet/clusternet_test.go
@@ -19,7 +19,6 @@
common "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/localstorage"
"source.monogon.dev/metropolis/node/core/localstorage/declarative"
- "source.monogon.dev/metropolis/node/core/network"
"source.monogon.dev/metropolis/test/util"
"source.monogon.dev/osbase/event/memory"
"source.monogon.dev/osbase/supervisor"
@@ -94,7 +93,7 @@
defer cl.Close()
curator := apb.NewCuratorClient(cl)
- var nval memory.Value[*network.Status]
+ var nval memory.Value[*common.NetStatus]
var podNetwork memory.Value[*Prefixes]
wg := &fakeWireguard{}
diff --git a/metropolis/node/core/network/hostsfile/BUILD.bazel b/metropolis/node/core/network/hostsfile/BUILD.bazel
index d7b5fd9..2d6d9c0 100644
--- a/metropolis/node/core/network/hostsfile/BUILD.bazel
+++ b/metropolis/node/core/network/hostsfile/BUILD.bazel
@@ -6,6 +6,7 @@
importpath = "source.monogon.dev/metropolis/node/core/network/hostsfile",
visibility = ["//visibility:public"],
deps = [
+ "//metropolis/node",
"//metropolis/node/core/curator/proto/api",
"//metropolis/node/core/curator/watcher",
"//metropolis/node/core/localstorage",
diff --git a/metropolis/node/core/network/hostsfile/hostsfile.go b/metropolis/node/core/network/hostsfile/hostsfile.go
index e509935..62d9af3 100644
--- a/metropolis/node/core/network/hostsfile/hostsfile.go
+++ b/metropolis/node/core/network/hostsfile/hostsfile.go
@@ -32,6 +32,7 @@
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/curator/watcher"
"source.monogon.dev/metropolis/node/core/localstorage"
"source.monogon.dev/metropolis/node/core/network"
@@ -159,7 +160,7 @@
supervisor.Logger(ctx).Infof("Saved cluster directory absent, not restoring any host data.")
}
- localC := make(chan *network.Status)
+ localC := make(chan *node.NetStatus)
s.clusterC = make(chan nodeMap)
if err := supervisor.Run(ctx, "local", event.Pipe(&s.Network.Status, localC)); err != nil {
diff --git a/metropolis/node/core/network/main.go b/metropolis/node/core/network/main.go
index 58af75a..3e069c3 100644
--- a/metropolis/node/core/network/main.go
+++ b/metropolis/node/core/network/main.go
@@ -58,7 +58,7 @@
natPostroutingChain *nftables.Chain
// Status is the current status of the network as seen by the service.
- Status memory.Value[*Status]
+ Status memory.Value[*node.NetStatus]
}
// New instantiates a new network service. If autoconfiguration is desired,
@@ -79,14 +79,6 @@
}
}
-// Status is the current network status of the host. It will be updated by the
-// network Service whenever the node's network configuration changes. Spurious
-// changes might occur, consumers should ensure that the change that occured is
-// meaningful to them.
-type Status struct {
- ExternalAddress net.IP
-}
-
func singleIPtoNetlinkAddr(ip net.IP, label string) *netlink.Addr {
var mask net.IPMask
if ip.To4() == nil {
@@ -171,7 +163,7 @@
if !newAddress.Equal(s.dhcpAddress) {
s.dhcpAddress = newAddress
// Notify status waiters.
- s.Status.Set(&Status{
+ s.Status.Set(&node.NetStatus{
ExternalAddress: newAddress,
})
if newAddress != nil {
diff --git a/metropolis/node/core/network/static.go b/metropolis/node/core/network/static.go
index 059cd5d..e8169d9 100644
--- a/metropolis/node/core/network/static.go
+++ b/metropolis/node/core/network/static.go
@@ -20,6 +20,7 @@
"source.monogon.dev/go/algorithm/toposort"
"source.monogon.dev/go/logging"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/network/dhcp4c"
dhcpcb "source.monogon.dev/metropolis/node/core/network/dhcp4c/callback"
"source.monogon.dev/osbase/supervisor"
@@ -175,7 +176,7 @@
}
}
}
- s.Status.Set(&Status{
+ s.Status.Set(&node.NetStatus{
ExternalAddress: selectedAddr,
})
}
diff --git a/metropolis/node/core/tconsole/BUILD.bazel b/metropolis/node/core/tconsole/BUILD.bazel
index c551760..f7b4ede 100644
--- a/metropolis/node/core/tconsole/BUILD.bazel
+++ b/metropolis/node/core/tconsole/BUILD.bazel
@@ -16,7 +16,7 @@
importpath = "source.monogon.dev/metropolis/node/core/tconsole",
visibility = ["//visibility:public"],
deps = [
- "//metropolis/node/core/network",
+ "//metropolis/node",
"//metropolis/node/core/productinfo",
"//metropolis/node/core/roleserve",
"//metropolis/proto/common",
diff --git a/metropolis/node/core/tconsole/standalone/BUILD.bazel b/metropolis/node/core/tconsole/standalone/BUILD.bazel
index e9ed29a..df9564d 100644
--- a/metropolis/node/core/tconsole/standalone/BUILD.bazel
+++ b/metropolis/node/core/tconsole/standalone/BUILD.bazel
@@ -12,7 +12,7 @@
"source.monogon.dev/metropolis/node/core/productinfo.path": "$(rlocationpath //metropolis/node:product_info )",
},
deps = [
- "//metropolis/node/core/network",
+ "//metropolis/node",
"//metropolis/node/core/roleserve",
"//metropolis/node/core/tconsole",
"//metropolis/proto/common",
diff --git a/metropolis/node/core/tconsole/standalone/main.go b/metropolis/node/core/tconsole/standalone/main.go
index eaf2c47..e1b23d2 100644
--- a/metropolis/node/core/tconsole/standalone/main.go
+++ b/metropolis/node/core/tconsole/standalone/main.go
@@ -18,7 +18,7 @@
"os/signal"
"time"
- "source.monogon.dev/metropolis/node/core/network"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/roleserve"
"source.monogon.dev/metropolis/node/core/tconsole"
cpb "source.monogon.dev/metropolis/proto/common"
@@ -28,7 +28,7 @@
)
func main() {
- var netV memory.Value[*network.Status]
+ var netV memory.Value[*node.NetStatus]
var rolesV memory.Value[*cpb.NodeRoles]
var curV memory.Value[*roleserve.CuratorConnection]
@@ -77,7 +77,7 @@
if err := delay(ctx, time.Millisecond*1000); err != nil {
return err
}
- netV.Set(&network.Status{
+ netV.Set(&node.NetStatus{
ExternalAddress: net.ParseIP(fmt.Sprintf("203.0.113.%d", mrand.Intn(256))),
})
}
diff --git a/metropolis/node/core/tconsole/tconsole.go b/metropolis/node/core/tconsole/tconsole.go
index eeb4536..315dca9 100644
--- a/metropolis/node/core/tconsole/tconsole.go
+++ b/metropolis/node/core/tconsole/tconsole.go
@@ -13,7 +13,7 @@
"github.com/gdamore/tcell/v2"
- "source.monogon.dev/metropolis/node/core/network"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/roleserve"
cpb "source.monogon.dev/metropolis/proto/common"
"source.monogon.dev/osbase/event"
@@ -24,7 +24,7 @@
type Config struct {
Terminal Terminal
LogTree *logtree.LogTree
- Network event.Value[*network.Status]
+ Network event.Value[*node.NetStatus]
Roles event.Value[*cpb.NodeRoles]
CuratorConn event.Value[*roleserve.CuratorConnection]
}
@@ -130,7 +130,7 @@
go c.screen.ChannelEvents(evC, evQuitC)
// Pipe event values into channels.
- netAddrC := make(chan *network.Status)
+ netAddrC := make(chan *node.NetStatus)
rolesC := make(chan *cpb.NodeRoles)
curatorConnC := make(chan *roleserve.CuratorConnection)
if err := supervisor.Run(ctx, "netpipe", event.Pipe(c.config.Network, netAddrC)); err != nil {
diff --git a/metropolis/node/kubernetes/service_controller.go b/metropolis/node/kubernetes/service_controller.go
index cd9fdbf..de85154 100644
--- a/metropolis/node/kubernetes/service_controller.go
+++ b/metropolis/node/kubernetes/service_controller.go
@@ -13,6 +13,7 @@
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/node/core/consensus"
"source.monogon.dev/metropolis/node/core/identity"
"source.monogon.dev/metropolis/node/core/localstorage"
@@ -101,7 +102,7 @@
networkWatch := s.c.Network.Status.Watch()
defer networkWatch.Close()
- var status *network.Status
+ var status *node.NetStatus
supervisor.Logger(ctx).Info("Waiting for node networking...")
for status == nil || status.ExternalAddress == nil {
diff --git a/metropolis/node/net_status.go b/metropolis/node/net_status.go
new file mode 100644
index 0000000..8bedfe4
--- /dev/null
+++ b/metropolis/node/net_status.go
@@ -0,0 +1,14 @@
+// Copyright The Monogon Project Authors.
+// SPDX-License-Identifier: Apache-2.0
+
+package node
+
+import "net"
+
+// NetStatus is the current network status of the host. It will be updated by the
+// network Service whenever the node's network configuration changes. Spurious
+// changes might occur, consumers should ensure that the change that occured is
+// meaningful to them.
+type NetStatus struct {
+ ExternalAddress net.IP
+}