From 8d732d3fa1e9ee555761e5598b9fb887ebe0a4dd Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Thu, 30 Jun 2022 14:04:40 -0700 Subject: [PATCH] fix: make sure api server informer does not stop after setting change Signed-off-by: Alexander Matyushentsev --- cmd/argocd-server/commands/argocd_server.go | 1 + cmd/argocd/commands/headless/headless.go | 1 + server/server.go | 9 ++++++--- server/server_norace_test.go | 4 ++++ server/server_test.go | 3 ++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/argocd-server/commands/argocd_server.go b/cmd/argocd-server/commands/argocd_server.go index 2c7b20a36688..877a24978b68 100644 --- a/cmd/argocd-server/commands/argocd_server.go +++ b/cmd/argocd-server/commands/argocd_server.go @@ -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()) lns, err := argocd.Listen() errors.CheckError(err) for { diff --git a/cmd/argocd/commands/headless/headless.go b/cmd/argocd/commands/headless/headless.go index 3f532d60cc43..e19b954de699 100644 --- a/cmd/argocd/commands/headless/headless.go +++ b/cmd/argocd/commands/headless/headless.go @@ -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 { diff --git a/server/server.go b/server/server.go index 28485841bb33..0c90d498ef38 100644 --- a/server/server.go +++ b/server/server.go @@ -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 @@ -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() { diff --git a/server/server_norace_test.go b/server/server_norace_test.go index 737186dd44c9..defa7f035f03 100644 --- a/server/server_norace_test.go +++ b/server/server_norace_test.go @@ -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) }() @@ -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) }() @@ -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) }() @@ -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) }() diff --git a/server/server_test.go b/server/server_test.go index e698ec4b7b44..51f1b05cd1ab 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -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) {