go: re-do the entire thing
This is a mega-change, but attempting to split this up further is
probably not worth the effort.
Summary:
1. Bump up bazel, rules_go, and others.
2. Switch to new go target naming (bye bye go_default_library)
3. Move go deps to go.mod/go.sum, use make gazelle generate from that
4. Bump up Python deps a bit
And also whatever was required to actually get things to work - loads of
small useless changes.
Tested to work on NixOS and Ubuntu 20.04:
$ bazel build //...
$ bazel test //...
Change-Id: I8364bdaa1406b9ae4d0385a6b607f3e7989f98a9
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1583
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/dc/topo/BUILD.bazel b/dc/topo/BUILD.bazel
index 83673e3..3cb0fb7 100644
--- a/dc/topo/BUILD.bazel
+++ b/dc/topo/BUILD.bazel
@@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
- name = "go_default_library",
+ name = "topo_lib",
srcs = [
"main.go",
"service.go",
@@ -9,23 +9,23 @@
importpath = "code.hackerspace.pl/hscloud/dc/topo",
visibility = ["//visibility:private"],
deps = [
- "//dc/proto:go_default_library",
- "//dc/topo/assets:go_default_library",
- "//dc/topo/graph:go_default_library",
- "//dc/topo/proto:go_default_library",
- "//dc/topo/state:go_default_library",
- "//go/mirko:go_default_library",
- "//go/statusz:go_default_library",
- "@com_github_digitalocean_go_netbox//netbox:go_default_library",
- "@com_github_digitalocean_go_netbox//netbox/client:go_default_library",
- "@com_github_golang_glog//:go_default_library",
+ "//dc/proto",
+ "//dc/topo/assets",
+ "//dc/topo/graph",
+ "//dc/topo/proto",
+ "//dc/topo/state",
+ "//go/mirko",
+ "//go/statusz",
+ "@com_github_digitalocean_go_netbox//netbox",
+ "@com_github_digitalocean_go_netbox//netbox/client",
+ "@com_github_fvbommel_sortorder//:sortorder",
+ "@com_github_golang_glog//:glog",
"@com_github_golang_protobuf//proto:go_default_library",
- "@ml_vbom_util//sortorder:go_default_library",
],
)
go_binary(
name = "topo",
- embed = [":go_default_library"],
+ embed = [":topo_lib"],
visibility = ["//visibility:public"],
)
diff --git a/dc/topo/assets/BUILD.bazel b/dc/topo/assets/BUILD.bazel
index 401487b..21d49f9 100644
--- a/dc/topo/assets/BUILD.bazel
+++ b/dc/topo/assets/BUILD.bazel
@@ -2,16 +2,16 @@
load("@io_bazel_rules_go//extras:embed_data.bzl", "go_embed_data")
go_embed_data(
- name = "assets",
+ name = "assets_embed",
srcs = glob(["*.js"]),
- package = "assets",
flatten = True,
+ package = "assets",
)
# keep
go_library(
- name = "go_default_library",
- srcs = [":assets"],
+ name = "assets",
+ srcs = [":assets_embed"],
importpath = "code.hackerspace.pl/hscloud/dc/topo/assets",
visibility = ["//dc/topo:__pkg__"],
)
diff --git a/dc/topo/graph/BUILD.bazel b/dc/topo/graph/BUILD.bazel
index 26a5fc2..fd93c4c 100644
--- a/dc/topo/graph/BUILD.bazel
+++ b/dc/topo/graph/BUILD.bazel
@@ -1,15 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
- name = "go_default_library",
+ name = "graph",
srcs = ["graph.go"],
importpath = "code.hackerspace.pl/hscloud/dc/topo/graph",
visibility = ["//visibility:public"],
deps = [
- "//dc/topo/proto:go_default_library",
- "@com_github_digitalocean_go_netbox//netbox/client:go_default_library",
- "@com_github_digitalocean_go_netbox//netbox/client/dcim:go_default_library",
- "@com_github_digitalocean_go_netbox//netbox/models:go_default_library",
- "@com_github_golang_glog//:go_default_library",
+ "//dc/topo/proto",
+ "@com_github_digitalocean_go_netbox//netbox/client",
+ "@com_github_digitalocean_go_netbox//netbox/client/dcim",
+ "@com_github_digitalocean_go_netbox//netbox/models",
+ "@com_github_golang_glog//:glog",
],
)
diff --git a/dc/topo/graph/graph.go b/dc/topo/graph/graph.go
index 4d31f39..288d306 100644
--- a/dc/topo/graph/graph.go
+++ b/dc/topo/graph/graph.go
@@ -142,7 +142,7 @@
}
-func (g *Graph) FeedFromNetbox(ctx context.Context, nb *client.NetBox) error {
+func (g *Graph) FeedFromNetbox(ctx context.Context, nb *client.NetBoxAPI) error {
// Clear all connections first, because it's easier that way.
for _, machine := range g.Machines {
for _, port := range machine.Ports {
@@ -169,18 +169,18 @@
return fmt.Errorf("while querying information about %q: %v", machine.Name, err)
}
for _, connection := range res.Payload.Results {
- ia := connection.InterfaceA
- ib := connection.InterfaceB
+ ia := connection.Interfacea
+ ib := connection.Interfaceb
if ia == nil || ib == nil {
continue
}
// Find which way this thing actually connects.
- var thisSide, otherSide *models.PeerInterface
- if ia.Device.Name == machine.Name {
+ var thisSide, otherSide *models.NestedInterface
+ if ia.Device.Name != nil && *ia.Device.Name == machine.Name {
thisSide = ia
otherSide = ib
- } else if ib.Device.Name == machine.Name {
+ } else if ib.Device.Name != nil && *ib.Device.Name == machine.Name {
thisSide = ib
otherSide = ia
} else {
@@ -192,9 +192,9 @@
if !ok {
continue
}
- sw, ok := g.Switches[otherSide.Device.Name]
+ sw, ok := g.Switches[*otherSide.Device.Name]
if !ok {
- glog.Warningf("Machine %q port %q is managed but connected to unknown device %q", machine.Name, thisPort.Name, otherSide.Device.Name)
+ glog.Warningf("Machine %q port %q is managed but connected to unknown device %q", machine.Name, thisPort.Name, *otherSide.Device.Name)
continue
}
otherPort, ok := sw.Ports[*otherSide.Name]
diff --git a/dc/topo/proto/BUILD.bazel b/dc/topo/proto/BUILD.bazel
index 3caae5b..488dea9 100644
--- a/dc/topo/proto/BUILD.bazel
+++ b/dc/topo/proto/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
@@ -15,7 +16,7 @@
)
go_library(
- name = "go_default_library",
+ name = "proto",
embed = [":proto_go_proto"],
importpath = "code.hackerspace.pl/hscloud/dc/topo/proto",
visibility = ["//visibility:public"],
diff --git a/dc/topo/service.go b/dc/topo/service.go
index 84eda5d..97a74dd 100644
--- a/dc/topo/service.go
+++ b/dc/topo/service.go
@@ -7,7 +7,7 @@
"sort"
"strings"
- "vbom.ml/util/sortorder"
+ "github.com/fvbommel/sortorder"
"code.hackerspace.pl/hscloud/go/mirko"
"code.hackerspace.pl/hscloud/go/statusz"
diff --git a/dc/topo/state/BUILD.bazel b/dc/topo/state/BUILD.bazel
index fefb3ef..6cb8d59 100644
--- a/dc/topo/state/BUILD.bazel
+++ b/dc/topo/state/BUILD.bazel
@@ -1,14 +1,14 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
- name = "go_default_library",
+ name = "state",
srcs = ["state.go"],
importpath = "code.hackerspace.pl/hscloud/dc/topo/state",
visibility = ["//visibility:public"],
deps = [
- "//dc/proto:go_default_library",
- "//dc/topo/proto:go_default_library",
- "//go/pki:go_default_library",
+ "//dc/proto",
+ "//dc/topo/proto",
+ "//go/pki",
"@org_golang_google_grpc//:go_default_library",
],
)