diff --git a/pkg/kubectl-argo-rollouts/cmd/get/get_rollout.go b/pkg/kubectl-argo-rollouts/cmd/get/get_rollout.go index 5b03f75566..0cb9709a9f 100644 --- a/pkg/kubectl-argo-rollouts/cmd/get/get_rollout.go +++ b/pkg/kubectl-argo-rollouts/cmd/get/get_rollout.go @@ -115,6 +115,7 @@ func (o *GetOptions) PrintRollout(roInfo *info.RolloutInfo) { fmt.Fprintf(o.Out, tableFormat, "Strategy:", roInfo.Strategy) if roInfo.Strategy == "Canary" { fmt.Fprintf(o.Out, tableFormat, " Step:", roInfo.Step) + o.PrintCanarySteps(roInfo) fmt.Fprintf(o.Out, tableFormat, " SetWeight:", roInfo.SetWeight) fmt.Fprintf(o.Out, tableFormat, " ActualWeight:", roInfo.ActualWeight) } @@ -235,3 +236,66 @@ func (o *GetOptions) PrintJob(w io.Writer, jobInfo info.JobInfo, prefix string, name := o.colorizeStatus(jobInfo.Name, jobInfo.Status) fmt.Fprintf(w, "%s%s %s\t%s\t%s %s\t%s\t%v\n", prefix, IconJob, name, "Job", o.colorize(jobInfo.Icon), jobInfo.Status, jobInfo.Age(), "") } + +func (o *GetOptions) setCanarySteps(roInfo *info.RolloutInfo) ([]string, int) { + newSteps := make([]string, 0) + currentIndex := 0 + for k, step := range roInfo.Steps { + stepIndex := fmt.Sprintf("[%v]", k+1) + if strings.Contains(step, "[*]") { + tempStep := strings.Replace(step, "[*]", "", -1) + newSteps = append(newSteps, fmt.Sprintf("%s%s", stepIndex, o.colorizeStatus(tempStep, info.InfoTagStable))) + currentIndex = k + } else { + newSteps = append(newSteps, fmt.Sprintf("%s%s", stepIndex, step)) + } + } + return newSteps, currentIndex +} + +const ( + stepsMsg = " Steps:" + maxPrintStep = 3 +) + +func (o *GetOptions) PrintCanarySteps(roInfo *info.RolloutInfo) { + newSteps, currentIndex := o.setCanarySteps(roInfo) + maxSteps := len(newSteps) - 1 + if maxSteps <= maxPrintStep { + fmt.Fprintf(o.Out, tableFormat, stepsMsg, strings.Join(newSteps, " -> ")) + return + } + + centre := currentIndex + if currentIndex == 0 { + if maxSteps > maxPrintStep { + fmt.Fprintf(o.Out, tableFormat, stepsMsg, strings.Join(newSteps[0:3], " -> ")+" ...") + } else { + fmt.Fprintf(o.Out, tableFormat, stepsMsg, strings.Join(newSteps[0:maxSteps+1], " -> ")) + } + return + } + if currentIndex >= maxSteps { + fmt.Fprintf(o.Out, tableFormat, stepsMsg, "... "+strings.Join(newSteps[maxSteps-2:maxSteps+1], " -> ")) + return + } + + printSteps := make([]string, 0) + if centre+1 <= maxSteps { + if currentIndex >= 1 { + printSteps = append(printSteps, "... ") + printSteps = append(printSteps, newSteps[centre-1:centre+2]...) + printSteps = append(printSteps, " ...") + fmt.Fprintf(o.Out, tableFormat, stepsMsg, strings.Join(printSteps, " -> ")) + } else { + printSteps = append(printSteps, newSteps[0:centre+3]...) + printSteps = append(printSteps, " ...") + fmt.Fprintf(o.Out, tableFormat, stepsMsg, strings.Join(printSteps, " -> ")) + } + return + } + if centre+1 >= maxSteps { + fmt.Fprintf(o.Out, tableFormat, stepsMsg, "... "+strings.Join(newSteps[centre-2:maxSteps+1], " -> ")) + return + } +} diff --git a/pkg/kubectl-argo-rollouts/cmd/get/get_test.go b/pkg/kubectl-argo-rollouts/cmd/get/get_test.go index 1e4abd429c..d2072851e0 100644 --- a/pkg/kubectl-argo-rollouts/cmd/get/get_test.go +++ b/pkg/kubectl-argo-rollouts/cmd/get/get_test.go @@ -262,6 +262,7 @@ Status: ✖ Degraded Message: ProgressDeadlineExceeded: ReplicaSet "canary-demo-65fb5ffc84" has timed out progressing. Strategy: Canary Step: 0/8 + Steps: [1]setWeight:20 -> [2]pause:∞ -> [3]setWeight:40 ... SetWeight: 20 ActualWeight: 0 Images: argoproj/rollouts-demo:does-not-exist (canary) @@ -310,6 +311,7 @@ Status: ✖ Degraded Message: ProgressDeadlineExceeded: ReplicaSet "rollout-experiment-analysis-6f646bf7b7" has timed out progressing. Strategy: Canary Step: 1/2 + Steps: [1]setWeight:25 SetWeight: 25 ActualWeight: 25 Images: argoproj/rollouts-demo:blue (stable) @@ -390,6 +392,7 @@ Status: ◌ Progressing Message: more replicas need to be updated Strategy: Canary Step: 0/1 + Steps: SetWeight: 0 ActualWeight: 0 Images: argoproj/rollouts-demo:blue (Σ:canary-preview) @@ -439,6 +442,7 @@ Status: ✖ Degraded Message: InvalidSpec: The Rollout "rollout-invalid" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"doesnt-match"}: `+"`selector`"+` does not match template `+"`labels`"+` Strategy: Canary Step: + Steps: SetWeight: 100 ActualWeight: 100 Replicas: @@ -472,6 +476,7 @@ Status: ✖ Degraded Message: RolloutAborted: metric "web" assessed Failed due to failed (1) > failureLimit (0) Strategy: Canary Step: 0/2 + Steps: [1]setWeight:10 -> [2]pause:∞ SetWeight: 0 ActualWeight: 0 Images: argoproj/rollouts-demo:blue (stable) diff --git a/pkg/kubectl-argo-rollouts/info/info.go b/pkg/kubectl-argo-rollouts/info/info.go index 563b4faef7..23d854ac04 100644 --- a/pkg/kubectl-argo-rollouts/info/info.go +++ b/pkg/kubectl-argo-rollouts/info/info.go @@ -20,6 +20,7 @@ const ( IconBad = "✖" IconPaused = "॥" IconNeutral = "•" + IconAlways = "∞" ) const ( diff --git a/pkg/kubectl-argo-rollouts/info/rollout_info.go b/pkg/kubectl-argo-rollouts/info/rollout_info.go index 900e9f8cd6..a5f208b03c 100644 --- a/pkg/kubectl-argo-rollouts/info/rollout_info.go +++ b/pkg/kubectl-argo-rollouts/info/rollout_info.go @@ -22,6 +22,7 @@ type RolloutInfo struct { Icon string Strategy string Step string + Steps []string SetWeight string ActualWeight string @@ -80,6 +81,8 @@ func NewRolloutInfo( roInfo.ActualWeight = roInfo.SetWeight } } + + roInfo.Steps = RolloutStepsDisplay(ro) } else if ro.Spec.Strategy.BlueGreen != nil { roInfo.Strategy = "BlueGreen" } @@ -326,3 +329,35 @@ func (r *RolloutInfo) AnalysisRunsByRevision(rev int) []AnalysisRunInfo { } return runs } + +func addSteps(stepsIndex int, index *int32, stepsData *[]string, steps v1alpha1.CanaryStep, ro *v1alpha1.Rollout) { + currentIcon := "" + if int32(stepsIndex)+1 == *index && *index <= int32(len(ro.Spec.Strategy.Canary.Steps)) { + currentIcon = "[*]" + } + if steps.SetWeight != nil { + *stepsData = append(*stepsData, fmt.Sprintf("%vsetWeight:%v", currentIcon, *steps.SetWeight)) + } + if steps.Pause != nil { + pause := fmt.Sprintf("%vpause:%s", currentIcon, IconAlways) + if steps.Pause.Duration != nil { + pause = fmt.Sprintf("%vpause:%v", currentIcon, steps.Pause.Duration) + } + *stepsData = append(*stepsData, pause) + } + +} + +func RolloutStepsDisplay(ro *v1alpha1.Rollout) []string { + stepsData := make([]string, 0) + _, index := replicasetutil.GetCurrentCanaryStep(ro) + if index == nil { + return stepsData + } + for k, steps := range ro.Spec.Strategy.Canary.Steps { + if steps.SetWeight != nil || steps.Pause != nil { + addSteps(k, index, &stepsData, steps, ro) + } + } + return stepsData +}