diff --git a/cmd/metal-api/internal/datastore/migrations_integration/migrate_integration_test.go b/cmd/metal-api/internal/datastore/migrations_integration/migrate_integration_test.go index fdb0e3b4..ef994335 100644 --- a/cmd/metal-api/internal/datastore/migrations_integration/migrate_integration_test.go +++ b/cmd/metal-api/internal/datastore/migrations_integration/migrate_integration_test.go @@ -5,7 +5,6 @@ package migrations_integration import ( "context" - "fmt" "log/slog" "os" "time" @@ -236,13 +235,13 @@ func Test_MigrationChildPrefixLength(t *testing.T) { n1fetched, err := rs.FindNetworkByID(n1.ID) require.NoError(t, err) require.NotNil(t, n1fetched) - require.Equal(t, p1.PrivateNetworkPrefixLength, n1fetched.DefaultChildPrefixLength[metal.IPv4AddressFamily], fmt.Sprintf("childprefixlength:%v", n1fetched.DefaultChildPrefixLength)) + require.Equal(t, p1.PrivateNetworkPrefixLength, n1fetched.DefaultChildPrefixLength[metal.IPv4AddressFamily], "childprefixlength:%v", n1fetched.DefaultChildPrefixLength) require.True(t, n1fetched.AddressFamilies[metal.IPv4AddressFamily]) n2fetched, err := rs.FindNetworkByID(n2.ID) require.NoError(t, err) require.NotNil(t, n2fetched) - require.Equal(t, p2.PrivateNetworkPrefixLength, n2fetched.DefaultChildPrefixLength[metal.IPv6AddressFamily], fmt.Sprintf("childprefixlength:%v", n2fetched.DefaultChildPrefixLength)) + require.Equal(t, p2.PrivateNetworkPrefixLength, n2fetched.DefaultChildPrefixLength[metal.IPv6AddressFamily], "childprefixlength:%v", n2fetched.DefaultChildPrefixLength) require.True(t, n2fetched.AddressFamilies[metal.IPv6AddressFamily]) n3fetched, err := rs.FindNetworkByID(n3.ID) diff --git a/cmd/metal-api/internal/service/machine-service_allocation_test.go b/cmd/metal-api/internal/service/machine-service_allocation_test.go index 8f0fc13e..6fa551df 100644 --- a/cmd/metal-api/internal/service/machine-service_allocation_test.go +++ b/cmd/metal-api/internal/service/machine-service_allocation_test.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "log/slog" "net" @@ -226,7 +227,7 @@ func allocMachine(container *restful.Container, ar v1.MachineAllocateRequest) (v resp := w.Result() defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return v1.MachineResponse{}, fmt.Errorf(w.Body.String()) + return v1.MachineResponse{}, errors.New(w.Body.String()) } var result v1.MachineResponse err = json.NewDecoder(resp.Body).Decode(&result) @@ -248,7 +249,7 @@ func freeMachine(container *restful.Container, id string) (v1.MachineResponse, e resp := w.Result() defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return v1.MachineResponse{}, fmt.Errorf(w.Body.String()) + return v1.MachineResponse{}, errors.New(w.Body.String()) } var result v1.MachineResponse err = json.NewDecoder(resp.Body).Decode(&result) diff --git a/cmd/metal-api/internal/service/switch-service.go b/cmd/metal-api/internal/service/switch-service.go index d84e7d60..42a7c69d 100644 --- a/cmd/metal-api/internal/service/switch-service.go +++ b/cmd/metal-api/internal/service/switch-service.go @@ -831,13 +831,14 @@ func (r *switchResource) makeBGPFilterMachine(m metal.Machine, ips metal.IPsMap) if err != nil { return v1.BGPFilter{}, err } - parentNetwork, err := r.ds.FindNetworkByID(privateNetwork.ID) - if err != nil { + parentNetwork, err := r.ds.FindNetworkByID(privateNetwork.ParentNetworkID) + if err != nil && !metal.IsNotFound(err) { return v1.BGPFilter{}, err } // Only for private networks, additionalRouteMapCidrs are applied. // they contain usually the pod- and service- cidrs in a kubernetes cluster if len(parentNetwork.AdditionalAnnouncableCIDRs) > 0 { + r.log.Debug("makeBGPFilterMachine", "additional cidrs", parentNetwork.AdditionalAnnouncableCIDRs) cidrs = append(cidrs, parentNetwork.AdditionalAnnouncableCIDRs...) } } diff --git a/cmd/metal-api/internal/service/switch-service_test.go b/cmd/metal-api/internal/service/switch-service_test.go index adbc3c07..9b62ed1b 100644 --- a/cmd/metal-api/internal/service/switch-service_test.go +++ b/cmd/metal-api/internal/service/switch-service_test.go @@ -505,7 +505,7 @@ func TestMakeBGPFilterMachine(t *testing.T) { mock.On(r.DB("mockdb").Table("network").Get(r.MockAnything()).Replace(r.MockAnything())).Return(testdata.EmptyResult, nil) mock.On(r.DB("mockdb").Table("network").Get(r.MockAnything()).Replace(r.MockAnything())).Return(testdata.EmptyResult, nil) - r := switchResource{webResource: webResource{ds: ds}} + r := switchResource{webResource: webResource{ds: ds, log: slog.Default()}} got, _ := r.makeBGPFilterMachine(tt.args.machine, tt.args.ipsMap) if !reflect.DeepEqual(got, tt.want) {