Skip to content

Commit

Permalink
fix(shutdown): make shutdown duration configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Clément Nussbaumer <[email protected]>
  • Loading branch information
clementnuss committed Dec 14, 2023
1 parent 3d6050c commit d7175a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/kubenurse/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Server struct {
// * KUBERNETES_SERVICE_PORT
// * KUBENURSE_NAMESPACE
// * KUBENURSE_NEIGHBOUR_FILTER
// * KUBENURSE_SHUTDOWN_DURATION
// * KUBENURSE_CHECK_API_SERVER_DIRECT
// * KUBENURSE_CHECK_API_SERVER_DNS
// * KUBENURSE_CHECK_ME_INGRESS
Expand Down Expand Up @@ -107,12 +108,23 @@ func New(ctx context.Context, k8s kubernetes.Interface) (*Server, error) {
return nil, err
}

shutdownDuration := 5 * time.Second
if v, ok := os.LookupEnv("KUBENURSE_SHUTDOWN_DURATION"); ok {

Check failure on line 112 in internal/kubenurse/server.go

View workflow job for this annotation

GitHub Actions / lint-go

if statements should only be cuddled with assignments used in the if statement itself (wsl)

Check failure on line 112 in internal/kubenurse/server.go

View workflow job for this annotation

GitHub Actions / lint-go

if statements should only be cuddled with assignments used in the if statement itself (wsl)
var err error
shutdownDuration, err = time.ParseDuration(v)

if err != nil {
return nil, err
}
}

chk.KubenurseIngressURL = os.Getenv("KUBENURSE_INGRESS_URL")
chk.KubenurseServiceURL = os.Getenv("KUBENURSE_SERVICE_URL")
chk.KubernetesServiceHost = os.Getenv("KUBERNETES_SERVICE_HOST")
chk.KubernetesServicePort = os.Getenv("KUBERNETES_SERVICE_PORT")
chk.KubenurseNamespace = os.Getenv("KUBENURSE_NAMESPACE")
chk.NeighbourFilter = os.Getenv("KUBENURSE_NEIGHBOUR_FILTER")
chk.ShutdownDuration = shutdownDuration

//nolint:goconst // No need to make "false" a constant in my opinion, readability is better like this.
chk.SkipCheckAPIServerDirect = os.Getenv("KUBENURSE_CHECK_API_SERVER_DIRECT") == "false"
Expand Down Expand Up @@ -198,11 +210,11 @@ func (s *Server) Shutdown(ctx context.Context) error {
s.ready = false
s.mu.Unlock()

// wait 5 second before actually shutting down the http/s server, as the updated
// wait before actually shutting down the http/s server, as the updated
// endpoints for the kubenurse service might not have propagated everywhere
// (other kubenurse/ingress controller) yet, which will lead to
// me_ingress or path errors in other pods
time.Sleep(5 * time.Second)
time.Sleep(s.checker.ShutdownDuration)

// stop the scheduled checker
s.checker.StopScheduled()
Expand Down
3 changes: 3 additions & 0 deletions internal/servicecheck/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type Checker struct {
SkipCheckMeIngress bool
SkipCheckMeService bool

// shutdownDuration defines the time during which kubenurse will wait before stopping
ShutdownDuration time.Duration

// Kubernetes API
KubernetesServiceHost string
KubernetesServicePort string
Expand Down

0 comments on commit d7175a5

Please sign in to comment.