Skip to content

Commit

Permalink
fix: make sure api server informer does not stop after setting change (
Browse files Browse the repository at this point in the history
…#9842)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
alexmt committed Jun 30, 2022
1 parent 71c1f54 commit ee7356a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
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())
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

0 comments on commit ee7356a

Please sign in to comment.