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