Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup Go
uses: actions/setup-go@v6
Expand All @@ -38,7 +38,7 @@ jobs:
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v8
uses: golangci/golangci-lint-action@v9
with:
args: --build-tags integration -D protogetter --timeout=5m

Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup Go
uses: actions/setup-go@v6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/datastore/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (ip *IntegerPool) genericAcquire(term *r.Term) (uint, error) {
return 0, metal.Conflict("integer is already acquired by another")
}

result := uint(res.Changes[0].OldValue.(map[string]interface{})["id"].(float64))
result := uint(res.Changes[0].OldValue.(map[string]any)["id"].(float64))
return result, nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
8 changes: 4 additions & 4 deletions cmd/metal-api/internal/datastore/integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestRethinkStore_ReleaseUniqueInteger(t *testing.T) {
mock.On(r.DB("mockdb").Table(ip.String()).Insert(integer{ID: tt.value}, r.InsertOpts{Conflict: "replace"})).Return(nil, tt.err)
} else {
mock.On(r.DB("mockdb").Table(ip.String()).Insert(integer{ID: tt.value}, r.InsertOpts{Conflict: "replace"})).Return(r.
WriteResponse{Changes: []r.ChangeResponse{{OldValue: map[string]interface{}{"id": float64(
WriteResponse{Changes: []r.ChangeResponse{{OldValue: map[string]any{"id": float64(
tt.value)}}}}, tt.err)
}
}
Expand All @@ -114,7 +114,7 @@ func TestRethinkStore_ReleaseUniqueInteger(t *testing.T) {
func TestRethinkStore_AcquireRandomUniqueInteger(t *testing.T) {
rs, mock := InitMockDB(t)
ip := rs.GetVRFPool()
changes := []r.ChangeResponse{{OldValue: map[string]interface{}{"id": float64(rs.VRFPoolRangeMin)}}}
changes := []r.ChangeResponse{{OldValue: map[string]any{"id": float64(rs.VRFPoolRangeMin)}}}
mock.On(r.DB("mockdb").Table(ip.String()).Limit(1).Delete(r.
DeleteOpts{ReturnChanges: true})).Return(r.WriteResponse{Changes: changes}, nil)

Expand Down Expand Up @@ -153,7 +153,7 @@ func TestRethinkStore_AcquireUniqueInteger(t *testing.T) {
ip := rs.GetVRFPool()

if tt.requiresMock {
changes := []r.ChangeResponse{{OldValue: map[string]interface{}{"id": float64(
changes := []r.ChangeResponse{{OldValue: map[string]any{"id": float64(
tt.value)}}}
mock.On(r.DB("mockdb").Table(ip.String()).Get(tt.value).Delete(r.
DeleteOpts{ReturnChanges: true})).Return(r.WriteResponse{Changes: changes}, tt.err)
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestRethinkStore_genericAcquire(t *testing.T) {
if tt.requiresMock {
var changes []r.ChangeResponse
if tt.tableChanges {
changes = []r.ChangeResponse{{OldValue: map[string]interface{}{"id": float64(
changes = []r.ChangeResponse{{OldValue: map[string]any{"id": float64(
tt.value)}}}
}
mock.On(term.Delete(r.DeleteOpts{ReturnChanges: true})).Return(r.WriteResponse{Changes: changes},
Expand Down
1 change: 0 additions & 1 deletion cmd/metal-api/internal/datastore/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (p *IPSearchQuery) generateTerm(rs *RethinkStore) (*r.Term, error) {
}

for _, t := range p.Tags {
t := t
q = q.Filter(func(row r.Term) r.Term {
return row.Field("tags").Contains(r.Expr(t))
})
Expand Down
17 changes: 1 addition & 16 deletions cmd/metal-api/internal/datastore/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, tag := range p.Tags {
tag := tag
q = q.Filter(func(row r.Term) r.Term {
return row.Field("tags").Contains(r.Expr(tag))
})
Expand Down Expand Up @@ -151,7 +150,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, id := range p.NetworkIDs {
id := id
q = q.Filter(func(row r.Term) r.Term {
return row.Field("allocation").Field("networks").Map(func(nw r.Term) r.Term {
return nw.Field("networkid")
Expand All @@ -160,7 +158,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, prefix := range p.NetworkPrefixes {
prefix := prefix
q = q.Filter(func(row r.Term) r.Term {
return row.Field("allocation").Field("networks").Contains(func(nw r.Term) r.Term {
return nw.Field("prefixes").Contains(r.Expr(prefix))
Expand All @@ -169,7 +166,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, ip := range p.NetworkIPs {
ip := ip
q = q.Filter(func(row r.Term) r.Term {
return row.Field("allocation").Field("networks").Contains(func(nw r.Term) r.Term {
return nw.Field("ips").Contains(r.Expr(ip))
Expand All @@ -178,7 +174,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, destPrefix := range p.NetworkDestinationPrefixes {
destPrefix := destPrefix
q = q.Filter(func(row r.Term) r.Term {
return row.Field("allocation").Field("networks").Contains(func(nw r.Term) r.Term {
return nw.Field("destinationprefixes").Contains(r.Expr(destPrefix))
Expand All @@ -187,7 +182,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, vrf := range p.NetworkVrfs {
vrf := vrf
q = q.Filter(func(row r.Term) r.Term {
return row.Field("allocation").Field("networks").Contains(func(nw r.Term) r.Term {
return nw.Field("vrf").Eq(r.Expr(vrf))
Expand All @@ -196,7 +190,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, asn := range p.NetworkASNs {
asn := asn
q = q.Filter(func(row r.Term) r.Term {
return row.Field("allocation").Field("networks").Map(func(nw r.Term) r.Term {
return nw.Field("asn")
Expand All @@ -211,7 +204,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, mac := range p.NicsMacAddresses {
mac := mac
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("network_interfaces").Map(func(nic r.Term) r.Term {
return nic.Field("macAddress")
Expand All @@ -220,7 +212,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, name := range p.NicsNames {
name := name
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("network_interfaces").Map(func(nic r.Term) r.Term {
return nic.Field("name")
Expand All @@ -229,7 +220,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, vrf := range p.NicsVrfs {
vrf := vrf
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("network_interfaces").Map(func(nic r.Term) r.Term {
return nic.Field("vrf")
Expand All @@ -238,7 +228,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, mac := range p.NicsNeighborMacAddresses {
mac := mac
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("network_interfaces").Contains(func(nic r.Term) r.Term {
return nic.Field("neighbors").Contains(func(neigh r.Term) r.Term {
Expand All @@ -249,7 +238,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, name := range p.NicsNeighborNames {
name := name
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("network_interfaces").Contains(func(nic r.Term) r.Term {
return nic.Field("neighbors").Contains(func(neigh r.Term) r.Term {
Expand All @@ -260,7 +248,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, vrf := range p.NicsNeighborVrfs {
vrf := vrf
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("network_interfaces").Contains(func(nic r.Term) r.Term {
return nic.Field("neighbors").Contains(func(neigh r.Term) r.Term {
Expand All @@ -271,7 +258,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, name := range p.DiskNames {
name := name
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("block_devices").Map(func(bd r.Term) r.Term {
return bd.Field("name")
Expand All @@ -280,7 +266,6 @@ func (p *MachineSearchQuery) generateTerm(rs *RethinkStore) *r.Term {
}

for _, size := range p.DiskSizes {
size := size
q = q.Filter(func(row r.Term) r.Term {
return row.Field("hardware").Field("block_devices").Map(func(bd r.Term) r.Term {
return bd.Field("size")
Expand Down Expand Up @@ -424,7 +409,7 @@ func (rs *RethinkStore) UpdateMachine(oldMachine *metal.Machine, newMachine *met
// but current implementation should have a slightly better readability.
func (rs *RethinkStore) FindWaitingMachine(ctx context.Context, projectid, partitionid string, size metal.Size, placementTags []string, role metal.Role) (*metal.Machine, error) {
q := *rs.machineTable()
q = q.Filter(map[string]interface{}{
q = q.Filter(map[string]any{
"allocation": nil,
"partitionid": partitionid,
"sizeid": size.ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
6 changes: 3 additions & 3 deletions cmd/metal-api/internal/datastore/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
// MustRegisterMigration registers a migration and panics when a problem occurs
func MustRegisterMigration(m Migration) {
if m.Version < 1 {
panic(fmt.Sprintf("migrations should start from version number '1', but found version %q", m.Version))
panic(fmt.Sprintf("migrations should start from version number '1', but found version %d", m.Version))
}
migrationRegisterLock.Lock()
defer migrationRegisterLock.Unlock()
Expand Down Expand Up @@ -127,13 +127,13 @@ func (rs *RethinkStore) Migrate(targetVersion *int, dry bool) error {
}

rs.log.Info("setting demoted runtime user to read only", "user", DemotedUser)
_, err = rs.db().Grant(DemotedUser, map[string]interface{}{"read": true, "write": false}).RunWrite(rs.session)
_, err = rs.db().Grant(DemotedUser, map[string]any{"read": true, "write": false}).RunWrite(rs.session)
if err != nil {
return err
}
defer func() {
rs.log.Info("removing read only", "user", DemotedUser)
_, err = rs.db().Grant(DemotedUser, map[string]interface{}{"read": true, "write": true}).RunWrite(rs.session)
_, err = rs.db().Grant(DemotedUser, map[string]any{"read": true, "write": true}).RunWrite(rs.session)
if err != nil {
rs.log.Error("error giving back write permissions", "user", DemotedUser)
}
Expand Down
8 changes: 2 additions & 6 deletions cmd/metal-api/internal/datastore/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestMigrations_Between(t *testing.T) {
},
args: args{
current: 0,
target: intPtr(2),
target: new(2),
},
want: []Migration{
{
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestMigrations_Between(t *testing.T) {
},
args: args{
current: 0,
target: intPtr(3),
target: new(3),
},
want: nil,
wantErr: true,
Expand All @@ -162,7 +162,3 @@ func TestMigrations_Between(t *testing.T) {
})
}
}

func intPtr(i int) *int {
return &i
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func init() {
}

for _, m := range machines {
m := m

if m.Allocation == nil {
continue
Expand Down
2 changes: 0 additions & 2 deletions cmd/metal-api/internal/datastore/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ func (p *NetworkSearchQuery) generateTerm(rs *RethinkStore) (*r.Term, error) {
}

for k, v := range p.Labels {
k := k
v := v
q = q.Filter(func(row r.Term) r.Term {
return row.Field("labels").Field(k).Eq(v)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
20 changes: 10 additions & 10 deletions cmd/metal-api/internal/datastore/rethinkdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ func (rs *RethinkStore) initializeTables(opts r.TableCreateOpts) error {

// demoted runtime user creation / update
rs.log.Info("creating / updating demoted runtime user")
_, err = rs.userTable().Insert(map[string]interface{}{"id": DemotedUser, "password": rs.dbpass}, r.InsertOpts{
_, err = rs.userTable().Insert(map[string]any{"id": DemotedUser, "password": rs.dbpass}, r.InsertOpts{
Conflict: "update",
}).RunWrite(rs.session)
if err != nil {
return err
}
rs.log.Info("ensuring demoted user can read and write")
_, err = rs.db().Grant(DemotedUser, map[string]interface{}{"read": true, "write": true}).RunWrite(rs.session)
_, err = rs.db().Grant(DemotedUser, map[string]any{"read": true, "write": true}).RunWrite(rs.session)
if err != nil {
return err
}
_, err = r.DB("rethinkdb").Grant(DemotedUser, map[string]interface{}{"read": true}).RunWrite(rs.session)
_, err = r.DB("rethinkdb").Grant(DemotedUser, map[string]any{"read": true}).RunWrite(rs.session)
if err != nil {
return err
}
Expand Down Expand Up @@ -361,7 +361,7 @@ tryAgain:
return s
}

func (rs *RethinkStore) findEntityByID(table *r.Term, entity interface{}, id string) error {
func (rs *RethinkStore) findEntityByID(table *r.Term, entity any, id string) error {
res, err := table.Get(id).Run(rs.session)
if err != nil {
return fmt.Errorf("cannot find %v with id %q in database: %w", getEntityName(entity), id, err)
Expand All @@ -377,7 +377,7 @@ func (rs *RethinkStore) findEntityByID(table *r.Term, entity interface{}, id str
return nil
}

func (rs *RethinkStore) findEntity(query *r.Term, entity interface{}) error {
func (rs *RethinkStore) findEntity(query *r.Term, entity any) error {
res, err := query.Run(rs.session)
if err != nil {
return fmt.Errorf("cannot find %v in database: %w", getEntityName(entity), err)
Expand All @@ -392,7 +392,7 @@ func (rs *RethinkStore) findEntity(query *r.Term, entity interface{}) error {
return fmt.Errorf("cannot find %v in database: %w", getEntityName(entity), err)
}

next := map[string]interface{}{}
next := map[string]any{}
hasResult = res.Next(&next)
if hasResult {
return fmt.Errorf("more than one %v exists", getEntityName(entity))
Expand All @@ -401,7 +401,7 @@ func (rs *RethinkStore) findEntity(query *r.Term, entity interface{}) error {
return nil
}

func (rs *RethinkStore) searchEntities(query *r.Term, entity interface{}) error {
func (rs *RethinkStore) searchEntities(query *r.Term, entity any) error {
res, err := query.Run(rs.session)
if err != nil {
return fmt.Errorf("cannot search %v in database: %w", getEntityName(entity), err)
Expand All @@ -415,7 +415,7 @@ func (rs *RethinkStore) searchEntities(query *r.Term, entity interface{}) error
return nil
}

func (rs *RethinkStore) listEntities(table *r.Term, entity interface{}) error {
func (rs *RethinkStore) listEntities(table *r.Term, entity any) error {
res, err := table.Run(rs.session)
if err != nil {
return fmt.Errorf("cannot list %v from database: %w", getEntityName(entity), err)
Expand Down Expand Up @@ -493,9 +493,9 @@ func (rs *RethinkStore) updateEntity(table *r.Term, newEntity metal.Entity, oldE
return nil
}

func getEntityName(entity interface{}) string {
func getEntityName(entity any) string {
t := reflect.TypeOf(entity)
for t.Kind() == reflect.Ptr {
for t.Kind() == reflect.Pointer {
t = t.Elem()
}
return strings.ToLower(t.Name())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
1 change: 0 additions & 1 deletion cmd/metal-api/internal/datastore/shared_mutex_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package datastore

Expand Down
Loading