This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new 4441f43d [operator] Completion of progress status (#519)
4441f43d is described below

commit 4441f43d5c73226d7e2b4467579fcb2037047511
Author: mfordjody <[email protected]>
AuthorDate: Mon Dec 2 17:39:34 2024 +0800

    [operator] Completion of progress status (#519)
---
 operator/pkg/util/progress/progress.go | 86 +++++++++++++++++++++++++---------
 1 file changed, 64 insertions(+), 22 deletions(-)

diff --git a/operator/pkg/util/progress/progress.go 
b/operator/pkg/util/progress/progress.go
index c23f0191..a268483f 100644
--- a/operator/pkg/util/progress/progress.go
+++ b/operator/pkg/util/progress/progress.go
@@ -19,14 +19,6 @@ const (
 
 const inProgress = `{{ yellow (cycle . "-" "-" " ") }}`
 
-type ManifestInfo struct {
-       report   func()
-       err      string
-       waiting  []string
-       finished bool
-       mu       sync.Mutex
-}
-
 type Info struct {
        components map[string]*ManifestInfo
        state      InstallState
@@ -42,13 +34,13 @@ func NewInfo() *Info {
        }
 }
 
-func (info *Info) reportProgress(componentName string) func() {
+func (i *Info) reportProgress(componentName string) func() {
        return func() {
                compName := component.Name(componentName)
                cliName := component.UserFacingCompName(compName)
-               info.mu.Lock()
-               defer info.mu.Unlock()
-               comp := info.components[componentName]
+               i.mu.Lock()
+               defer i.mu.Unlock()
+               comp := i.components[componentName]
                comp.mu.Lock()
                finished := comp.finished
                compErr := comp.err
@@ -59,27 +51,43 @@ func (info *Info) reportProgress(componentName string) 
func() {
                }
                if finished || compErr != "" {
                        if finished {
-                               info.SetMessage(fmt.Sprintf(`{{ green "✔" }} %s 
install Completed %s`, cliName, successIcon), true)
+                               i.SetMessage(fmt.Sprintf(`{{ green "✔" }} %s 
install Completed %s`, cliName, successIcon), true)
                        } else {
-                               info.SetMessage(fmt.Sprintf(`{{ read "✘" }} %s 
encountered an error: %s`, cliName, compErr), true)
+                               i.SetMessage(fmt.Sprintf(`{{ read "✘" }} %s 
encountered an error: %s`, cliName, compErr), true)
                        }
-                       delete(info.components, componentName)
-                       info.bar = createBar()
+                       delete(i.components, componentName)
+                       i.bar = createBar()
                        return
                }
        }
 }
 
-func (info *Info) SetMessage(status string, finish bool) {
-       if !info.bar.GetBool(pb.Terminal) && status == info.template {
+func (i *Info) SetMessage(status string, finish bool) {
+       if !i.bar.GetBool(pb.Terminal) && status == i.template {
                return
        }
-       info.template = status
-       info.bar.SetTemplateString(info.template)
+       i.template = status
+       i.bar.SetTemplateString(i.template)
        if finish {
-               info.bar.Finish()
+               i.bar.Finish()
+       }
+       i.bar.Write()
+}
+
+func (i *Info) SetState(state InstallState) {
+       i.mu.Lock()
+       defer i.mu.Unlock()
+       i.state = state
+       switch i.state {
+       case StatePruning:
+               i.SetMessage(inProgress+`Pruning removed resources`, false)
+       case StateComplete:
+               // TODO Install provides the command for copying and running.
+               i.SetMessage(`{{ green "✔" }} Installation complete`, true)
+       case StateUninstallComplete:
+               // TODO Uninstall provides a one-click command to delete CRDs.
+               i.SetMessage(`{{ green "✔" }} Uninstallation complete`, true)
        }
-       info.bar.Write()
 }
 
 func createBar() *pb.ProgressBar {
@@ -95,3 +103,37 @@ func createBar() *pb.ProgressBar {
        }
        return bar
 }
+
+type ManifestInfo struct {
+       report   func()
+       err      string
+       waiting  []string
+       finished bool
+       mu       sync.Mutex
+}
+
+func (mi *ManifestInfo) reportProgress() {
+       if mi == nil {
+               return
+       }
+}
+
+func (mi *ManifestInfo) reportFinished() {
+       if mi == nil {
+               return
+       }
+       mi.mu.Lock()
+       mi.finished = true
+       mi.mu.Unlock()
+       mi.report()
+}
+
+func (mi *ManifestInfo) reportError(err string) {
+       if mi == nil {
+               return
+       }
+       mi.mu.Lock()
+       mi.err = err
+       mi.mu.Unlock()
+       mi.report()
+}

Reply via email to