Skip to content

Commit

Permalink
feat: introduce idiot-light
Browse files Browse the repository at this point in the history
And put node deletion challenge behind the idiot-light
  • Loading branch information
hansbogert committed Feb 17, 2024
1 parent e7d34ee commit 8cc59fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ K9s uses aliases to navigate most K8s resources.
memory: 100Mi
# Enable TTY
tty: true
# When enabled adds extra input field in which you have to confirm the deletion of a node
idiotLight: false
```
---
Expand Down
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ func initK9sFlags() {
"",
"Sets a path to a dir for a screen dumps",
)
rootCmd.Flags().BoolVar(
k9sFlags.IdiotLight,
"idiot-light",
false,
"Enable idiot light to warn the user for potentially destructive operations, e.g., delete a node",
)

rootCmd.Flags()
}

Expand Down
2 changes: 2 additions & 0 deletions internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Flags struct {
Write *bool
Crumbsless *bool
ScreenDumpDir *string
IdiotLight *bool
}

// NewFlags returns new configuration flags.
Expand All @@ -43,6 +44,7 @@ func NewFlags() *Flags {
Write: boolPtr(false),
Crumbsless: boolPtr(false),
ScreenDumpDir: strPtr(AppDumpsDir),
IdiotLight: boolPtr(false),
}
}

Expand Down
14 changes: 14 additions & 0 deletions internal/config/k9s.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ type K9s struct {
ImageScans ImageScans `json:"imageScans" yaml:"imageScans"`
Logger Logger `json:"logger" yaml:"logger"`
Thresholds Threshold `json:"thresholds" yaml:"thresholds"`
IdiotLight bool `json:"idiotLight" yaml:"idiotLight"`
manualRefreshRate int
manualHeadless *bool
manualLogoless *bool
manualCrumbsless *bool
manualReadOnly *bool
manualIdiotLight *bool
manualCommand *string
manualScreenDumpDir *string
dir *data.Dir
Expand Down Expand Up @@ -99,6 +101,7 @@ func (k *K9s) Merge(k1 *K9s) {
k.ShellPod = k1.ShellPod
k.Logger = k1.Logger
k.ImageScans = k1.ImageScans
k.IdiotLight = k1.IdiotLight
if k1.Thresholds != nil {
k.Thresholds = k1.Thresholds
}
Expand Down Expand Up @@ -249,9 +252,11 @@ func (k *K9s) Override(k9sFlags *Flags) {

k.manualHeadless = k9sFlags.Headless
k.manualLogoless = k9sFlags.Logoless
k.manualIdiotLight = k9sFlags.IdiotLight
k.manualCrumbsless = k9sFlags.Crumbsless
if k9sFlags.ReadOnly != nil && *k9sFlags.ReadOnly {
k.manualReadOnly = k9sFlags.ReadOnly

}
if k9sFlags.Write != nil && *k9sFlags.Write {
var false bool
Expand Down Expand Up @@ -310,6 +315,15 @@ func (k *K9s) IsReadOnly() bool {
return ro
}

func (k *K9s) HasIdiotLight() bool {
idiotLight := k.IdiotLight
if k.manualIdiotLight != nil {
idiotLight = *k.manualIdiotLight
}

return idiotLight
}

// Validate the current configuration.
func (k *K9s) Validate(c client.Connection, ks data.KubeSettings) {
if k.RefreshRate <= 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/view/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (b *Browser) deleteCmd(evt *tcell.EventKey) *tcell.EventKey {
}

challenge := ""
if b.GVR().R() == "nodes" {
if b.App().Config.K9s.HasIdiotLight() && b.GVR().R() == "nodes" {
challenge = "delete!"
}

Expand Down

0 comments on commit 8cc59fb

Please sign in to comment.