Skip to content

Commit

Permalink
Update test application
Browse files Browse the repository at this point in the history
Signed-off-by: Mikkel Oscar Lyderik Larsen <m@moscar.net>
  • Loading branch information
mikkeloscar committed May 26, 2018
1 parent 62642ff commit 3f9af9c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 1 addition & 4 deletions Makefile
Expand Up @@ -4,12 +4,9 @@ BINARY ?= sigterm-test
VERSION ?= $(shell git describe --tags --always --dirty)
IMAGE ?= mikkeloscar/$(BINARY)
TAG ?= $(VERSION)
GITHEAD = $(shell git rev-parse --short HEAD)
GITURL = $(shell git config --get remote.origin.url)
GITSTATUS = $(shell git status --porcelain || echo "no changes")
SOURCES = $(shell find . -name '*.go')
DOCKERFILE ?= Dockerfile
GOPKGS = $(shell go list ./... | grep -v /vendor/)
GOPKGS = $(shell go list ./...)
BUILD_FLAGS ?= -v
LDFLAGS ?= -X main.version=$(VERSION) -w -s

Expand Down
13 changes: 11 additions & 2 deletions deployment.yaml
@@ -1,9 +1,12 @@
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: "sigterm-test"
spec:
replicas: 2
selector:
matchLabels:
application: "sigterm-test"
template:
metadata:
labels:
Expand All @@ -12,6 +15,8 @@ spec:
containers:
- name: sigterm-test
image: mikkeloscar/sigterm-test:latest
args:
- -sigterm-timeout=0s
# args:
# - -keep-alive # set when testing not disabling keep-alives.
ports:
Expand All @@ -25,6 +30,10 @@ spec:
httpGet:
path: /healthz?type=readiness
port: 8080
lifecycle:
preStop:
exec:
command: ["sleep","20"]
# scheme: HTTP
# failureThreshold: 2
# initialDelaySeconds: 2
Expand Down Expand Up @@ -66,7 +75,7 @@ metadata:
name: sigterm-test
spec:
rules:
- host: myhost.example.org
- host: sigterm.teapot.zalan.do
http:
paths:
- backend:
Expand Down
8 changes: 6 additions & 2 deletions main.go
Expand Up @@ -35,10 +35,14 @@ func healthHandler(w http.ResponseWriter, r *http.Request) {
}
}

var keepAlive bool
var (
keepAlive bool
sigtermTimeout time.Duration
)

func main() {
flag.BoolVar(&keepAlive, "keep-alive", false, "Don't disable keep-alives after SIGTERM.")
flag.DurationVar(&sigtermTimeout, "sigterm-timeout", 20*time.Second, "How long to wait after SIGTERM before terminating.")
flag.Parse()

sigTerm := make(chan os.Signal, 1)
Expand All @@ -63,6 +67,6 @@ func main() {
log.Println("SetKeepAlivesEnabled=false")
server.SetKeepAlivesEnabled(false)
}
time.Sleep(20 * time.Second)
time.Sleep(sigtermTimeout)
log.Println("exiting")
}

0 comments on commit 3f9af9c

Please sign in to comment.