From a1c2c553a5f67f68642feb9dede6bba4ac97ca32 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (VMware)" <alexellis2@gmail.com> Date: Tue, 17 Jul 2018 09:52:01 +0100 Subject: [PATCH] Add scale_from_zero flag Added scale_from_zero to config, docs and wrote unit test for the value. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com> --- gateway/README.md | 1 + gateway/types/readconfig.go | 6 ++++++ gateway/types/readconfig_test.go | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/gateway/README.md b/gateway/README.md index c1cf047b..9cf4f5b6 100644 --- a/gateway/README.md +++ b/gateway/README.md @@ -56,3 +56,4 @@ The gateway can be configured through the following environment variables: | `direct_functions_suffix` | Provide a DNS suffix for invoking functions directly over overlay network | | `basic_auth` | Set to `true` or `false` to enable embedded basic auth on the /system and /ui endpoints (recommended) | | `secret_mount_path` | Set a location where you have mounted `basic-auth-user` and `basic-auth-password`, default: `/run/secrets/`. | +| `scale_from_zero` | Enables an intercepting proxy which will scale any function from 0 replicas to the desired amount | diff --git a/gateway/types/readconfig.go b/gateway/types/readconfig.go index 115c9d59..09a0d960 100644 --- a/gateway/types/readconfig.go +++ b/gateway/types/readconfig.go @@ -112,6 +112,7 @@ func (ReadConfig) Read(hasEnv HasEnv) GatewayConfig { secretPath = "/run/secrets/" } cfg.SecretMountPath = secretPath + cfg.ScaleFromZero = parseBoolValue(hasEnv.Getenv("scale_from_zero")) return cfg } @@ -149,11 +150,16 @@ type GatewayConfig struct { // If set this will be used to resolve functions directly DirectFunctionsSuffix string +<<<<<<< HEAD // If set, reads secrets from file-system for enabling basic auth. UseBasicAuth bool // SecretMountPath specifies where to read secrets from for embedded basic auth SecretMountPath string +======= + // Enable the gateway to scale any service from 0 replicas to its configured "min replicas" + ScaleFromZero bool +>>>>>>> Add scale_from_zero flag } // UseNATS Use NATSor not diff --git a/gateway/types/readconfig_test.go b/gateway/types/readconfig_test.go index f1a09489..9d904e77 100644 --- a/gateway/types/readconfig_test.go +++ b/gateway/types/readconfig_test.go @@ -68,6 +68,29 @@ func TestRead_DirectFunctionsOverride(t *testing.T) { } } +func TestRead_ScaleZeroDefaultAndOverride(t *testing.T) { + defaults := NewEnvBucket() + readConfig := ReadConfig{} + // defaults.Setenv("scale_from_zero", "true") + config := readConfig.Read(defaults) + + want := false + if config.ScaleFromZero != want { + t.Logf("ScaleFromZero should be %v, got: %v", want, config.ScaleFromZero) + t.Fail() + } + + defaults.Setenv("scale_from_zero", "true") + config = readConfig.Read(defaults) + want = true + + if config.ScaleFromZero != want { + t.Logf("ScaleFromZero was overriden - should be %v, got: %v", want, config.ScaleFromZero) + t.Fail() + } + +} + func TestRead_EmptyTimeoutConfig(t *testing.T) { defaults := NewEnvBucket() readConfig := ReadConfig{} -- GitLab