Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt commands to new provisioning FSM #144

Merged
merged 43 commits into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
96f936a
Introduce generic applier.
Gerrit91 Jul 7, 2022
2838d6e
Docs.
Gerrit91 Jul 7, 2022
5410471
Add empty file test.
Gerrit91 Jul 7, 2022
f2f1a86
Adding another test.
Gerrit91 Jul 7, 2022
5d348fd
Use generic CLI from metal-lib.
Gerrit91 Jul 7, 2022
afd17c1
Shorten a bit.
Gerrit91 Jul 7, 2022
5060724
Nicify.
Gerrit91 Jul 7, 2022
be433d6
Introduce command wrapper.
Gerrit91 Jul 7, 2022
5f63905
Updates.
Gerrit91 Jul 8, 2022
2e6fee9
Updates.
Gerrit91 Jul 8, 2022
7b99766
Smaller.
Gerrit91 Jul 8, 2022
befb9fc
Do it for image as well.
Gerrit91 Jul 8, 2022
b77377a
Do for partitions.
Gerrit91 Jul 8, 2022
f51f3f4
Allow overriding yaml printer.
Gerrit91 Jul 8, 2022
56107ee
Default command generation.
Gerrit91 Jul 8, 2022
146ec23
Do for FSLs.
Gerrit91 Jul 8, 2022
a0f906c
Do for switches.
Gerrit91 Jul 8, 2022
df603f7
Do for firewalls.
Gerrit91 Jul 8, 2022
d85e7b3
Updates.
Gerrit91 Jul 11, 2022
b04eec2
Apply patterns for rest of the entities.
Gerrit91 Jul 11, 2022
09a568b
Replace printers.
Gerrit91 Jul 11, 2022
63ddcbe
Improvements.
Gerrit91 Jul 11, 2022
fdc1a21
Fix apply.
Gerrit91 Jul 11, 2022
2de8efb
Remove unused code.
Gerrit91 Jul 11, 2022
2469ee4
Make autowrap table set available.
Gerrit91 Jul 11, 2022
9acffef
Fixes.
Gerrit91 Jul 11, 2022
58a662f
Completion client usage and sorters are private.
Gerrit91 Jul 12, 2022
c54f118
Move to metal-lib.
Gerrit91 Jul 12, 2022
6d23178
Add missing shorthand flags for file.
Gerrit91 Jul 18, 2022
e435db3
Fix metalctl machine ipmi.
Gerrit91 Jul 18, 2022
95bd511
Replace driver where it's easy.
Gerrit91 Jul 19, 2022
6d8d666
Update metal-lib.
Gerrit91 Jul 20, 2022
24c9c31
Update metal-lib.
Gerrit91 Jul 20, 2022
bcef623
Update metal-lib.
Gerrit91 Jul 20, 2022
f0cf97d
Fix command tree init (early cobra flags not working).
Gerrit91 Jul 22, 2022
f72dd2b
Naming.
Gerrit91 Jul 22, 2022
757d853
Fix machine logs and improve displayed time.
Gerrit91 Jul 27, 2022
54fe914
Adaptions for new provisioning FSM.
Gerrit91 Jul 27, 2022
eacfa70
Adapt to latest API.
Gerrit91 Aug 9, 2022
31bb2e0
Merge branch 'master'
Aug 10, 2022
e953265
Better help text.
Gerrit91 Aug 10, 2022
3c64eba
Single new line is enough.
Gerrit91 Aug 10, 2022
d790866
Nice time format for machine logs.
Gerrit91 Aug 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 52 additions & 10 deletions cmd/machine.go
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"strings"
"time"

"fmt"

