Skip to content

Commit

Permalink
Support Additional Announcable CIDRs
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 26, 2024
1 parent e616e8a commit 27c09bb
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.18
FROM alpine:3.20
LABEL maintainer="metal-stack authors <[email protected]>"
COPY bin/metalctl-linux-amd64 /metalctl
ENTRYPOINT ["/metalctl"]
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22
FROM golang:1.23
WORKDIR /work
COPY go.* .
RUN go mod download
Expand Down
2 changes: 1 addition & 1 deletion cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func assertExhaustiveArgs(t *testing.T, args []string, exclude ...string) {
return nil
}
}
return fmt.Errorf("not exhaustive: does not contain " + prefix)
return fmt.Errorf("not exhaustive: does not contain %s", prefix)
}

root := newRootCmd(&config{comp: &completion.Completion{}})
Expand Down
67 changes: 38 additions & 29 deletions cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func newNetworkCmd(c *config) *cobra.Command {
cmd.Flags().StringSlice("prefixes", []string{}, "prefixes in this network.")
cmd.Flags().StringSlice("labels", []string{}, "add initial labels, must be in the form of key=value, use it like: --labels \"key1=value1,key2=value2\".")
cmd.Flags().StringSlice("destination-prefixes", []string{}, "destination prefixes in this network.")
cmd.Flags().StringSlice("additionalannouncablecidrs", []string{}, "list of cidrs which are added to the route maps per tenant private network, these are typically pod- and service cidrs, can only be set in a supernetwork")
cmd.Flags().BoolP("privatesuper", "", false, "set private super flag of network, if set to true, this network is used to start machines there.")
cmd.Flags().BoolP("nat", "", false, "set nat flag of network, if set to true, traffic from this network will be natted.")
cmd.Flags().BoolP("underlay", "", false, "set underlay flag of network, if set to true, this is used to transport underlay network traffic")
Expand Down Expand Up @@ -80,6 +81,7 @@ func newNetworkCmd(c *config) *cobra.Command {
cmd.Flags().StringSlice("add-destinationprefixes", []string{}, "destination prefixes to be added to the network [optional]")
cmd.Flags().StringSlice("remove-destinationprefixes", []string{}, "destination prefixes to be removed from the network [optional]")
cmd.Flags().StringSlice("labels", []string{}, "the labels of the network, must be in the form of key=value, use it like: --labels \"key1=value1,key2=value2\". [optional]")
cmd.Flags().StringSlice("additionalannouncablecidrs", []string{}, "list of cidrs which are added to the route maps per tenant private network, these are typically pod- and service cidrs, can only be set in a supernetwork")
cmd.Flags().Bool("shared", false, "marks a network as shared or not [optional]")
},
}
Expand Down Expand Up @@ -225,33 +227,35 @@ func (c networkCmd) Convert(r *models.V1NetworkResponse) (string, *models.V1Netw

func networkResponseToCreate(r *models.V1NetworkResponse) *models.V1NetworkCreateRequest {
return &models.V1NetworkCreateRequest{
Description: r.Description,
Destinationprefixes: r.Destinationprefixes,
ID: r.ID,
Labels: r.Labels,
Name: r.Name,
Nat: r.Nat,
Parentnetworkid: r.Parentnetworkid,
Partitionid: r.Partitionid,
Prefixes: r.Prefixes,
Privatesuper: r.Privatesuper,
Projectid: r.Projectid,
Shared: r.Shared,
Underlay: r.Underlay,
Vrf: r.Vrf,
Vrfshared: r.Vrfshared,
Description: r.Description,
Destinationprefixes: r.Destinationprefixes,
ID: r.ID,
Labels: r.Labels,
Name: r.Name,
Nat: r.Nat,
Parentnetworkid: r.Parentnetworkid,
Partitionid: r.Partitionid,
Prefixes: r.Prefixes,
Privatesuper: r.Privatesuper,
Projectid: r.Projectid,
Shared: r.Shared,
Underlay: r.Underlay,
Vrf: r.Vrf,
Vrfshared: r.Vrfshared,
Additionalannouncablecidrs: r.Additionalannouncablecidrs,
}
}

func networkResponseToUpdate(r *models.V1NetworkResponse) *models.V1NetworkUpdateRequest {
return &models.V1NetworkUpdateRequest{
Description: r.Description,
Destinationprefixes: r.Destinationprefixes,
ID: r.ID,
Labels: r.Labels,
Name: r.Name,
Prefixes: r.Prefixes,
Shared: r.Shared,
Description: r.Description,
Destinationprefixes: r.Destinationprefixes,
ID: r.ID,
Labels: r.Labels,
Name: r.Name,
Prefixes: r.Prefixes,
Shared: r.Shared,
Additionalannouncablecidrs: r.Additionalannouncablecidrs,
}
}

Expand Down Expand Up @@ -356,15 +360,20 @@ func (c *networkCmd) updateRequestFromCLI(args []string) (*models.V1NetworkUpdat
shared = viper.GetBool("shared")
}

var additionalCidrs []string
if viper.IsSet("additionalannouncablecidrs") {
additionalCidrs = viper.GetStringSlice("additionalannouncablecidrs")
}
var (
ur = &models.V1NetworkUpdateRequest{
Description: viper.GetString("description"),
Destinationprefixes: nil,
ID: pointer.Pointer(id),
Labels: labels,
Name: viper.GetString("name"),
Prefixes: nil,
Shared: shared,
Description: viper.GetString("description"),
Destinationprefixes: nil,
ID: pointer.Pointer(id),
Labels: labels,
Name: viper.GetString("name"),
Prefixes: nil,
Shared: shared,
Additionalannouncablecidrs: additionalCidrs,
}
addPrefixes = sets.New(viper.GetStringSlice("add-prefixes")...)
removePrefixes = sets.New(viper.GetStringSlice("remove-prefixes")...)
Expand Down
32 changes: 19 additions & 13 deletions cmd/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ var (
UsedIps: pointer.Pointer(int64(300)),
UsedPrefixes: pointer.Pointer(int64(400)),
},
Vrf: 50,
Vrfshared: true,
Vrf: 50,
Vrfshared: true,
Additionalannouncablecidrs: []string{},
}
network1child = &models.V1NetworkResponse{
Description: "child 1",
Expand All @@ -62,8 +63,9 @@ var (
UsedIps: pointer.Pointer(int64(300)),
UsedPrefixes: pointer.Pointer(int64(400)),
},
Vrf: 50,
Vrfshared: true,
Vrf: 50,
Vrfshared: true,
Additionalannouncablecidrs: []string{},
}
network2 = &models.V1NetworkResponse{
Description: "network 2",
Expand All @@ -85,8 +87,9 @@ var (
UsedIps: pointer.Pointer(int64(200)),
UsedPrefixes: pointer.Pointer(int64(100)),
},
Vrf: 60,
Vrfshared: true,
Vrf: 60,
Vrfshared: true,
Additionalannouncablecidrs: []string{},
}
)

