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 765eb06
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 182 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
94 changes: 52 additions & 42 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 All @@ -262,19 +266,20 @@ func (c *networkCmd) createRequestFromCLI() (*models.V1NetworkCreateRequest, err
}

return &models.V1NetworkCreateRequest{
ID: pointer.Pointer(viper.GetString("id")),
Description: viper.GetString("description"),
Name: viper.GetString("name"),
Partitionid: viper.GetString("partition"),
Projectid: viper.GetString("project"),
Prefixes: viper.GetStringSlice("prefixes"),
Destinationprefixes: viper.GetStringSlice("destination-prefixes"),
Privatesuper: pointer.Pointer(viper.GetBool("privatesuper")),
Nat: pointer.Pointer(viper.GetBool("nat")),
Underlay: pointer.Pointer(viper.GetBool("underlay")),
Vrf: viper.GetInt64("vrf"),
Vrfshared: viper.GetBool("vrfshared"),
Labels: lbs,
ID: pointer.Pointer(viper.GetString("id")),
Description: viper.GetString("description"),
Name: viper.GetString("name"),
Partitionid: viper.GetString("partition"),
Projectid: viper.GetString("project"),
Prefixes: viper.GetStringSlice("prefixes"),
Destinationprefixes: viper.GetStringSlice("destination-prefixes"),
Privatesuper: pointer.Pointer(viper.GetBool("privatesuper")),
Nat: pointer.Pointer(viper.GetBool("nat")),
Underlay: pointer.Pointer(viper.GetBool("underlay")),
Vrf: viper.GetInt64("vrf"),
Vrfshared: viper.GetBool("vrfshared"),
Labels: lbs,
Additionalannouncablecidrs: viper.GetStringSlice("additionalannouncablecidrs"),
}, nil
}

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

additionalCidrs := resp.Additionalannouncablecidrs
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{"10.240.0.0/12"},
}
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", "10.240.0.0/12",
}
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", "10.240.0.0/12",
}
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
59 changes: 30 additions & 29 deletions docs/metalctl_network_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ metalctl network create [flags]
### Options

```
--bulk-output when used with --file (bulk operation): prints results at the end as a list. default is printing results intermediately during the operation, which causes single entities to be printed in a row.
-d, --description string description of the network to create. [optional]
--destination-prefixes strings destination prefixes in this network.
-f, --file string filename of the create or update request in yaml format, or - for stdin.
Example:
$ metalctl network describe network-1 -o yaml > network.yaml
$ vi network.yaml
$ # either via stdin
$ cat network.yaml | metalctl network create -f -
$ # or via file
$ metalctl network create -f network.yaml
the file can also contain multiple documents and perform a bulk operation.
-h, --help help for create
--id string id of the network to create. [optional]
--labels strings add initial labels, must be in the form of key=value, use it like: --labels "key1=value1,key2=value2".
-n, --name string name of the network to create. [optional]
--nat set nat flag of network, if set to true, traffic from this network will be natted.
-p, --partition string partition where this network should exist.
--prefixes strings prefixes in this network.
--privatesuper set private super flag of network, if set to true, this network is used to start machines there.
--project string project of the network to create. [optional]
--skip-security-prompts skips security prompt for bulk operations
--timestamps when used with --file (bulk operation): prints timestamps in-between the operations
--underlay set underlay flag of network, if set to true, this is used to transport underlay network traffic
--vrf int vrf of this network
--vrfshared vrf shared allows multiple networks to share a vrf
--additionalannouncablecidrs strings 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
--bulk-output when used with --file (bulk operation): prints results at the end as a list. default is printing results intermediately during the operation, which causes single entities to be printed in a row.
-d, --description string description of the network to create. [optional]
--destination-prefixes strings destination prefixes in this network.
-f, --file string filename of the create or update request in yaml format, or - for stdin.
Example:
$ metalctl network describe network-1 -o yaml > network.yaml
$ vi network.yaml
$ # either via stdin
$ cat network.yaml | metalctl network create -f -
$ # or via file
$ metalctl network create -f network.yaml
the file can also contain multiple documents and perform a bulk operation.
-h, --help help for create
--id string id of the network to create. [optional]
--labels strings add initial labels, must be in the form of key=value, use it like: --labels "key1=value1,key2=value2".
-n, --name string name of the network to create. [optional]
--nat set nat flag of network, if set to true, traffic from this network will be natted.
-p, --partition string partition where this network should exist.
--prefixes strings prefixes in this network.
--privatesuper set private super flag of network, if set to true, this network is used to start machines there.
--project string project of the network to create. [optional]
--skip-security-prompts skips security prompt for bulk operations
--timestamps when used with --file (bulk operation): prints timestamps in-between the operations
--underlay set underlay flag of network, if set to true, this is used to transport underlay network traffic
--vrf int vrf of this network
--vrfshared vrf shared allows multiple networks to share a vrf
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_network_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ metalctl network update [flags]
```
--add-destinationprefixes strings destination prefixes to be added to the network [optional]
--add-prefixes strings prefixes to be added to the network [optional]
--additionalannouncablecidrs strings 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
--bulk-output when used with --file (bulk operation): prints results at the end as a list. default is printing results intermediately during the operation, which causes single entities to be printed in a row.
--description string the description of the network [optional]
-f, --file string filename of the create or update request in yaml format, or - for stdin.
Expand Down
Loading

0 comments on commit 765eb06

Please sign in to comment.