diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 476e31cf..f151efc8 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -31,7 +31,7 @@ jobs: cache: false - name: Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: args: --build-tags integration -p bugs -p unused --timeout=5m diff --git a/cmd/ip.go b/cmd/ip.go index 18a4ebb2..e6c9ff03 100644 --- a/cmd/ip.go +++ b/cmd/ip.go @@ -115,6 +115,7 @@ func (c ipCmd) List() ([]*models.V1IPResponse, error) { return nil, err } + // actually filtered client side because server side would require a reql filter for addressfamilies if viper.IsSet("addressfamily") { af := viper.GetString("addressfamily") var result []*models.V1IPResponse diff --git a/cmd/sorters/ip.go b/cmd/sorters/ip.go index dd958887..5bafb0fc 100644 --- a/cmd/sorters/ip.go +++ b/cmd/sorters/ip.go @@ -2,6 +2,7 @@ package sorters import ( "net/netip" + "time" "github.com/metal-stack/metal-go/api/models" "github.com/metal-stack/metal-lib/pkg/multisort" @@ -32,5 +33,8 @@ func IPSorter() *multisort.Sorter[*models.V1IPResponse] { "type": func(a, b *models.V1IPResponse, descending bool) multisort.CompareResult { return multisort.Compare(p.SafeDeref(a.Type), p.SafeDeref(b.Type), descending) }, + "age": func(a, b *models.V1IPResponse, descending bool) multisort.CompareResult { + return multisort.Compare(time.Time(a.Created).Unix(), time.Time(b.Created).Unix(), descending) + }, }, multisort.Keys{{ID: "ipaddress"}}) } diff --git a/cmd/switch.go b/cmd/switch.go index d9fb46f5..58927825 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -11,6 +11,7 @@ import ( "github.com/metal-stack/metal-go/api/models" "github.com/metal-stack/metal-lib/pkg/genericcli" "github.com/metal-stack/metal-lib/pkg/genericcli/printers" + "github.com/metal-stack/metal-lib/pkg/pointer" "github.com/metal-stack/metalctl/cmd/sorters" "github.com/metal-stack/metalctl/cmd/tableprinters" "github.com/spf13/cobra" @@ -59,6 +60,9 @@ func newSwitchCmd(c *config) *cobra.Command { genericcli.Must(cmd.RegisterFlagCompletionFunc("os-vendor", c.comp.SwitchOSVendorListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("os-version", c.comp.SwitchOSVersionListCompletion)) }, + DeleteCmdMutateFn: func(cmd *cobra.Command) { + cmd.Flags().Bool("force", false, "forcefully delete the switch accepting the risk that it still has machines connected to it") + }, } switchDetailCmd := &cobra.Command{ @@ -222,7 +226,7 @@ func (c switchCmd) List() ([]*models.V1SwitchResponse, error) { } func (c switchCmd) Delete(id string) (*models.V1SwitchResponse, error) { - resp, err := c.client.SwitchOperations().DeleteSwitch(switch_operations.NewDeleteSwitchParams().WithID(id), nil) + resp, err := c.client.SwitchOperations().DeleteSwitch(switch_operations.NewDeleteSwitchParams().WithID(id).WithForce(pointer.Pointer(viper.GetBool("force"))), nil) if err != nil { return nil, err } diff --git a/cmd/switch_test.go b/cmd/switch_test.go index 41934bca..da16d9ba 100644 --- a/cmd/switch_test.go +++ b/cmd/switch_test.go @@ -239,7 +239,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST S }, mocks: &client.MetalMockFns{ SwitchOperations: func(mock *mock.Mock) { - mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID)), nil).Return(&switch_operations.DeleteSwitchOK{ + mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID).WithForce(pointer.Pointer(false))), nil).Return(&switch_operations.DeleteSwitchOK{ Payload: switch1, }, nil) }, @@ -387,7 +387,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST S }, mocks: &client.MetalMockFns{ SwitchOperations: func(mock *mock.Mock) { - mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID)), nil).Return(&switch_operations.DeleteSwitchOK{ + mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID).WithForce(pointer.Pointer(false))), nil).Return(&switch_operations.DeleteSwitchOK{ Payload: switch1, }, nil) }, diff --git a/docs/metalctl_network_ip_list.md b/docs/metalctl_network_ip_list.md index 4aa96424..52ea88ff 100644 --- a/docs/metalctl_network_ip_list.md +++ b/docs/metalctl_network_ip_list.md @@ -17,7 +17,7 @@ metalctl network ip list [flags] --network string network to filter [optional] --prefix string prefix to filter [optional] --project string project to filter [optional] - --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: description|id|ipaddress|name|network|type + --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: age|description|id|ipaddress|name|network|type --tags strings tags to filter [optional] --type string type to filter [optional] ``` diff --git a/docs/metalctl_switch_delete.md b/docs/metalctl_switch_delete.md index 791b19dd..0d4b62d0 100644 --- a/docs/metalctl_switch_delete.md +++ b/docs/metalctl_switch_delete.md @@ -22,6 +22,7 @@ metalctl switch delete [flags] the file can also contain multiple documents and perform a bulk operation. + --force forcefully delete the switch accepting the risk that it still has machines connected to it -h, --help help for delete --skip-security-prompts skips security prompt for bulk operations --timestamps when used with --file (bulk operation): prints timestamps in-between the operations