Expand Down Expand Up @@ -297,6 +300,7 @@ nw1 network-1
"--underlay", strconv.FormatBool(*want.Underlay),
"--vrf", strconv.FormatInt(want.Vrf, 10),
"--vrfshared", strconv.FormatBool(want.Vrfshared),
"--additionalannouncablecidrs", "",
}
assertExhaustiveArgs(t, args, commonExcludedFileArgs()...)
return args
Expand All @@ -322,6 +326,7 @@ nw1 network-1
fmt.Sprintf("--shared=%t", want.Shared),
"--labels", "a=b",
"--name", want.Name,
"--additionalannouncablecidrs", "",
}
assertExhaustiveArgs(t, args, commonExcludedFileArgs()...)
return args
Expand All @@ -337,13 +342,14 @@ nw1 network-1
Payload: networkToUpdate,
}, nil)
mock.On("UpdateNetwork", testcommon.MatchIgnoreContext(t, network.NewUpdateNetworkParams().WithBody(&models.V1NetworkUpdateRequest{
ID: network1.ID,
Name: network1.Name,
Description: network1.Description,
Destinationprefixes: network1.Destinationprefixes,
Prefixes: network1.Prefixes,
Labels: network1.Labels,
Shared: network1.Shared,
ID: network1.ID,
Name: network1.Name,
Description: network1.Description,
Destinationprefixes: network1.Destinationprefixes,
Prefixes: network1.Prefixes,
Labels: network1.Labels,
Shared: network1.Shared,
Additionalannouncablecidrs: network1.Additionalannouncablecidrs,
})), nil).Return(&network.UpdateNetworkOK{
Payload: network1,
}, nil)
Expand Down
56 changes: 28 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/metal-stack/metalctl

go 1.22
go 1.23

require (
github.com/Masterminds/semver/v3 v3.2.1
Expand All @@ -10,7 +10,7 @@ require (
github.com/go-openapi/strfmt v0.23.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/metal-stack/metal-go v0.32.2
github.com/metal-stack/metal-go v0.33.1-0.20240826073837-338dfec8b9ce
github.com/metal-stack/metal-lib v0.17.1
github.com/metal-stack/updater v1.2.2
github.com/metal-stack/v v1.0.3
Expand All @@ -31,7 +31,7 @@ require (
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/avast/retry-go/v4 v4.6.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.24.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.12 // indirect
Expand All @@ -49,19 +49,19 @@ require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.5 // indirect
github.com/coreos/go-iptables v0.7.0 // indirect
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dblohm7/wingoes v0.0.0-20231220174005-6310b4cece37 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dblohm7/wingoes v0.0.0-20240801171404-fc12d7c70140 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e // indirect
github.com/emicklei/go-restful-openapi/v2 v2.9.1 // indirect
github.com/emicklei/go-restful-openapi/v2 v2.10.2 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
Expand All @@ -73,8 +73,8 @@ require (
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/goccy/go-yaml v1.12.0 // indirect
github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -95,13 +95,13 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/jsimonetti/rtnetlink v1.4.1 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.5 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.21 // indirect
github.com/lestrrat-go/jwx/v2 v2.1.0 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -112,7 +112,7 @@ require (
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/sdnotify v1.0.0 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/metal-stack/security v0.8.0 // indirect
github.com/metal-stack/security v0.8.1 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand Down Expand Up @@ -144,25 +144,25 @@ require (
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.mongodb.org/mongo-driver v1.16.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
Loading

0 comments on commit 27c09bb

Please sign in to comment.