Skip to content

Commit

Permalink
Moved ready to a dflag so it can be changed with curl on 7999 or in cmap
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Feb 25, 2024
1 parent b875afe commit 8dcf341
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ tail-log:
kubectl logs -f -n memstore memstore-0 | logc

debug-pod:
kubectl run debug --image=ubuntu --restart=Never -- /bin/sleep infinity
kubectl run debug --image=ubuntu -- /bin/sleep infinity
2 changes: 2 additions & 0 deletions chart/templates/02_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ data:
dns: memstore-internal.memstore.svc.cluster.local
dns-interval: 5s
statefulset: "true"
ready: "false"
config-port: "7999"
4 changes: 2 additions & 2 deletions mstore/dnsWatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func reverseDNS(ips sets.Set[string]) (sets.Set[string], bool) {
allNames.Add(shortName)
}
if !allNames.Has(myName) {
log.Errf("My name %q not found in the reverse DNS list: %v", myName, allNames)
log.Warnf("My name %q not found in the reverse DNS list: %v", myName, allNames)
}
return allNames, hasError
}
Expand All @@ -76,7 +76,7 @@ func checkDNS(serviceName string) {
var hasErrors bool
peerNames, hasErrors = reverseDNS(newIPs)
numPeers = len(peerNames)
log.Infof("StatefulSet mode, errs %v found %d peers (including ourselves %q) for %q: %v",
log.Infof("StatefulSet mode, errs %v found %d peers (possibly including ourselves %q) for %q: %v",
hasErrors, numPeers, myName, serviceName, peerNames)
if hasErrors {
return
Expand Down
18 changes: 10 additions & 8 deletions probes/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ import (
"net/http"
"sync"

"fortio.org/dflag"
"fortio.org/log"
)

type state struct {
started bool
live bool
ready bool
// mutex
mutex sync.Mutex
}

var State = state{}
var (
State = state{}
ReadyFlag = dflag.NewBool(false, "Initial readiness state")
)

func (s *state) SetLive(live bool) {
s.mutex.Lock()
s.live = live
s.mutex.Unlock()
log.Infof("Setting live to %v", live)
}

func (s *state) SetReady(ready bool) {
s.mutex.Lock()
s.ready = ready
s.mutex.Unlock()
_ = ReadyFlag.SetV(ready)
log.Infof("Setting ready to %v", ready)
}

func (s *state) SetStarted(started bool) {
s.mutex.Lock()
s.started = started
s.mutex.Unlock()
log.Infof("Setting started to %v", started)
}

func (s *state) IsLive() bool {
Expand All @@ -43,9 +47,7 @@ func (s *state) IsLive() bool {
}

func (s *state) IsReady() bool {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.ready
return ReadyFlag.Get()
}

func (s *state) IsStarted() bool {
Expand Down
3 changes: 2 additions & 1 deletion proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
dflag.Flag("dns", mstore.DNSWatch)
dflag.Flag("dns-interval", mstore.DNSWatchSleepTime)
dflag.FlagBool("statefulset", mstore.StatefulSet)
dflag.FlagBool("ready", probes.ReadyFlag)
scli.ServerMain()
if mstore.StatefulSet.Get() && mstore.DNSWatch.Get() == "" {
log.Fatalf("StatefulSet mode needs -dns to be set")
Expand All @@ -43,7 +44,7 @@ func main() {
probes.Setup(mux)
probes.State.SetLive(true)
probes.State.SetStarted(true)
probes.State.SetReady(true)
// For testing/changing we can use curl to set flags podip:7999/set?name=ready&value=true
/*
time.Sleep(50 * time.Second) // give time for the probes to be ready
log.Warnf("Switching back to not ready")
Expand Down

0 comments on commit 8dcf341

Please sign in to comment.