Skip to content

Commit

Permalink
Merge pull request openshift#707 from runcom/update-lock
Browse files Browse the repository at this point in the history
pkg/daemon: lock when checking if update is active
  • Loading branch information
openshift-merge-robot authored May 6, 2019
2 parents a2c37de + f17b95b commit 247b58e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/signal"
"path/filepath"
"strings"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -90,7 +91,8 @@ type Daemon struct {
kubeletHealthzEnabled bool
kubeletHealthzEndpoint string

updateActive bool
updateActive bool
updateActiveLock sync.Mutex

nodeWriter NodeWriter

Expand Down Expand Up @@ -481,7 +483,10 @@ func (dn *Daemon) InstallSignalHandler(signaled chan struct{}) {
for sig := range termChan {
switch sig {
case syscall.SIGTERM:
if dn.updateActive {
dn.updateActiveLock.Lock()
updateActive := dn.updateActive
dn.updateActiveLock.Unlock()
if updateActive {
glog.Info("Got SIGTERM, but actively updating")
} else {
close(signaled)
Expand Down
4 changes: 4 additions & 0 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,17 @@ func (dn *Daemon) logSystem(format string, a ...interface{}) {
}

func (dn *Daemon) catchIgnoreSIGTERM() {
dn.updateActiveLock.Lock()
defer dn.updateActiveLock.Unlock()
if dn.updateActive {
return
}
dn.updateActive = true
}

func (dn *Daemon) cancelSIGTERM() {
dn.updateActiveLock.Lock()
defer dn.updateActiveLock.Unlock()
if dn.updateActive {
dn.updateActive = false
}
Expand Down

0 comments on commit 247b58e

Please sign in to comment.