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: viewcontroller gorouting leak in status and get subcommand #1584

Merged
merged 2 commits into from
Oct 17, 2021
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
5 changes: 4 additions & 1 deletion pkg/kubectl-argo-rollouts/cmd/get/get_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"

"github.com/argoproj/argo-rollouts/pkg/apiclient/rollout"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/cmd/signals"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/info"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/options"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/viewcontroller"
Expand Down Expand Up @@ -44,7 +45,9 @@ func NewCmdGetRollout(o *options.ArgoRolloutsOptions) *cobra.Command {
}
name := args[0]
controller := viewcontroller.NewRolloutViewController(o.Namespace(), name, getOptions.KubeClientset(), getOptions.RolloutsClientset())
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
signals.SetupSignalHandler(cancel)
controller.Start(ctx)

ri, err := controller.GetRolloutInfo()
Expand Down
19 changes: 19 additions & 0 deletions pkg/kubectl-argo-rollouts/cmd/signals/signal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package signals

import (
"context"
"os"
"os/signal"
"syscall"
)

func SetupSignalHandler(cancel context.CancelFunc) {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
cancel()
<-c
os.Exit(1) // second signal. Exit directly.
}()
}
7 changes: 4 additions & 3 deletions pkg/kubectl-argo-rollouts/cmd/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/argoproj/argo-rollouts/pkg/apiclient/rollout"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/cmd/signals"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/options"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/viewcontroller"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -50,6 +51,7 @@ func NewCmdStatus(o *options.ArgoRolloutsOptions) *cobra.Command {
controller := viewcontroller.NewRolloutViewController(o.Namespace(), name, statusOptions.KubeClientset(), statusOptions.RolloutsClientset())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
signals.SetupSignalHandler(cancel)
controller.Start(ctx)

ri, err := controller.GetRolloutInfo()
Expand All @@ -61,7 +63,6 @@ func NewCmdStatus(o *options.ArgoRolloutsOptions) *cobra.Command {
fmt.Fprintln(o.Out, ri.Status)
} else {
rolloutUpdates := make(chan *rollout.RolloutInfo)
defer close(rolloutUpdates)
controller.RegisterCallback(func(roInfo *rollout.RolloutInfo) {
rolloutUpdates <- roInfo
})
Expand All @@ -72,7 +73,7 @@ func NewCmdStatus(o *options.ArgoRolloutsOptions) *cobra.Command {
if err != nil {
return err
}

close(rolloutUpdates)
if finalRi.Status == "Degraded" {
return fmt.Errorf("The rollout is in a degraded state with message: %s", finalRi.Message)
} else if finalRi.Status != "Healthy" {
Expand All @@ -88,7 +89,7 @@ func NewCmdStatus(o *options.ArgoRolloutsOptions) *cobra.Command {
return cmd
}

func (o *StatusOptions) WatchStatus(stopCh <-chan struct{}, rolloutUpdates chan *rollout.RolloutInfo) string {
func (o *StatusOptions) WatchStatus(stopCh <-chan struct{}, rolloutUpdates <-chan *rollout.RolloutInfo) string {
timeout := make(chan bool)
var roInfo *rollout.RolloutInfo
var preventFlicker time.Time
Expand Down