Expand All @@ -19,6 +20,7 @@ import (
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metalctl/cmd/sorters"
"github.com/metal-stack/metalctl/cmd/tableprinters"
"github.com/metal-stack/metalctl/pkg/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -293,6 +295,7 @@ In case the machine did not register properly a direct ipmi console access is av
machineIpmiCmd := &cobra.Command{
Use: "ipmi [<machine ID>]",
Short: `display ipmi details of the machine, if no machine ID is given all ipmi addresses are returned.`,
Long: `display ipmi details of the machine, if no machine ID is given all ipmi addresses are returned.` + "\n" + api.EmojiHelpText(),
RunE: func(cmd *cobra.Command, args []string) error {
return w.machineIpmi(args)
},
Expand All @@ -301,6 +304,7 @@ In case the machine did not register properly a direct ipmi console access is av
machineIssuesCmd := &cobra.Command{
Use: "issues",
Short: `display machines which are in a potential bad state`,
Long: `display machines which are in a potential bad state` + "\n" + api.EmojiHelpText(),
RunE: func(cmd *cobra.Command, args []string) error {
return w.machineIssues()
},
Expand Down Expand Up @@ -351,6 +355,7 @@ In case the machine did not register properly a direct ipmi console access is av
c := c
must(cmds.listCmd.RegisterFlagCompletionFunc(c.flagName, c.f))
}
cmds.listCmd.Long = cmds.listCmd.Short + "\n" + api.EmojiHelpText()

machineIpmiCmd.Flags().AddFlagSet(cmds.listCmd.Flags())

Expand Down Expand Up @@ -1080,7 +1085,25 @@ func (c *machineCmd) machineLogs(args []string) error {
return err
}

return newPrinterFromCLI().Print(pointer.SafeDeref(resp.Events).Log)
err = newPrinterFromCLI().Print(pointer.SafeDeref(resp.Events).Log)
if err != nil {
return err
}

if pointer.SafeDeref(resp.Events).LastErrorEvent != nil {
timeSince := time.Since(time.Time(resp.Events.LastErrorEvent.Time))
if timeSince > tableprinters.LastErrorEventRelevant {
return nil
}

fmt.Println()
fmt.Printf("Recent last error (%s ago):\n", timeSince.String())
fmt.Println()

return newPrinterFromCLI().Print(resp.Events.LastErrorEvent)
}

return nil
}

func (c *machineCmd) machineConsole(args []string) error {
Expand Down Expand Up @@ -1204,6 +1227,11 @@ func (c *machineCmd) machineIssues() error {
return err
}

err = sorters.MachineIPMISort(resp.Payload)
if err != nil {
return err
}

var (
only = viper.GetStringSlice("only")
omit = viper.GetStringSlice("omit")
Expand Down Expand Up @@ -1240,15 +1268,22 @@ func (c *machineCmd) machineIssues() error {
return
}

mWithIssues, ok := res[*m.ID]
if !ok {
mWithIssues = api.MachineWithIssues{
var mWithIssues *api.MachineWithIssues
for _, machine := range res {
machine := machine
if pointer.SafeDeref(m.ID) == pointer.SafeDeref(machine.Machine.ID) {
mWithIssues = &machine
break
}
}
if mWithIssues == nil {
mWithIssues = &api.MachineWithIssues{
Machine: *m,
}
res = append(res, *mWithIssues)
}

mWithIssues.Issues = append(mWithIssues.Issues, issue)
res[*m.ID] = mWithIssues
}
)

Expand Down Expand Up @@ -1276,17 +1311,24 @@ func (c *machineCmd) machineIssues() error {
addIssue(m, api.IssueLivelinessNotAvailable)
}

if m.Allocation == nil && len(m.Events.Log) > 0 && *m.Events.Log[0].Event == "Phoned Home" {
if pointer.SafeDeref(pointer.SafeDeref(m.Events).FailedMachineReclaim) {
addIssue(m, api.IssueFailedMachineReclaim)
}

if m.Events.IncompleteProvisioningCycles != nil &&
*m.Events.IncompleteProvisioningCycles != "" &&
*m.Events.IncompleteProvisioningCycles != "0" {
if pointer.SafeDeref(pointer.SafeDeref(m.Events).CrashLoop) {
if m.Events != nil && len(m.Events.Log) > 0 && *m.Events.Log[0].Event == "Waiting" {
// Machine which are waiting are not considered to have issues
} else {
addIssue(m, api.IssueIncompleteCycles)
addIssue(m, api.IssueCrashLoop)
}
}

if pointer.SafeDeref(m.Events).LastErrorEvent != nil {
timeSince := time.Since(time.Time(m.Events.LastErrorEvent.Time))
if timeSince < tableprinters.LastErrorEventRelevant {
issue := api.IssueLastEventError
issue.Description = fmt.Sprintf("%s (%s ago)", issue.Description, timeSince.String())
addIssue(m, issue)
}
}

Expand Down
12 changes: 4 additions & 8 deletions cmd/tableprinters/common.go
Expand Up @@ -9,14 +9,10 @@ import (
)

const (
bark = "🚧"
circle = "↻"
dot = "●"
exclamationMark = "❗"
lock = "🔒"
nbr = " "
question = "❓"
skull = "💀"
LastErrorEventRelevant = 7 * 24 * time.Hour

dot = "●"
nbr = " "
)

func depth(path string) uint {
Expand Down