added confirm dialog for Michael's rollout restart feature
parent
f6f52fb762
commit
c97ccc06dd
|
|
@ -44,19 +44,19 @@ changelog:
|
|||
- "^test:"
|
||||
|
||||
# Homebrew
|
||||
brew:
|
||||
name: k9s
|
||||
github:
|
||||
owner: derailed
|
||||
name: k9s-homebrew-tap
|
||||
commit_author:
|
||||
name: derailed
|
||||
email: fernand@imhotep.io
|
||||
folder: Formula
|
||||
homepage: https://k9ss.io
|
||||
description: Kubernetes CLI To Manage Your Clusters In Style!
|
||||
test: |
|
||||
system "k9s version"
|
||||
brews:
|
||||
- name: k9s
|
||||
github:
|
||||
owner: derailed
|
||||
name: k9s-homebrew-tap
|
||||
commit_author:
|
||||
name: derailed
|
||||
email: fernand@imhotep.io
|
||||
folder: Formula
|
||||
homepage: https://k9ss.io
|
||||
description: Kubernetes CLI To Manage Your Clusters In Style!
|
||||
test: |
|
||||
system "k9s version"
|
||||
|
||||
# Snapcraft
|
||||
# snapcraft:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package dialog
|
||||
|
||||
import (
|
||||
"github.com/derailed/tview"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
const confirmKey = "confirm"
|
||||
|
||||
type (
|
||||
confirmFunc func()
|
||||
)
|
||||
|
||||
// ShowConfirm pops a confirmation dialog.
|
||||
func ShowConfirm(pages *tview.Pages, title, msg string, ack confirmFunc, cancel cancelFunc) {
|
||||
f := tview.NewForm()
|
||||
f.SetItemPadding(0)
|
||||
f.SetButtonsAlign(tview.AlignCenter).
|
||||
SetButtonBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
|
||||
SetButtonTextColor(tview.Styles.PrimaryTextColor).
|
||||
SetLabelColor(tcell.ColorAqua).
|
||||
SetFieldTextColor(tcell.ColorOrange)
|
||||
f.AddButton("Cancel", func() {
|
||||
dismissConfirm(pages)
|
||||
cancel()
|
||||
})
|
||||
f.AddButton("OK", func() {
|
||||
ack()
|
||||
dismissConfirm(pages)
|
||||
cancel()
|
||||
})
|
||||
|
||||
modal := tview.NewModalForm(title, f)
|
||||
modal.SetText(msg)
|
||||
modal.SetDoneFunc(func(int, string) {
|
||||
dismissConfirm(pages)
|
||||
cancel()
|
||||
})
|
||||
pages.AddPage(confirmKey, modal, false, false)
|
||||
pages.ShowPage(confirmKey)
|
||||
|
||||
// pages.AddAndSwitchToPage(confirmKey, modal, false)
|
||||
}
|
||||
|
||||
func dismissConfirm(pages *tview.Pages) {
|
||||
pages.RemovePage(confirmKey)
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package dialog
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/derailed/tview"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfirmDialog(t *testing.T) {
|
||||
a := tview.NewApplication()
|
||||
p := tview.NewPages()
|
||||
a.SetRoot(p, false)
|
||||
|
||||
ackFunc := func() {
|
||||
assert.True(t, true)
|
||||
}
|
||||
caFunc := func() {
|
||||
assert.True(t, true)
|
||||
}
|
||||
ShowConfirm(p, "Blee", "Yo", ackFunc, caFunc)
|
||||
|
||||
d := p.GetPrimitive(confirmKey).(*tview.ModalForm)
|
||||
assert.NotNil(t, d)
|
||||
|
||||
dismissConfirm(p)
|
||||
assert.Nil(t, p.GetPrimitive(confirmKey))
|
||||
}
|
||||
|
|
@ -52,7 +52,6 @@ func (v *masterDetail) init(ctx context.Context, ns string) {
|
|||
|
||||
func (v *masterDetail) setExtraActionsFn(f ui.ActionsFunc) {
|
||||
v.extraActionsFn = f
|
||||
// f(v.actions)
|
||||
}
|
||||
|
||||
// Protocol...
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/derailed/k9s/internal/resource"
|
||||
"github.com/derailed/k9s/internal/ui"
|
||||
"github.com/derailed/k9s/internal/ui/dialog"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
|
|
@ -31,22 +32,29 @@ func (v *restartableResourceView) restartCmd(evt *tcell.EventKey) *tcell.EventKe
|
|||
return evt
|
||||
}
|
||||
|
||||
v.restartRollout(v.masterPage().GetSelectedItem())
|
||||
sel := v.masterPage().GetSelectedItem()
|
||||
v.stopUpdates()
|
||||
defer v.restartUpdates()
|
||||
msg := "Please confirm rollout restart for " + sel
|
||||
dialog.ShowConfirm(v.Pages, "<Confirm Restart>", msg, func() {
|
||||
if err := v.restartRollout(sel); err != nil {
|
||||
v.app.Flash().Err(err)
|
||||
} else {
|
||||
v.app.Flash().Infof("Rollout restart in progress for `%s...", sel)
|
||||
}
|
||||
}, func() {
|
||||
v.showMaster()
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *restartableResourceView) restartRollout(selection string) {
|
||||
ns, n := namespaced(selection)
|
||||
|
||||
func (v *restartableResourceView) restartRollout(selection string) error {
|
||||
r, ok := v.list.Resource().(resource.Restartable)
|
||||
if !ok {
|
||||
v.app.Flash().Err(errors.New("resource is not of type resource.Restartable"))
|
||||
return
|
||||
return errors.New("resource is not of type resource.Restartable")
|
||||
}
|
||||
ns, n := namespaced(selection)
|
||||
|
||||
err := r.Restart(ns, n)
|
||||
if err != nil {
|
||||
v.app.Flash().Err(err)
|
||||
}
|
||||
v.app.Flash().Info("Restarted Rollout")
|
||||
return r.Restart(ns, n)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue