Skip to content

Commit

Permalink
running golangci-lint on ui/pods package
Browse files Browse the repository at this point in the history
Signed-off-by: Navid Yaghoobi <[email protected]>
  • Loading branch information
navidys committed Nov 26, 2023
1 parent 9bad433 commit f99918f
Show file tree
Hide file tree
Showing 9 changed files with 469 additions and 123 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ run:
- ui/dialogs
- ui/images
- ui/networks
- ui/pods
linters:
enable-all: true
disable:
Expand Down
107 changes: 92 additions & 15 deletions ui/pods/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog/log"
)

func (p *Pods) runCommand(cmd string) {
func (p *Pods) runCommand(cmd string) { //nolint:cyclop
switch cmd {
case "create":
p.createDialog.Display()
Expand All @@ -20,7 +20,7 @@ func (p *Pods) runCommand(cmd string) {
p.kill()
case "pause":
p.pause()
case "prune":
case "prune": //nolint:goconst
p.confirmDialog.SetTitle("podman pod prune")
p.confirmData = "prune"
p.confirmDialog.SetText("Are you sure you want to remove all stopped pods ?")
Expand Down Expand Up @@ -51,207 +51,277 @@ func (p *Pods) displayError(title string, err error) {

func (p *Pods) stats() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to perform stats command"))
p.displayError("", errNoPodStat)

return
}

podOptions := p.getAllItemsForStats()

p.statsDialog.SetPodsOptions(podOptions)
p.statsDialog.Display()
}

func (p *Pods) create() {
podSpec := p.createDialog.GetPodSpec()

p.progressDialog.SetTitle("pod create in progress")
p.progressDialog.Display()

createFunc := func() {
err := ppods.Create(podSpec)

p.progressDialog.Hide()

if err != nil {
p.displayError("POD CREATE ERROR", err)

return
}
}

go createFunc()
}

func (p *Pods) inspect() {
podID, podName := p.getSelectedItem()
if podID == "" {
p.displayError("", fmt.Errorf("there is no pod to display inspect"))
p.displayError("", errNoPodInspect)

return
}

data, err := ppods.Inspect(podID)
if err != nil {
title := fmt.Sprintf("POD (%s) INSPECT ERROR", podID)

p.displayError(title, err)

return
}

headerLabel := fmt.Sprintf("%12s (%s)", podID, podName)

p.messageDialog.SetTitle("podman pod inspect")
p.messageDialog.SetText(dialogs.MessagePodInfo, headerLabel, data)
p.messageDialog.Display()
}

func (p *Pods) kill() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to kill"))
p.displayError("", errNoPodKill)

return
}

p.progressDialog.SetTitle("pod kill in progress")
p.progressDialog.Display()

kill := func(id string) {
err := ppods.Kill(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) KILL ERROR", p.selectedID)

p.displayError(title, err)

return
}
}

go kill(p.selectedID)
}

func (p *Pods) pause() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to pause"))
p.displayError("", errNoPodPause)

return
}

p.progressDialog.SetTitle("pod pause in progress")
p.progressDialog.Display()

pause := func(id string) {
err := ppods.Pause(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) PAUSE ERROR", p.selectedID)

p.displayError(title, err)

return
}
}

go pause(p.selectedID)
}

func (p *Pods) prune() {
p.progressDialog.SetTitle("pod purne in progress")
p.progressDialog.Display()

unpause := func() {
errData, err := ppods.Prune()

p.progressDialog.Hide()

if err != nil {
p.displayError("PODS PRUNE ERROR", err)

return
}

if len(errData) > 0 {
errMessages := fmt.Errorf("%v", errData)
errMessages := fmt.Errorf("%w %v", errPodPrune, errData)

p.displayError("PODS PRUNE ERROR", errMessages)
}

}

go unpause()
}

func (p *Pods) restart() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to restart"))
p.displayError("", errNoPodRestart)

return
}

p.progressDialog.SetTitle("pod restart in progress")
p.progressDialog.Display()

restart := func(id string) {
err := ppods.Restart(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) RESTART ERROR", p.selectedID)
p.displayError(title, err)

return
}
}

go restart(p.selectedID)
}

func (p *Pods) rm() {
podID, podName := p.getSelectedItem()
if podID == "" {
p.displayError("", fmt.Errorf("there is no pod to remove"))
p.displayError("", errNoPodRemove)

return
}

p.confirmDialog.SetTitle("podman pod rm")

p.confirmData = "rm"
bgColor := style.GetColorHex(style.DialogBorderColor)
fgColor := style.GetColorHex(style.DialogFgColor)
podItem := fmt.Sprintf("[%s:%s:b]POD ID:[:-:-] %s (%s)", fgColor, bgColor, podID, podName)

description := fmt.Sprintf("%s\n\nAre you sure you want to remove the selected pod?", podItem)

p.confirmDialog.SetText(description)
p.confirmDialog.Display()
}

func (p *Pods) remove() {
p.progressDialog.SetTitle("pod remove in progress")
p.progressDialog.Display()

remove := func(id string) {
errData, err := ppods.Remove(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) REMOVE ERROR", p.selectedID)
p.displayError(title, err)

return
}

if len(errData) > 0 {
title := fmt.Sprintf("POD (%s) REMOVE ERROR", p.selectedID)
p.displayError(title, fmt.Errorf("%v", errData))
p.displayError(title, fmt.Errorf("%w %v", errPodRemove, errData))
}
}

go remove(p.selectedID)
}

func (p *Pods) start() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to start"))
p.displayError("", errNoPodStart)

return
}

p.progressDialog.SetTitle("pod start in progress")
p.progressDialog.Display()

start := func(id string) {
err := ppods.Start(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) START ERROR", p.selectedID)
p.displayError(title, err)

return
}
}

go start(p.selectedID)
}

func (p *Pods) stop() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to stop"))
p.displayError("", errNoPodStop)

return
}

p.progressDialog.SetTitle("pod stop in progress")
p.progressDialog.Display()

stop := func(id string) {
err := ppods.Stop(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) STOP ERROR", p.selectedID)
p.displayError(title, err)

return
}
}

go stop(p.selectedID)
}

func (p *Pods) top() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to display top"))
p.displayError("", errNoPodTop)

return
}

data, err := ppods.Top(p.selectedID)
if err != nil {
title := fmt.Sprintf("POD (%s) TOP ERROR", p.selectedID)
p.displayError(title, err)

return
}

Expand All @@ -262,19 +332,26 @@ func (p *Pods) top() {

func (p *Pods) unpause() {
if p.selectedID == "" {
p.displayError("", fmt.Errorf("there is no pod to unpause"))
p.displayError("", errNoPodUnpause)

return
}

p.progressDialog.SetTitle("pod unpause in progress")
p.progressDialog.Display()

unpause := func(id string) {
err := ppods.Unpause(id)

p.progressDialog.Hide()

if err != nil {
title := fmt.Sprintf("POD (%s) UNPAUSE ERROR", p.selectedID)
p.displayError(title, err)

return
}
}

go unpause(p.selectedID)
}
12 changes: 8 additions & 4 deletions ui/pods/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import (
"github.com/rs/zerolog/log"
)

// UpdateData retrieves pods list data
// UpdateData retrieves pods list data.
func (pods *Pods) UpdateData() {
podList, err := ppods.List()
if err != nil {
log.Error().Msgf("view: pods update %v", err)
pods.errorDialog.SetText(fmt.Sprintf("%v", err))
pods.errorDialog.Display()

return
}

pods.podsList.mu.Lock()
pods.podsList.report = podList
pods.podsList.mu.Unlock()
Expand All @@ -29,15 +31,17 @@ func (pods *Pods) getData() []*entities.ListPodsReport {
pods.podsList.mu.Lock()
data := pods.podsList.report
pods.podsList.mu.Unlock()

return data
}

// ClearData clears table data
func (pods *Pods) ClearData() {
// ClearData clears table data.
func (pods *Pods) ClearData() { //nolint:stylecheck
pods.podsList.mu.Lock()
pods.podsList.report = nil
pods.podsList.mu.Unlock()
pods.table.Clear()

expand := 1
fgColor := style.PageHeaderFgColor
bgColor := style.PageHeaderBgColor
Expand All @@ -51,6 +55,6 @@ func (pods *Pods) ClearData() {
SetAlign(tview.AlignLeft).
SetSelectable(false))
}
pods.table.SetTitle(fmt.Sprintf("[::b]%s[0]", strings.ToUpper(pods.title)))

pods.table.SetTitle(fmt.Sprintf("[::b]%s[0]", strings.ToUpper(pods.title)))
}
Loading

0 comments on commit f99918f

Please sign in to comment.