Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/metal-stack/metal-api int…
Browse files Browse the repository at this point in the history
…o dualstack-support
  • Loading branch information
majst01 committed Aug 14, 2024
2 parents f553164 + f0628c1 commit fa47c76
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package migrations_integration

import (
"context"
"fmt"
"log/slog"
"os"
"time"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log/slog"
"net"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions cmd/metal-api/internal/service/switch-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/switch-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fa47c76

Please sign in to comment.