Skip to content

Commit

Permalink
feat: Implement graceful shutdown in application-controller (#19465)
Browse files Browse the repository at this point in the history
* Implement graceful shutdown in argocd-application-controller

Signed-off-by: leehosu <hosu4549@gmail.com>

* Implement code to pass waitGroup to Run function

Signed-off-by: leehosu <hosu4549@gmail.com>

* Add retuen nil

Signed-off-by: leehosu <hosu4549@gmail.com>

* Add log for lean shutdown

Signed-off-by: leehosu <hosu4549@gmail.com>

* collect e2e coverage from app-controller

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* Remove select {}

Signed-off-by: leehosu <hosu4549@gmail.com>

* Add ctx.done() about application-controller

Signed-off-by: leehosu <hosu4549@gmail.com>

* simplify

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: leehosu <hosu4549@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
leehosu and crenshaw-dev authored Aug 11, 2024
1 parent bdb2608 commit dad6fa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ jobs:
name: test-results
path: test-results
- name: combine-go-coverage
# We generate coverage reports for all Argo CD components, but only the applicationset-controller and
# repo-server report contain coverage data. The other components currently don't shut down gracefully, so no
# coverage data is produced. Once those components are fixed, we can add references to their coverage output
# directories.
# We generate coverage reports for all Argo CD components, but only the applicationset-controller,
# app-controller, and repo-server report contain coverage data. The other components currently don't shut down
# gracefully, so no coverage data is produced. Once those components are fixed, we can add references to their
# coverage output directories.
run: |
go tool covdata percent -i=test-results,e2e-code-coverage/applicationset-controller,e2e-code-coverage/repo-server -o test-results/full-coverage.out
go tool covdata percent -i=test-results,e2e-code-coverage/applicationset-controller,e2e-code-coverage/repo-server,e2e-code-coverage/app-controller -o test-results/full-coverage.out
- name: Upload code coverage information to codecov.io
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"fmt"
"math"
"os"
"os/signal"
"syscall"
"time"

"github.com/argoproj/pkg/stats"
Expand Down Expand Up @@ -188,10 +191,22 @@ func NewCommand() *cobra.Command {
defer closeTracer()
}

// Graceful shutdown code
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
go func() {
s := <-sigCh
log.Printf("got signal %v, attempting graceful shutdown", s)
cancel()
}()

go appController.Run(ctx, statusProcessors, operationProcessors)

// Wait forever
select {}
<-ctx.Done()

log.Println("clean shutdown")

return nil
},
}

Expand Down

0 comments on commit dad6fa2

Please sign in to comment.