Skip to content

Commit

Permalink
Support reporting nic identifiers (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyMikhalkin authored Mar 2, 2023
1 parent b9b49cf commit b5e11ba
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 685 deletions.
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
run:
concurrency: 4
deadline: 10m
linters:
disable:
- musttag
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ RUN curl -fLsS https://sourceforge.net/projects/e1000/files/ice%20stable/${ICE_V
&& mkdir -p /lib/firmware/intel/ice/ddp/ \
&& mv ice-${ICE_VERSION}/ddp/ice-${ICE_PKG_VERSION}.pkg /work/ice.pkg

FROM r.metal-stack.io/metal/supermicro:2.5.2 as sum

FROM golang:1.14-buster as initrd-builder
ENV UROOT_GIT_SHA_OR_TAG=v0.7.0
RUN apt-get update \
Expand Down Expand Up @@ -37,7 +35,7 @@ RUN mkdir -p ${GOPATH}/src/github.com/u-root \
&& GO111MODULE=off go install
WORKDIR /work
COPY lvmlocal.conf metal.key metal.key.pub passwd varrun Makefile .git /work/
COPY --from=sum /usr/bin/sum /work/
COPY --from=r.metal-stack.io/metal/supermicro:2.5.2 /usr/bin/sum /work/
COPY --from=builder /common /common
COPY --from=builder /work/ice.pkg /work/ice.pkg
COPY --from=builder /work/bin/metal-hammer /work/bin/
Expand Down
26 changes: 19 additions & 7 deletions cmd/network/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"strings"
"time"

v1 "github.com/metal-stack/metal-api/pkg/api/v1"

"github.com/metal-stack/go-lldpd/pkg/lldp"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/v"
"go.uber.org/zap"

Expand Down Expand Up @@ -95,9 +96,7 @@ func linkSetUp(name string) error {
}

// Neighbors of a interface, detected via ip neighbor detection
func (n *Network) Neighbors(name string) ([]*models.V1MachineNic, error) {
neighbors := make([]*models.V1MachineNic, 0)

func (n *Network) Neighbors(name string) (neighbors []*v1.MachineNic, err error) {
host := n.LLDPClient.Host

for !host.done {
Expand All @@ -115,13 +114,26 @@ func (n *Network) Neighbors(name string) ([]*models.V1MachineNic, error) {

neighs := host.neighbors[name]
for _, neigh := range neighs {
macAddress := neigh.Port.Value
neighbors = append(neighbors, &models.V1MachineNic{Mac: &macAddress, Name: &name})
identifier := neigh.Port.Value
// this breaks old metal-images because they still rely on the mac address field
// do not add this:
//
// mac := ""
// if m, err := net.ParseMAC(identifier); err == nil {
// mac = m.String()
// }
n.Log.Infow("register add neighbor", "nic", name, "identifier", identifier)
neighbors = append(neighbors, &v1.MachineNic{
Mac: identifier,
Identifier: identifier,
Name: name,
Hostname: neigh.Name,
})
}
return neighbors, nil
}

// InternalIP returns the first ipv4 ip of a eth* interface.
// InternalIP returns the first ipv4 ip of an eth* interface.
func InternalIP() string {
for _, name := range Interfaces() {
if !strings.HasPrefix(name, "eth") {
Expand Down
6 changes: 3 additions & 3 deletions cmd/network/lldpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func (l *LLDPClient) requirementsMet() bool {
if len(l.Host.neighbors) < l.Host.minimumInterfaces {
return false
}
// Then check if 2 distinct Chassis neighbors where found
// and every port type of a interface on the switch is set to mac

// Then check if 2 distinct Chassis neighbors were found
neighMap := make(map[string]string)
for iface, neighs := range l.Host.neighbors {
for _, neigh := range neighs {
if neigh.Chassis.Type == lldp.Mac && neigh.Port.Type == lldp.Mac {
if neigh.Chassis.Type == lldp.Mac && (neigh.Port.Type == lldp.Mac || neigh.Port.Type == lldp.Local) {
neighMap[neigh.Chassis.Value] = iface
}
}
Expand Down
18 changes: 3 additions & 15 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,13 @@ func (r *Register) readHardwareDetails() (*v1.BootServiceRegisterRequest, error)
// now attach neighbors, this will wait up to 2*tx-intervall
// if during this timeout not all required neighbors where found abort and reboot.
for _, nic := range nics {
r.log.Infow("register search neigbor for", "nic", nic.Name)
r.log.Infow("register search neighbor for", "nic", nic.Name)
neighbors, err := r.network.Neighbors(nic.Name)
if err != nil {
return nil, fmt.Errorf("unable to determine neighbors of interface:%s %w", nic.Name, err)
}
r.log.Infow("register found neigbor for", "nic", nic.Name, "neighbors", neighbors)
ns := []*v1.MachineNic{}
for i := range neighbors {
n := neighbors[i]
if n.Mac == nil || n.Name == nil {
continue
}
r.log.Infow("register add neigbor", "nic", n.Name, "mac", n.Mac)
ns = append(ns, &v1.MachineNic{
Mac: *n.Mac,
Name: *n.Name,
})
}
nic.Neighbors = ns
r.log.Infow("register found neighbor for", "nic", nic.Name, "neighbors", neighbors)
nic.Neighbors = neighbors
}

// Disks
Expand Down
61 changes: 33 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/metal-stack/metal-hammer

go 1.19
go 1.20

require (
github.com/beevik/ntp v0.3.0
Expand All @@ -10,7 +10,7 @@ require (
github.com/jaypipes/ghw v0.9.0
github.com/metal-stack/go-hal v0.4.2
github.com/metal-stack/go-lldpd v0.4.2
github.com/metal-stack/metal-api v0.21.4
github.com/metal-stack/metal-api v0.22.2
github.com/metal-stack/metal-go v0.21.4
github.com/metal-stack/pixie v0.2.2
github.com/metal-stack/v v1.0.3
Expand All @@ -19,10 +19,10 @@ require (
github.com/pierrec/lz4/v4 v4.1.17
github.com/u-root/u-root v0.10.0
github.com/vishvananda/netlink v1.2.1-beta.2
go.uber.org/zap v1.23.0
go.uber.org/zap v1.24.0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.1.0
google.golang.org/grpc v1.50.1
golang.org/x/sys v0.5.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -32,29 +32,32 @@ require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/avast/retry-go/v4 v4.3.0 // indirect
github.com/avast/retry-go/v4 v4.3.3 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/coreos/go-oidc/v3 v3.4.0 // indirect
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
github.com/creack/pty v1.1.18 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/frankban/quicktest v1.14.3 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gliderlabs/ssh v0.3.5 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/runtime v0.24.2 // indirect
github.com/go-openapi/spec v0.20.7 // indirect
github.com/go-openapi/runtime v0.25.0 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/strfmt v0.21.3 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.0 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand All @@ -65,37 +68,39 @@ require (
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.2.25 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
github.com/mdlayher/lldp v0.0.0-20150915211757-afd9f83164c5 // indirect
github.com/metal-stack/metal-lib v0.11.2 // indirect
github.com/metal-stack/security v0.6.5 // indirect
github.com/metal-stack/metal-lib v0.11.3 // indirect
github.com/metal-stack/security v0.6.6 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/sethvargo/go-password v0.2.0 // indirect
github.com/stmcginnis/gofish v0.13.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vishvananda/netns v0.0.0-20220913150850-18c4f4234207 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702 // indirect
go.mongodb.org/mongo-driver v1.10.3 // indirect
go.mongodb.org/mongo-driver v1.11.1 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 // indirect
google.golang.org/genproto v0.0.0-20230222225845-10f96fb3dbec // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.0 // indirect
Expand Down
Loading

0 comments on commit b5e11ba

Please sign in to comment.