Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/admin/v2/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func AddCmds(cmd *cobra.Command, c *config.Config) {
adminCmd.AddCommand(newAuditCmd(c))
adminCmd.AddCommand(newComponentCmd(c))
adminCmd.AddCommand(newFilesystemCmd(c))
adminCmd.AddCommand(newHousekeepingCmd(c))
adminCmd.AddCommand(newImageCmd(c))
adminCmd.AddCommand(newIPCmd(c))
adminCmd.AddCommand(newMachineCmd(c))
Expand Down
85 changes: 85 additions & 0 deletions cmd/admin/v2/housekeepeing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package v2

import (
"context"

adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2"
"github.com/metal-stack/cli/cmd/config"
"github.com/spf13/cobra"
)

type housekeeping struct {
c *config.Config
}

func newHousekeepingCmd(c *config.Config) *cobra.Command {
w := &housekeeping{
c: c,
}

housekeepingCmd := &cobra.Command{
Use: "housekeeping",
Short: "execute housekeeping commands",
Long: "housekeeping commands are usually as cronjobs in the control-plane",
}

machineLivelinessCmd := &cobra.Command{
Use: "machine-liveliness",
Short: "execute machine liveliness housekeeping",
Long: "updates the liveleness of all machines, only the modified machines are returned",
RunE: func(cmd *cobra.Command, args []string) error {
return w.machineLiveliness(cmd.Context())
},
}

machineVPNConnectedCmd := &cobra.Command{
Use: "machine-vpn-connected",
Short: "execute machine vpn connected housekeeping",
Long: "updates the vpn connection details of machines which have vpn configured, only the modified machines are returned",
RunE: func(cmd *cobra.Command, args []string) error {
return w.machineVPNConnected(cmd.Context())
},
}

machineResurrectCmd := &cobra.Command{
Use: "machine-resurrect",
Short: "execute machine resurrect housekeeping",
Long: "tries to resurrect machines which are not allocated but not in waiting state by forcing a restart, only machines where a restart was triggered are returned",
RunE: func(cmd *cobra.Command, args []string) error {
return w.machineResurrect(cmd.Context())
},
}

housekeepingCmd.AddCommand(machineLivelinessCmd)
housekeepingCmd.AddCommand(machineVPNConnectedCmd)
housekeepingCmd.AddCommand(machineResurrectCmd)

return housekeepingCmd
}

func (h *housekeeping) machineLiveliness(ctx context.Context) (err error) {
result, err := h.c.Client.Adminv2().Housekeeping().MachineLiveliness(ctx, &adminv2.HousekeepingServiceMachineLivelinessRequest{})
if err != nil {
return err
}

return h.c.DescribePrinter.Print(result)
}

func (h *housekeeping) machineVPNConnected(ctx context.Context) (err error) {
result, err := h.c.Client.Adminv2().Housekeeping().MachineVPNConnected(ctx, &adminv2.HousekeepingServiceMachineVPNConnectedRequest{})
if err != nil {
return err
}

return h.c.ListPrinter.Print(result.ModifiedMachines)
}

func (h *housekeeping) machineResurrect(ctx context.Context) (err error) {
result, err := h.c.Client.Adminv2().Housekeeping().MachineResurrect(ctx, &adminv2.HousekeepingServiceMachineResurrectRequest{})
if err != nil {
return err
}

return h.c.ListPrinter.Print(result.ModifiedMachines)
}
5 changes: 5 additions & 0 deletions cmd/tableprinters/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (t *TablePrinter) ToHeaderAndRows(data any, wide bool) ([]string, [][]strin
case []*apiv2.MachineBMCDetails:
return t.MachineBMCTable(d, wide)

case *adminv2.MachineWithLiveliness:
return t.HousekeepingMachineLivelinessTable(pointer.WrapInSlice(d), wide)
case []*adminv2.MachineWithLiveliness:
return t.HousekeepingMachineLivelinessTable(d, wide)

case *apiv2.IP:
return t.IPTable(pointer.WrapInSlice(d), wide)
case []*apiv2.IP:
Expand Down
29 changes: 29 additions & 0 deletions cmd/tableprinters/housekeeping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tableprinters

import (
"github.com/metal-stack/api/go/enum"
adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2"
)

func (t *TablePrinter) HousekeepingMachineLivelinessTable(data []*adminv2.MachineWithLiveliness, wide bool) ([]string, [][]string, error) {
var (
rows [][]string
header = []string{"Machine", "Liveliness"}
)

for _, ms := range data {
var lvl string
lvlString, err := enum.GetStringValue(ms.Liveliness)
if err != nil {
lvl = "unknown"
} else {
lvl = *lvlString
}

rows = append(rows, []string{ms.Uuid, lvl})
}

t.t.DisableAutoWrap(false)

return header, rows, nil
}
1 change: 1 addition & 0 deletions docs/admin/metalctlv2_admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ these commands utilize the admin api, which can only be accessed by metal-stack
* [metalctlv2 admin audit](metalctlv2_admin_audit.md) - manage audit entities
* [metalctlv2 admin component](metalctlv2_admin_component.md) - manage component entities
* [metalctlv2 admin filesystemlayout](metalctlv2_admin_filesystemlayout.md) - manage filesystemlayout entities
* [metalctlv2 admin housekeeping](metalctlv2_admin_housekeeping.md) - execute housekeeping commands
* [metalctlv2 admin image](metalctlv2_admin_image.md) - manage image entities
* [metalctlv2 admin ip](metalctlv2_admin_ip.md) - manage ip entities
* [metalctlv2 admin machine](metalctlv2_admin_machine.md) - manage machine entities
Expand Down
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ require (
github.com/fatih/color v1.19.0
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/metal-stack/api v0.9.0
github.com/metal-stack/api v0.10.0
github.com/metal-stack/metal-console v0.8.2
github.com/metal-stack/metal-lib v0.26.4
github.com/metal-stack/v v1.0.3
github.com/spf13/afero v1.15.0
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.12.1
google.golang.org/grpc v1.84.0
google.golang.org/grpc v1.85.0
google.golang.org/protobuf v1.36.12
sigs.k8s.io/yaml v1.6.0
)

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.2 // indirect
buf.build/go/protovalidate v1.4.0 // indirect
buf.build/go/protoyaml v0.7.0 // indirect
cel.dev/cel-go v0.32.0 // indirect
buf.build/go/protoyaml v0.8.0 // indirect
cel.dev/cel-go v0.33.2 // indirect
cel.dev/expr v0.25.3 // indirect
connectrpc.com/connect/v2 v2.0.0 // indirect
connectrpc.com/connect/v2 v2.0.2 // indirect
filippo.io/edwards25519 v1.2.0 // indirect
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e // indirect
Expand All @@ -42,21 +42,21 @@ require (
github.com/creachadair/msync v0.10.1 // indirect
github.com/dblohm7/wingoes v0.0.0-20260526185140-fb298caac7ca // indirect
github.com/fsnotify/fsnotify v1.10.1 // indirect
github.com/fxamacker/cbor/v2 v2.9.6 // indirect
github.com/fxamacker/cbor/v2 v2.10.0 // indirect
github.com/gaissmai/bart v0.30.0 // indirect
github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 // indirect
github.com/go-openapi/errors v0.22.9 // indirect
github.com/go-openapi/strfmt v0.27.4 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/goccy/go-json v0.11.2 // indirect
github.com/goccy/go-json v0.12.0 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/godbus/dbus/v5 v5.2.4 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/huin/goupnp v1.3.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jsimonetti/rtnetlink v1.4.2 // indirect
github.com/klauspost/compress v1.20.3 // indirect
Expand Down Expand Up @@ -89,27 +89,27 @@ require (
github.com/tailscale/web-client-prebuilt v0.0.0-20260917222731-e0ed2d0d0fea // indirect
github.com/tailscale/wireguard-go v0.0.0-20260928213032-417aef361226 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
go.yaml.in/yaml/v2 v2.4.5 // indirect
go.yaml.in/yaml/v3 v3.0.6 // indirect
go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect
go4.org/netipx v0.0.0-20260823151212-3075585bcbeb // indirect
golang.org/x/crypto v0.58.0 // indirect
golang.org/x/exp v0.0.0-20261014143641-f0251eb4aa3e // indirect
golang.org/x/net v0.61.0 // indirect
golang.org/x/net v0.62.0 // indirect
golang.org/x/oauth2 v0.37.0 // indirect
golang.org/x/sync v0.24.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/term v0.47.0 // indirect
golang.org/x/text v0.43.0 // indirect
golang.org/x/time v0.16.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v1.0.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261019180522-ce908d29299b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261019180522-ce908d29299b // indirect
golang.zx2c4.com/wireguard/windows v1.1.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gvisor.dev/gvisor v0.0.0-20260915211658-a6f909f08a72 // indirect
k8s.io/apimachinery v0.37.1 // indirect
sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5 // indirect
tailscale.com v1.104.2 // indirect
tailscale.com v1.104.5 // indirect
)
Loading
Loading