Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin panic while watching progress #1796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions pkg/kubectl-argo-rollouts/cmd/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewCmdStatus(o *options.ArgoRolloutsOptions) *cobra.Command {
})
go controller.Run(ctx)
statusOptions.WatchStatus(ctx.Done(), rolloutUpdates)
close(rolloutUpdates)
defer close(rolloutUpdates)

// the final rollout info after timeout or reach Healthy or Degraded status
ri, err = controller.GetRolloutInfo()
Expand All @@ -98,7 +98,7 @@ func NewCmdStatus(o *options.ArgoRolloutsOptions) *cobra.Command {
func (o *StatusOptions) WatchStatus(stopCh <-chan struct{}, rolloutUpdates <-chan *rollout.RolloutInfo) string {
timeout := make(chan bool)
var roInfo *rollout.RolloutInfo
var preventFlicker time.Time
var prevMessage string

if o.Timeout != 0 {
go func() {
Expand All @@ -107,16 +107,25 @@ func (o *StatusOptions) WatchStatus(stopCh <-chan struct{}, rolloutUpdates <-cha
}()
}

printStatus := func(roInfo rollout.RolloutInfo) {
message := roInfo.Status
if roInfo.Message != "" {
message = fmt.Sprintf("%s - %s", roInfo.Status, roInfo.Message)
}
if message != prevMessage {
fmt.Fprintln(o.Out, message)
prevMessage = message
}
}

for {
select {
case roInfo = <-rolloutUpdates:
if roInfo != nil && roInfo.Status == "Healthy" || roInfo.Status == "Degraded" {
fmt.Fprintln(o.Out, roInfo.Status)
return roInfo.Status
}
if roInfo != nil && time.Now().After(preventFlicker.Add(200*time.Millisecond)) {
fmt.Fprintf(o.Out, "%s - %s\n", roInfo.Status, roInfo.Message)
preventFlicker = time.Now()
if roInfo != nil {
printStatus(*roInfo)
if roInfo.Status == "Healthy" || roInfo.Status == "Degraded" {
return roInfo.Status
}
}
case <-stopCh:
return ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl-argo-rollouts/cmd/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestWatchAbortedRollout(t *testing.T) {
assert.Error(t, err)
stdout := o.Out.(*bytes.Buffer).String()
stderr := o.ErrOut.(*bytes.Buffer).String()
assert.Equal(t, "Degraded\n", stdout)
assert.Equal(t, "Degraded - RolloutAborted: metric \"web\" assessed Failed due to failed (1) > failureLimit (0)\n", stdout)
assert.Equal(t, "Error: The rollout is in a degraded state with message: RolloutAborted: metric \"web\" assessed Failed due to failed (1) > failureLimit (0)\n", stderr)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/kubectl-argo-rollouts/viewcontroller/viewcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (c *viewController) Run(ctx context.Context) error {
}
}, time.Second, ctx.Done())
<-ctx.Done()
c.DeregisterCallbacks()
return nil
}

Expand All @@ -168,6 +169,10 @@ func (c *viewController) processNextWorkItem() bool {
return true
}

func (c *viewController) DeregisterCallbacks() {
c.callbacks = nil
}

func (c *RolloutViewController) GetRolloutInfo() (*rollout.RolloutInfo, error) {
ro, err := c.rolloutLister.Get(c.name)
if err != nil {
Expand Down