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: make sure api server informer does not stop after setting change #9842

Merged
merged 1 commit into from Jun 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/argocd-server/commands/argocd_server.go
Expand Up @@ -160,6 +160,7 @@ func NewCommand() *cobra.Command {
stats.StartStatsTicker(10 * time.Minute)
stats.RegisterHeapDumper("memprofile")
argocd := server.NewServer(context.Background(), argoCDOpts)
argocd.Init(context.Background())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really your problem, but just noticed we call context.Background() three times in same function and you might consider consolidating to one ctx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem is fairly pervasive throughout cmd/.

I may look at this a little bit since it's an easy opportunity to get to know the codebase more.

lns, err := argocd.Listen()
errors.CheckError(err)
for {
Expand Down
1 change: 1 addition & 0 deletions cmd/argocd/commands/headless/headless.go
Expand Up @@ -215,6 +215,7 @@ func StartLocalServer(clientOpts *apiclient.ClientOptions, ctxStr string, port *
ListenHost: *address,
RepoClientset: &forwardRepoClientset{namespace: namespace, context: ctxStr},
})
srv.Init(ctx)

lns, err := srv.Listen()
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions server/server.go
Expand Up @@ -362,6 +362,12 @@ func (a *ArgoCDServer) Listen() (*Listeners, error) {
return &Listeners{Main: mainLn, Metrics: metricsLn, GatewayConn: conn}, nil
}

// Init starts informers used by the API server
func (a *ArgoCDServer) Init(ctx context.Context) {
go a.projInformer.Run(ctx.Done())
go a.appInformer.Run(ctx.Done())
}

// Run runs the API Server
// We use k8s.io/code-generator/cmd/go-to-protobuf to generate the .proto files from the API types.
// k8s.io/ go-to-protobuf uses protoc-gen-gogo, which comes from gogo/protobuf (a fork of
Expand Down Expand Up @@ -429,9 +435,6 @@ func (a *ArgoCDServer) Run(ctx context.Context, listeners *Listeners) {
log.Infof("argocd %s serving on port %d (url: %s, tls: %v, namespace: %s, sso: %v)",
common.GetVersion(), a.ListenPort, a.settings.URL, a.useTLS(), a.Namespace, a.settings.IsSSOConfigured())

go a.projInformer.Run(ctx.Done())
go a.appInformer.Run(ctx.Done())

go func() { a.checkServeErr("grpcS", grpcS.Serve(grpcL)) }()
go func() { a.checkServeErr("httpS", httpS.Serve(httpL)) }()
if a.useTLS() {
Expand Down
4 changes: 4 additions & 0 deletions server/server_norace_test.go
Expand Up @@ -36,6 +36,7 @@ func TestUserAgent(t *testing.T) {
defer cancelInformer()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s.Init(ctx)
go s.Run(ctx, lns)
defer func() { time.Sleep(3 * time.Second) }()

Expand Down Expand Up @@ -101,6 +102,7 @@ func Test_StaticHeaders(t *testing.T) {
defer cancelInformer()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s.Init(ctx)
go s.Run(ctx, lns)
defer func() { time.Sleep(3 * time.Second) }()

Expand Down Expand Up @@ -129,6 +131,7 @@ func Test_StaticHeaders(t *testing.T) {
assert.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s.Init(ctx)
go s.Run(ctx, lns)
defer func() { time.Sleep(3 * time.Second) }()

Expand Down Expand Up @@ -157,6 +160,7 @@ func Test_StaticHeaders(t *testing.T) {
assert.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s.Init(ctx)
go s.Run(ctx, lns)
defer func() { time.Sleep(3 * time.Second) }()

Expand Down
3 changes: 2 additions & 1 deletion server/server_test.go
Expand Up @@ -66,7 +66,8 @@ func fakeServer() (*ArgoCDServer, func()) {
),
RedisClient: redis,
}
return NewServer(context.Background(), argoCDOpts), closer
srv := NewServer(context.Background(), argoCDOpts)
return srv, closer
}

func TestEnforceProjectToken(t *testing.T) {
Expand Down