Fixed code quality issues.
parent
302cd7ce8d
commit
23fffea2ab
|
|
@ -1,13 +1,8 @@
|
|||
package views
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/derailed/k9s/internal/k8s"
|
||||
"github.com/derailed/k9s/internal/resource"
|
||||
"github.com/derailed/tview"
|
||||
"github.com/gdamore/tcell"
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
|
@ -53,66 +48,3 @@ func (v *deployView) showPods(app *appView, _, res, sel string) {
|
|||
|
||||
showPods(app, ns, l.String(), "", v.backCmd)
|
||||
}
|
||||
|
||||
func (v *deployView) scaleCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||
if !v.rowSelected() {
|
||||
return evt
|
||||
}
|
||||
|
||||
v.showScaleDialog(v.getList().GetName(), v.getSelectedItem())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *deployView) scale(selection string, replicas int) {
|
||||
ns, n := namespaced(selection)
|
||||
d := k8s.NewDeployment(v.app.conn())
|
||||
|
||||
err := d.Scale(ns, n, int32(replicas))
|
||||
if err != nil {
|
||||
v.app.flash().err(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *deployView) showScaleDialog(resourceType string, resourceName string) {
|
||||
f := tview.NewForm()
|
||||
f.SetItemPadding(0)
|
||||
f.SetButtonsAlign(tview.AlignCenter).
|
||||
SetButtonBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
|
||||
SetButtonTextColor(tview.Styles.PrimaryTextColor).
|
||||
SetLabelColor(tcell.ColorAqua).
|
||||
SetFieldTextColor(tcell.ColorOrange)
|
||||
|
||||
replicas := "1"
|
||||
f.AddInputField("Replicas:", replicas, 4, func(textToCheck string, lastChar rune) bool {
|
||||
_, err := strconv.Atoi(textToCheck)
|
||||
return err == nil
|
||||
}, func(changed string) {
|
||||
replicas = changed
|
||||
})
|
||||
|
||||
dismiss := func() {
|
||||
v.Pages.RemovePage(scaleDialogKey)
|
||||
}
|
||||
|
||||
f.AddButton("OK", func() {
|
||||
if val, err := strconv.Atoi(replicas); err == nil {
|
||||
v.scale(v.getSelectedItem(), val)
|
||||
} else {
|
||||
v.app.flash().err(err)
|
||||
}
|
||||
|
||||
dismiss()
|
||||
})
|
||||
|
||||
f.AddButton("Cancel", func() {
|
||||
dismiss()
|
||||
})
|
||||
|
||||
confirm := tview.NewModalForm("<Scale>", f)
|
||||
confirm.SetText(fmt.Sprintf("Scale %s %s", resourceType, resourceName))
|
||||
confirm.SetDoneFunc(func(int, string) {
|
||||
dismiss()
|
||||
})
|
||||
v.AddPage(scaleDialogKey, confirm, false, false)
|
||||
v.ShowPage(scaleDialogKey)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,13 +52,19 @@ func (v *scalableResourceView) scale(selection string, replicas int) {
|
|||
}
|
||||
|
||||
func (v *scalableResourceView) showScaleDialog(resourceType string, resourceName string) {
|
||||
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 := v.createScaleForm()
|
||||
|
||||
confirm := tview.NewModalForm("<Scale>", f)
|
||||
confirm.SetText(fmt.Sprintf("Scale %s %s", resourceType, resourceName))
|
||||
confirm.SetDoneFunc(func(int, string) {
|
||||
v.dismissScaleDialog()
|
||||
})
|
||||
v.AddPage(scaleDialogKey, confirm, false, false)
|
||||
v.ShowPage(scaleDialogKey)
|
||||
}
|
||||
|
||||
func (v *scalableResourceView) createScaleForm() *tview.Form {
|
||||
f := v.createStyledForm()
|
||||
|
||||
replicas := "1"
|
||||
f.AddInputField("Replicas:", replicas, 4, func(textToCheck string, lastChar rune) bool {
|
||||
|
|
@ -68,29 +74,38 @@ func (v *scalableResourceView) showScaleDialog(resourceType string, resourceName
|
|||
replicas = changed
|
||||
})
|
||||
|
||||
dismiss := func() {
|
||||
v.Pages.RemovePage(scaleDialogKey)
|
||||
f.AddButton("OK", func() {
|
||||
v.okSelected(replicas)
|
||||
})
|
||||
|
||||
f.AddButton("Cancel", func() {
|
||||
v.dismissScaleDialog()
|
||||
})
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
f.AddButton("OK", func() {
|
||||
func (v *scalableResourceView) createStyledForm() *tview.Form {
|
||||
f := tview.NewForm()
|
||||
f.SetItemPadding(0)
|
||||
f.SetButtonsAlign(tview.AlignCenter).
|
||||
SetButtonBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
|
||||
SetButtonTextColor(tview.Styles.PrimaryTextColor).
|
||||
SetLabelColor(tcell.ColorAqua).
|
||||
SetFieldTextColor(tcell.ColorOrange)
|
||||
return f
|
||||
}
|
||||
|
||||
func (v *scalableResourceView) okSelected(replicas string) {
|
||||
if val, err := strconv.Atoi(replicas); err == nil {
|
||||
v.scale(v.selectedItem, val)
|
||||
} else {
|
||||
v.app.flash().err(err)
|
||||
}
|
||||
|
||||
dismiss()
|
||||
})
|
||||
|
||||
f.AddButton("Cancel", func() {
|
||||
dismiss()
|
||||
})
|
||||
|
||||
confirm := tview.NewModalForm("<Scale>", f)
|
||||
confirm.SetText(fmt.Sprintf("Scale %s %s", resourceType, resourceName))
|
||||
confirm.SetDoneFunc(func(int, string) {
|
||||
dismiss()
|
||||
})
|
||||
v.AddPage(scaleDialogKey, confirm, false, false)
|
||||
v.ShowPage(scaleDialogKey)
|
||||
v.dismissScaleDialog()
|
||||
}
|
||||
|
||||
func (v *scalableResourceView) dismissScaleDialog() {
|
||||
v.Pages.RemovePage(scaleDialogKey)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue