From ed2a774e108b6b2f48e4160e67904b28ded205e4 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 23 Jan 2020 15:03:15 +0100 Subject: [PATCH 1/3] Add `--unhealthy` and `--unready` flags Depending on the flag set, the healthy or ready state is never reached. --- Makefile | 3 ++- cmd/podinfo/main.go | 2 ++ pkg/api/server.go | 10 ++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fbef905..68b2ce8 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,12 @@ DOCKER_REPOSITORY:=stefanprodan DOCKER_IMAGE_NAME:=$(DOCKER_REPOSITORY)/$(NAME) GIT_COMMIT:=$(shell git describe --dirty --always) VERSION:=$(shell grep 'VERSION' pkg/version/version.go | awk '{ print $$4 }' | tr -d '"') +EXTRA_RUN_ARGS?= run: GO111MODULE=on go run -ldflags "-s -w -X github.com/stefanprodan/podinfo/pkg/version.REVISION=$(GIT_COMMIT)" cmd/podinfo/* \ --level=debug --grpc-port=9999 --backend-url=https://httpbin.org/status/401 --backend-url=https://httpbin.org/status/500 \ - --ui-logo=https://raw.githubusercontent.com/stefanprodan/podinfo/gh-pages/cuddle_clap.gif --ui-color=#34577c + --ui-logo=https://raw.githubusercontent.com/stefanprodan/podinfo/gh-pages/cuddle_clap.gif --ui-color=#34577c $(EXTRA_RUN_ARGS) test: GO111MODULE=on go test -v -race ./... diff --git a/cmd/podinfo/main.go b/cmd/podinfo/main.go index 0be0fbb..598de56 100644 --- a/cmd/podinfo/main.go +++ b/cmd/podinfo/main.go @@ -42,6 +42,8 @@ func main() { fs.Bool("h2c", false, "Allow upgrading to H2C") fs.Bool("random-delay", false, "between 0 and 5 seconds random delay") fs.Bool("random-error", false, "1/3 chances of a random response error") + fs.Bool("unhealthy", false, "when set, healthy state is never reached") + fs.Bool("unready", false, "when set, ready state is never reached") fs.Int("stress-cpu", 0, "Number of CPU cores with 100 load") fs.Int("stress-memory", 0, "MB of data to load into memory") diff --git a/pkg/api/server.go b/pkg/api/server.go index b5aa67d..ffac5cd 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -65,6 +65,8 @@ type Config struct { H2C bool `mapstructure:"h2c"` RandomDelay bool `mapstructure:"random-delay"` RandomError bool `mapstructure:"random-error"` + Unhealthy bool `mapstructure:"unhealthy"` + Unready bool `mapstructure:"unready"` JWTSecret string `mapstructure:"jwt-secret"` } @@ -181,8 +183,12 @@ func (s *Server) ListenAndServe(stopCh <-chan struct{}) { }() // signal Kubernetes the server is ready to receive traffic - atomic.StoreInt32(&healthy, 1) - atomic.StoreInt32(&ready, 1) + if !s.config.Unhealthy { + atomic.StoreInt32(&healthy, 1) + } + if !s.config.Unready { + atomic.StoreInt32(&ready, 1) + } // wait for SIGTERM or SIGINT <-stopCh From 15600cc7d3651de86eedf5f025e0e6606c97beb9 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 23 Jan 2020 15:07:16 +0100 Subject: [PATCH 2/3] Lowercase all flag descriptions --- cmd/podinfo/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/podinfo/main.go b/cmd/podinfo/main.go index 598de56..47b3aec 100644 --- a/cmd/podinfo/main.go +++ b/cmd/podinfo/main.go @@ -39,12 +39,12 @@ func main() { fs.String("ui-logo", "", "UI logo") fs.String("ui-color", "cyan", "UI color") fs.String("ui-message", fmt.Sprintf("greetings from podinfo v%v", version.VERSION), "UI message") - fs.Bool("h2c", false, "Allow upgrading to H2C") + fs.Bool("h2c", false, "allow upgrading to H2C") fs.Bool("random-delay", false, "between 0 and 5 seconds random delay") fs.Bool("random-error", false, "1/3 chances of a random response error") fs.Bool("unhealthy", false, "when set, healthy state is never reached") fs.Bool("unready", false, "when set, ready state is never reached") - fs.Int("stress-cpu", 0, "Number of CPU cores with 100 load") + fs.Int("stress-cpu", 0, "number of CPU cores with 100 load") fs.Int("stress-memory", 0, "MB of data to load into memory") versionFlag := fs.BoolP("version", "v", false, "get version number") From 48402eff7ee2949621842409043e8a2b127ff5fc Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 23 Jan 2020 15:16:55 +0100 Subject: [PATCH 3/3] Add `--unhealthy` and `--unready` flags to chart --- charts/podinfo/README.md | 2 ++ charts/podinfo/templates/deployment.yaml | 6 ++++++ charts/podinfo/values.yaml | 2 ++ 3 files changed, 10 insertions(+) diff --git a/charts/podinfo/README.md b/charts/podinfo/README.md index 4518156..2275286 100644 --- a/charts/podinfo/README.md +++ b/charts/podinfo/README.md @@ -36,6 +36,8 @@ Parameter | Description | Default `backends` | echo backend URL array | None `faults.delay` | random HTTP response delays between 0 and 5 seconds | `false` `faults.error` | 1/3 chances of a random HTTP response error | `false` +`faults.unhealthy` | when set, the healthy state is never reached | `false` +`faults.unready` | when set, the ready state is never reached | `false` `hpa.enabled` | enables HPA | `false` `hpa.cpu` | target CPU usage per pod | None `hpa.memory` | target memory usage per pod | None diff --git a/charts/podinfo/templates/deployment.yaml b/charts/podinfo/templates/deployment.yaml index d8160e3..95c381a 100644 --- a/charts/podinfo/templates/deployment.yaml +++ b/charts/podinfo/templates/deployment.yaml @@ -54,6 +54,12 @@ spec: - --level={{ .Values.logLevel }} - --random-delay={{ .Values.faults.delay }} - --random-error={{ .Values.faults.error }} + {{- if .Values.faults.unhealthy }} + - --unhealthy + {{- end }} + {{- if .Values.faults.unready }} + - --unready + {{- end }} {{- if .Values.h2c.enabled }} - --h2c {{- end }} diff --git a/charts/podinfo/values.yaml b/charts/podinfo/values.yaml index 398c150..b46fccf 100644 --- a/charts/podinfo/values.yaml +++ b/charts/podinfo/values.yaml @@ -13,6 +13,8 @@ ui: faults: delay: false error: false + unhealthy: false + unready: false h2c: enabled: false