Skip to content

Commit

Permalink
bootstrap: API shows up, start it again
Browse files Browse the repository at this point in the history
  • Loading branch information
celebdor committed Oct 1, 2020
1 parent 53b17b6 commit 6858d3c
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions pkg/monitor/dynkeepalived.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const (
bootstrapApiFailuresThreshold int = 4
)

type APIState uint8

const (
stopped APIState = iota
started APIState = iota
)

var (
gBootstrapIP string
)
Expand Down Expand Up @@ -143,7 +150,7 @@ func isModeUpdateNeeded(cfgPath string) (bool, modeUpdateInfo) {
return updateRequired, desiredModeInfo
}

func handleBootstrapStopKeepalived(kubeconfigPath string, bootstrapStopKeepalived chan bool) {
func handleBootstrapStopKeepalived(kubeconfigPath string, bootstrapStopKeepalived chan APIState) {
consecutiveErr := 0

/* It could take up to ~20 seconds for the local kube-apiserver to start running on the bootstrap node,
Expand All @@ -166,15 +173,17 @@ func handleBootstrapStopKeepalived(kubeconfigPath string, bootstrapStopKeepalive
"consecutiveErr": consecutiveErr,
}).Info("handleBootstrapStopKeepalived: detect failure on API")
} else {
if consecutiveErr > bootstrapApiFailuresThreshold { // Means it was stopped
bootstrapStopKeepalived <- started
}
consecutiveErr = 0
}
if consecutiveErr > bootstrapApiFailuresThreshold {
log.WithFields(logrus.Fields{
"consecutiveErr": consecutiveErr,
"bootstrapApiFailuresThreshold": bootstrapApiFailuresThreshold,
}).Info("handleBootstrapStopKeepalived: Num of failures exceeds threshold")
bootstrapStopKeepalived <- true
return
bootstrapStopKeepalived <- stopped
}
time.Sleep(1 * time.Second)
}
Expand Down Expand Up @@ -277,7 +286,7 @@ func KeepalivedWatch(kubeconfigPath, clusterConfigPath, templatePath, cfgPath st
signals := make(chan os.Signal, 1)
done := make(chan bool, 1)
updateModeCh := make(chan modeUpdateInfo, 1)
bootstrapStopKeepalived := make(chan bool, 1)
bootstrapStopKeepalived := make(chan APIState, 1)

signal.Notify(signals, syscall.SIGTERM)
signal.Notify(signals, syscall.SIGINT)
Expand Down Expand Up @@ -306,23 +315,25 @@ func KeepalivedWatch(kubeconfigPath, clusterConfigPath, templatePath, cfgPath st
case <-done:
return nil

case <-bootstrapStopKeepalived:
case APIStateChanged := <-bootstrapStopKeepalived:
//Verify that stop message sent successfully
for {
_, err := conn.Write([]byte("stop\n"))
var cmdMsg []byte
if APIStateChanged == stopped {
cmdMsg = []byte("stop\n")
} else {
cmdMsg = []byte("reload\n")
}
_, err := conn.Write(cmdMsg)
if err == nil {
log.Info("Stop message successfully sent to Keepalived container control socket")
log.Info("Command message successfully sent to Keepalived container control socket: %s", string(cmdMsg[:]))
break
}
log.WithFields(logrus.Fields{
"socket": keepalivedControlSock,
}).Error("Failed to write stop to Keepalived container control socket")
}).Error("Failed to write command to Keepalived container control socket")
time.Sleep(1 * time.Second)
}
for {
time.Sleep(20 * time.Second)
log.Info("Keepalived watcher sleep forever: API not available")
}

case desiredModeInfo := <-updateModeCh:

Expand Down

0 comments on commit 6858d3c

Please sign in to comment.