From fdb1f4fed009c2c583ce913a8ec775b37825f4e5 Mon Sep 17 00:00:00 2001 From: "Han Verstraete (OpenFaaS Ltd)" Date: Tue, 14 May 2024 13:18:36 +0200 Subject: [PATCH] Add configuration parameter for namespace mount path Support changing the path used by the watchdog to read the funcion namespace by setting the env variable 'namespace_mount_path'. Required for running functions locally with jwt_auth. Signed-off-by: Han Verstraete (OpenFaaS Ltd) --- README.md | 1 + executor/jwt_authenticator.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 604d5b97..c036a644 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ Environmental variables: | `log_call_id` | In HTTP mode, when printing a response code, content-length and timing, include the X-Call-Id header at the end of the line in brackets i.e. `[079d9ff9-d7b7-4e37-b195-5ad520e6f797]` or `[none]` when it's empty. Default: `false` | | `max_inflight` | Limit the maximum number of requests in flight, and return a HTTP status 429 when exceeded | | `mode` | The mode which of-watchdog operates in, Default `streaming` [see doc](#3-streaming-fork-modestreaming---default). Options are [http](#1-http-modehttp), [serialising fork](#2-serializing-fork-modeserializing), [streaming fork](#3-streaming-fork-modestreaming---default), [static](#4-static-modestatic) | +| `namespace_mount_path | Path used by the watchdog to lookup the namespace the function is deployed in. | `/var/run/secrets/kubernetes.io/serviceaccount/namespace` | | `port` | Specify an alternative TCP port for testing. Default: `8080` | | `prefix_logs` | When set to `true` the watchdog will add a prefix of "Date Time" + "stderr/stdout" to every line read from the function process. Default `true` | | `read_timeout` | HTTP timeout for reading the payload from the client caller (in seconds) | diff --git a/executor/jwt_authenticator.go b/executor/jwt_authenticator.go index 0c05e08d..39b92c9d 100644 --- a/executor/jwt_authenticator.go +++ b/executor/jwt_authenticator.go @@ -207,7 +207,12 @@ func getFnName() (string, error) { } func getFnNamespace() (string, error) { - nsVal, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") + namespacePath := "/var/run/secrets/kubernetes.io/serviceaccount/namespace" + if v, ok := os.LookupEnv("namespace_mount_path"); ok && len(v) > 0 { + namespacePath = v + } + + nsVal, err := os.ReadFile(namespacePath) if err != nil { return "", err }