Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into new-partition-capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Sep 13, 2024
2 parents 631fa02 + 4b7b53c commit 2127872
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 232 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 <info@metal-stack.io>"
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
9 changes: 5 additions & 4 deletions cmd/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/metal-stack/metal-go/api/client/health"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-go/test/client"
"github.com/metal-stack/metal-lib/pkg/healthstatus"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metal-lib/pkg/testcommon"
"github.com/metal-stack/metal-lib/rest"
Expand All @@ -23,14 +24,14 @@ func Test_HealthCmd(t *testing.T) {
Health: func(mock *mock.Mock) {
mock.On("Health", testcommon.MatchIgnoreContext(t, health.NewHealthParams()), nil).Return(&health.HealthOK{
Payload: &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusHealthy)),
Status: pointer.Pointer(string(healthstatus.HealthStatusHealthy)),
Message: pointer.Pointer("ok"),
},
}, nil)
},
},
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
Message: "ok",
Services: nil,
},
Expand All @@ -44,14 +45,14 @@ func Test_HealthCmd(t *testing.T) {
Health: func(mock *mock.Mock) {
mock.On("Health", testcommon.MatchIgnoreContext(t, health.NewHealthParams()), nil).Return(nil, &health.HealthInternalServerError{
Payload: &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusUnhealthy)),
Status: pointer.Pointer(string(healthstatus.HealthStatusUnhealthy)),
Message: pointer.Pointer("error"),
},
})
},
},
want: &rest.HealthResponse{
Status: rest.HealthStatusUnhealthy,
Status: healthstatus.HealthStatusUnhealthy,
Message: "error",
Services: nil,
},
Expand Down
96 changes: 53 additions & 43 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("additional-announcable-cidrs", []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("additional-announcable-cidrs", []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 @@ -208,7 +210,7 @@ func (c networkCmd) Create(rq *models.V1NetworkCreateRequest) (*models.V1Network
}

func (c networkCmd) Update(rq *models.V1NetworkUpdateRequest) (*models.V1NetworkResponse, error) {
resp, err := c.client.Network().UpdateNetwork(network.NewUpdateNetworkParams().WithBody(rq), nil)
resp, err := c.client.Network().UpdateNetwork(network.NewUpdateNetworkParams().WithBody(rq).WithForce(pointer.Pointer(viper.GetBool(forceFlag))), nil)
if err != nil {
return nil, err
}
Expand All @@ -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("additional-announcable-cidrs"),
}, 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("additional-announcable-cidrs") {
additionalCidrs = viper.GetStringSlice("additional-announcable-cidrs")
}
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
38 changes: 22 additions & 16 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 @@ -156,7 +159,7 @@ nw2 network-2
mocks: &client.MetalMockFns{
Network: func(mock *mock.Mock) {
mock.On("CreateNetwork", testcommon.MatchIgnoreContext(t, network.NewCreateNetworkParams().WithBody(networkResponseToCreate(network1))), nil).Return(nil, &network.CreateNetworkConflict{}).Once()
mock.On("UpdateNetwork", testcommon.MatchIgnoreContext(t, network.NewUpdateNetworkParams().WithBody(networkResponseToUpdate(network1))), nil).Return(&network.UpdateNetworkOK{
mock.On("UpdateNetwork", testcommon.MatchIgnoreContext(t, network.NewUpdateNetworkParams().WithBody(networkResponseToUpdate(network1)).WithForce(pointer.Pointer(false))), nil).Return(&network.UpdateNetworkOK{
Payload: network1,
}, nil)
mock.On("CreateNetwork", testcommon.MatchIgnoreContext(t, network.NewCreateNetworkParams().WithBody(networkResponseToCreate(network2))), nil).Return(&network.CreateNetworkCreated{
Expand Down Expand Up @@ -198,7 +201,7 @@ nw2 network-2
},
mocks: &client.MetalMockFns{
Network: func(mock *mock.Mock) {
mock.On("UpdateNetwork", testcommon.MatchIgnoreContext(t, network.NewUpdateNetworkParams().WithBody(networkResponseToUpdate(network1))), nil).Return(&network.UpdateNetworkOK{
mock.On("UpdateNetwork", testcommon.MatchIgnoreContext(t, network.NewUpdateNetworkParams().WithBody(networkResponseToUpdate(network1)).WithForce(pointer.Pointer(false))), nil).Return(&network.UpdateNetworkOK{
Payload: network1,
}, nil)
},
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),
"--additional-announcable-cidrs", "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,
"--additional-announcable-cidrs", "10.240.0.0/12",
}
assertExhaustiveArgs(t, args, commonExcludedFileArgs()...)
return args
Expand All @@ -337,14 +342,15 @@ 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,
})), nil).Return(&network.UpdateNetworkOK{
ID: network1.ID,
Name: network1.Name,
Description: network1.Description,
Destinationprefixes: network1.Destinationprefixes,
Prefixes: network1.Prefixes,
Labels: network1.Labels,
Shared: network1.Shared,
AdditionalAnnouncableCIDRs: network1.AdditionalAnnouncableCIDRs,
}).WithForce(pointer.Pointer(false))), nil).Return(&network.UpdateNetworkOK{
Payload: network1,
}, nil)
},
Expand Down
13 changes: 7 additions & 6 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/healthstatus"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metal-lib/rest"
"github.com/spf13/afero"
Expand Down Expand Up @@ -38,7 +39,7 @@ func Test_BasicRootCmdStuff(t *testing.T) {
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write(mustMarshal(t, &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusHealthy)),
Status: pointer.Pointer(string(healthstatus.HealthStatusHealthy)),
}))
if err != nil {
t.Errorf("error writing response: %s", err)
Expand All @@ -60,7 +61,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -76,7 +77,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -86,7 +87,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -98,7 +99,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -109,7 +110,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tableprinters/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (t *TablePrinter) PartitionCapacityTable(data []*models.V1PartitionCapacity
}

footerRow := ([]string{
"Σ",
"Total",
"",
fmt.Sprintf("%d", allocatedCount),
fmt.Sprintf("%d", freeCount),
Expand Down
Loading

0 comments on commit 2127872

Please sign in to comment.