m/node: implement Port type for node ports
This allows us to use %v/%s to get a pretty port name where needed.
We also drive-by remove MasterServicePort which is a leftover from
a pre-curator cluster service implementation.
Change-Id: Id8feddf87269b13dd1dad2460a015c1a7ecbc6d7
Reviewed-on: https://review.monogon.dev/c/monogon/+/418
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/test/launch/launch.go b/metropolis/test/launch/launch.go
index 0b15a58..4a4c803 100644
--- a/metropolis/test/launch/launch.go
+++ b/metropolis/test/launch/launch.go
@@ -32,6 +32,7 @@
"golang.org/x/sys/unix"
"google.golang.org/grpc"
+ "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/pkg/freeport"
)
@@ -57,28 +58,28 @@
// PortMap represents where VM ports are mapped to on the host. It maps from the VM
// port number to the host port number.
-type PortMap map[uint16]uint16
+type PortMap map[node.Port]uint16
// ToQemuForwards generates QEMU hostfwd values (https://qemu.weilnetz.de/doc/qemu-
// doc.html#:~:text=hostfwd=) for all mapped ports.
func (p PortMap) ToQemuForwards() []string {
var hostfwdOptions []string
for vmPort, hostPort := range p {
- hostfwdOptions = append(hostfwdOptions, fmt.Sprintf("tcp::%v-:%v", hostPort, vmPort))
+ hostfwdOptions = append(hostfwdOptions, fmt.Sprintf("tcp::%d-:%d", hostPort, vmPort))
}
return hostfwdOptions
}
// DialGRPC creates a gRPC client for a VM port that's forwarded/mapped to the
// host. The given port is automatically resolved to the host-mapped port.
-func (p PortMap) DialGRPC(port uint16, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
+func (p PortMap) DialGRPC(port node.Port, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
mappedPort, ok := p[port]
if !ok {
- return nil, fmt.Errorf("cannot dial port: port %v is not mapped/forwarded", port)
+ return nil, fmt.Errorf("cannot dial port: port %d is not mapped/forwarded", port)
}
- grpcClient, err := grpc.Dial(fmt.Sprintf("localhost:%v", mappedPort), opts...)
+ grpcClient, err := grpc.Dial(fmt.Sprintf("localhost:%d", mappedPort), opts...)
if err != nil {
- return nil, fmt.Errorf("failed to dial port %v: %w", port, err)
+ return nil, fmt.Errorf("failed to dial port %d: %w", port, err)
}
return grpcClient, nil
}
@@ -86,10 +87,10 @@
// IdentityPortMap returns a port map where each given port is mapped onto itself
// on the host. This is mainly useful for development against Metropolis. The dbg
// command requires this mapping.
-func IdentityPortMap(ports []uint16) PortMap {
+func IdentityPortMap(ports []node.Port) PortMap {
portMap := make(PortMap)
for _, port := range ports {
- portMap[port] = port
+ portMap[port] = uint16(port)
}
return portMap
}
@@ -99,7 +100,7 @@
// multiple instances of Metropolis nodes might be running. Please call this
// function for each Launch command separately and as close to it as possible since
// it cannot guarantee that the ports will remain free.
-func ConflictFreePortMap(ports []uint16) (PortMap, error) {
+func ConflictFreePortMap(ports []node.Port) (PortMap, error) {
portMap := make(PortMap)
for _, port := range ports {
mappedPort, listenCloser, err := freeport.AllocateTCPPort()