Skip to content

Commit

Permalink
keep the process active to avoid restarting and running again (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvizvary authored Apr 9, 2021
1 parent fe8d72a commit 764df21
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"spot-termination-handler/pkg/terminate"
"strconv"
"syscall"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -122,7 +124,7 @@ func main() {
gracePeriodEnv, gracePeriodSeconds,
))

dh := drain.Handler{
dh := &drain.Handler{
Client: clientSet,
Logger: logger,
PodName: podName,
Expand All @@ -134,12 +136,19 @@ func main() {

select {
case <-sigusr:
dh.Drain(node)
drainNode(log, dh, node)
case <-terminate.WaitCh():
dh.Drain(node)
drainNode(log, dh, node)
case <-shutdown:
}
log.Info("shutting down spot-termination-handler")
}

func drainNode(log *zap.SugaredLogger, dh *drain.Handler, node *v1.Node) {
dh.Drain(node)
log.Info("my work is done here. Going to sleep")
if !devMode {
time.Sleep(3 * time.Minute)
}
}

func getKubeConfig(log *zap.SugaredLogger) (*rest.Config, error) {
Expand Down

0 comments on commit 764df21

Please sign in to comment.