Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add epoch so helm upgrade always turns into pod roll
Browse files Browse the repository at this point in the history
ldemailly committed Feb 25, 2024
1 parent ea5ae9c commit b875afe
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -13,15 +13,15 @@ test:

# Works with docker-desktop for instance:

LOCAL_HELM_OVERRIDES:=--set image.pullPolicy=Never --set debug=true
LOCAL_HELM_OVERRIDES:=--set image.pullPolicy=Never --set debug=true --set epoch=$(shell date +%s)
HELM:=helm
CHART_NAME:=memstore
CHART_DIR:=chart/
HELM_INSTALL_ARGS:=upgrade --install $(CHART_NAME) $(CHART_DIR) $(LOCAL_HELM_OVERRIDES)

local-k8s:
CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" .
-kubectl delete statefulset -n memstore memstore # so it'll reload the image
# -kubectl delete statefulset -n memstore memstore # so it'll reload the image
docker buildx build --load --tag fortio/memstore:latest .
$(HELM) $(HELM_INSTALL_ARGS)

2 changes: 2 additions & 0 deletions chart/templates/03_memstore.yaml
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ spec:
image: {{.Values.image.repository}}:{{.Values.image.tag}}
imagePullPolicy: {{.Values.image.pullPolicy}}
env:
- name: EPOCH
value: {{ .Values.epoch | quote }} # To cause update even if tag is the same
- name: NAME
valueFrom:
fieldRef:
2 changes: 2 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -6,4 +6,6 @@ image:
tag: latest # Use specific tag for prod
pullPolicy: IfNotPresent # We use never in local docker desktop mode (see Makefile)

epoch: 1

debug: false # Don't install fortio client
11 changes: 7 additions & 4 deletions proto.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ package main
import (
"flag"
"os"
"time"

"fortio.org/dflag"
"fortio.org/fortio/fhttp"
@@ -34,6 +33,8 @@ func main() {
if mstore.StatefulSet.Get() && !found {
log.Fatalf("No NAME env var found for statefulset mode (to this pod's name)")
}
epoch := os.Getenv("EPOCH")
log.Infof("Starting memstore with name %q and epoch %s", myName, epoch)
mstore.Start(myName)
mux, addr := fhttp.HTTPServer("memstore", *port)
if addr == nil {
@@ -43,9 +44,11 @@ func main() {
probes.State.SetLive(true)
probes.State.SetStarted(true)
probes.State.SetReady(true)
time.Sleep(50 * time.Second) // give time for the probes to be ready
log.Warnf("Switching back to not ready")
probes.State.SetReady(false)
/*
time.Sleep(50 * time.Second) // give time for the probes to be ready
log.Warnf("Switching back to not ready")
probes.State.SetReady(false)
*/
scli.UntilInterrupted()
mstore.Stop()
}

0 comments on commit b875afe

Please sign in to comment.