Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grpc boot service #279

Merged
merged 44 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
019724e
register and report boot service
majst01 May 6, 2022
a6d577b
Merge branch 'master' of https://github.com/metal-stack/metal-api int…
majst01 May 6, 2022
520dc1b
Report.success/message
majst01 May 6, 2022
0e17d3d
process nics with neighbors
majst01 May 8, 2022
99bddd3
Register BootService
majst01 May 9, 2022
901393e
Merge branch 'master' of https://github.com/metal-stack/metal-api int…
majst01 May 9, 2022
4c2b811
Return MachineNicExtended on machine get
majst01 May 9, 2022
78ce0e3
linter issue
majst01 May 9, 2022
7dcb5e8
spec adoption
majst01 May 9, 2022
cc88e7d
Remove NicExtended
majst01 May 9, 2022
439ed12
Set boot order to hdd
majst01 May 11, 2022
7cb35ea
add abortreinstall
majst01 May 11, 2022
1730c3b
add dhcp endpoint
majst01 May 12, 2022
687ece8
more logic
majst01 May 16, 2022
2dc04af
remove
majst01 May 17, 2022
b3ae53c
DHCP Request provides uuid instead of mac
majst01 May 17, 2022
88d0a56
fixes
majst01 May 17, 2022
d8b91ff
Fix
majst01 May 17, 2022
775cecc
more debug
majst01 May 17, 2022
1562faf
Log stack grpc panics
majst01 May 17, 2022
e0231b8
fix integration
majst01 May 17, 2022
c51809e
Docu and fixes
majst01 May 18, 2022
8f99886
Add hints for later removal
majst01 May 18, 2022
767e4d9
missed protoc
majst01 May 18, 2022
9dfdd4d
Update deps
majst01 May 25, 2022
398eba5
format proto with buf
majst01 May 25, 2022
511b4d6
Fix comment
majst01 May 25, 2022
754fea3
move proto files to new directory, use buf
majst01 May 30, 2022
7a413cd
move proto files to new directory, use buf
majst01 May 30, 2022
69802d5
Do not build protoc in docker, should already be compiled
majst01 May 30, 2022
fd84b28
review findings
majst01 May 30, 2022
e2de479
Ensure generated files are clean before generating
majst01 May 31, 2022
0a3554f
better proto linting
majst01 May 31, 2022
87ee45e
move superuserpassword service to boot as well
majst01 May 31, 2022
24c82cf
add missing comment
majst01 May 31, 2022
3cec500
Naming
majst01 May 31, 2022
8f4f8a1
Log supwd req
majst01 May 31, 2022
df05de7
Store version of metalhammer in the machinestate
majst01 May 31, 2022
5cbc32c
spec
majst01 May 31, 2022
9452b54
last updates
majst01 Jun 9, 2022
8617011
Ensure protoc runs in ci
majst01 Jun 10, 2022
40a1c1b
Better protoc
majst01 Jun 10, 2022
4e7fe11
performance and refactoring switch logic a bit
majst01 Jun 10, 2022
34f20f3
Review round with gerrit
majst01 Jun 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ jobs:
with:
go-version: '1.18.x'

- name: setup buf
uses: bufbuild/buf-setup-action@v1
with:
version: '1.5.0'

- name: generate proto and lint
working-directory: proto
run: make protoc

- name: Docker Login
uses: docker/login-action@v1
with:
Expand Down Expand Up @@ -47,10 +56,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.17
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: '1.17.x'
go-version: '1.18.x'

- name: Run integration tests
run: |
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ jobs:
with:
go-version: '1.18.x'

- name: setup buf
uses: bufbuild/buf-setup-action@v1
with:
version: '1.5.0'

- name: generate proto and lint
working-directory: proto
run: make protoc

- name: Figure out if running fork PR
id: fork
run: '["${{ secrets.DOCKER_REGISTRY_TOKEN }}" == ""] && echo "::set-output name=is_fork_pr::true" || echo "::set-output name=is_fork_pr::false"'
Expand Down Expand Up @@ -50,10 +59,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.17
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: '1.17.x'
go-version: '1.18.x'

- name: Run integration tests
run: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ jobs:
with:
go-version: '1.18.x'

- name: setup buf
uses: bufbuild/buf-setup-action@v1
with:
version: '1.5.0'

- name: generate proto and lint
working-directory: proto
run: make protoc

- name: Docker Login
uses: docker/login-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bin
vendor
.idea
.vscode/settings.json
.vscode
generate
coverage.out
__debug_bin
__debug_bin
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM metalstack/builder:latest as builder

FROM alpine:3.15
FROM alpine:3.16
RUN apk -U add ca-certificates
COPY --from=builder /work/bin/metal-api /metal-api
CMD ["/metal-api"]
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MINI_LAB_KUBECONFIG := $(shell pwd)/../mini-lab/.kubeconfig

include $(COMMONDIR)/Makefile.inc

release:: protoc spec check-diff all ;
Gerrit91 marked this conversation as resolved.
Show resolved Hide resolved
release:: spec check-diff all ;

.PHONY: spec
spec: all
Expand All @@ -22,12 +22,13 @@ redoc:

.PHONY: protoc
protoc:
protoc -I pkg --go_out plugins=grpc:pkg pkg/api/v1/*.proto
rm -rf pkg/api/v1
make -C proto protoc

.PHONY: protoc-docker
protoc-docker:
docker pull metalstack/builder
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/work -w /work metalstack/builder protoc -I pkg --go_out plugins=grpc:pkg pkg/api/v1/*.proto
docker pull bufbuild/buf:1.5.0
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/work --tmpfs /.cache -w /work/proto bufbuild/buf:1.5.0 generate -v

.PHONY: mini-lab-push
mini-lab-push:
Expand Down
4 changes: 2 additions & 2 deletions cmd/metal-api/internal/datastore/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func (rs *RethinkStore) FromHardware(hw metal.MachineHardware) (*metal.Size, []*
// this should not happen, so we do not return a notfound
return nil, nil, errors.New("no sizes found in database")
}
var sizes []metal.Size
var sizes metal.Sizes
for _, s := range sz {
if len(s.Constraints) < 1 {
rs.Error("missing constraints", "size", s)
continue
}
sizes = append(sizes, s)
}
return metal.Sizes(sizes).FromHardware(hw)
return sizes.FromHardware(hw)
}
101 changes: 101 additions & 0 deletions cmd/metal-api/internal/datastore/switch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package datastore

import (
"fmt"

"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
)
Expand Down Expand Up @@ -64,6 +66,25 @@ func (rs *RethinkStore) SearchSwitches(rackid string, macs []string) ([]metal.Sw
return ss, nil
}

// SearchSwitchesByPartition searches for switches by the given partition.
func (rs *RethinkStore) SearchSwitchesByPartition(partitionID string) ([]metal.Switch, error) {
q := *rs.switchTable()

if partitionID != "" {
q = q.Filter(func(row r.Term) r.Term {
return row.Field("partitionid").Eq(partitionID)
})
}

var ss []metal.Switch
err := rs.searchEntities(&q, &ss)
if err != nil {
return nil, err
}

return ss, nil
}

// SearchSwitchesConnectedToMachine searches switches that are connected to the given machine.
func (rs *RethinkStore) SearchSwitchesConnectedToMachine(m *metal.Machine) ([]metal.Switch, error) {
switches, err := rs.SearchSwitches(m.RackID, nil)
Expand All @@ -79,3 +100,83 @@ func (rs *RethinkStore) SearchSwitchesConnectedToMachine(m *metal.Machine) ([]me
}
return res, nil
}

// SetVrfAtSwitches finds the switches connected to the given machine and puts the switch ports into the given vrf.
// Returns the updated switches.
func (rs *RethinkStore) SetVrfAtSwitches(m *metal.Machine, vrf string) ([]metal.Switch, error) {
switches, err := rs.SearchSwitchesConnectedToMachine(m)
if err != nil {
return nil, err
}
newSwitches := make([]metal.Switch, 0)
for i := range switches {
sw := switches[i]
oldSwitch := sw
sw.SetVrfOfMachine(m, vrf)
err := rs.UpdateSwitch(&oldSwitch, &sw)
if err != nil {
return nil, err
}
newSwitches = append(newSwitches, sw)
}
return newSwitches, nil
}

func (rs *RethinkStore) ConnectMachineWithSwitches(m *metal.Machine) error {
switches, err := rs.SearchSwitchesByPartition(m.PartitionID)
if err != nil {
return err
}
oldSwitches := []metal.Switch{}
newSwitches := []metal.Switch{}
for _, sw := range switches {
oldSwitch := sw
if cons := sw.ConnectMachine(m); cons > 0 {
oldSwitches = append(oldSwitches, oldSwitch)
newSwitches = append(newSwitches, sw)
}
}

if len(newSwitches) != 2 {
return fmt.Errorf("machine %v is not connected to exactly two switches, found connections to %d switches", m.ID, len(newSwitches))
}

s1 := newSwitches[0]
s2 := newSwitches[1]
cons1 := s1.MachineConnections[m.ID]
cons2 := s2.MachineConnections[m.ID]
connectionMapError := fmt.Errorf("twin-switches do not have a connection map that is mirrored crosswise for machine %v, switch %v (connections: %v), switch %v (connections: %v)", m.ID, s1.Name, cons1, s2.Name, cons2)
if len(cons1) != len(cons2) {
return connectionMapError
}

if s1.RackID != s2.RackID {
return fmt.Errorf("connected switches of a machine must reside in the same rack, rack of switch %s: %s, rack of switch %s: %s, machine: %s", s1.Name, s1.RackID, s2.Name, s2.RackID, m.ID)
}
// We detect the rackID of a machine by connections to leaf switches
m.RackID = s1.RackID
m.PartitionID = s1.PartitionID

byNicName, err := s2.MachineConnections.ByNicName()
if err != nil {
return err
}
for _, con := range s1.MachineConnections[m.ID] {
if con2, has := byNicName[con.Nic.Name]; has {
if con.Nic.Name != con2.Nic.Name {
return connectionMapError
}
} else {
return connectionMapError
}
}

for i := range oldSwitches {
err = rs.UpdateSwitch(&oldSwitches[i], &newSwitches[i])
if err != nil {
return err
}
}

return nil
}
Loading