Skip to content

Commit

Permalink
Add configuration parameter for namespace mount path
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
welteki committed May 14, 2024
1 parent 19d7e56 commit fdb1f4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
7 changes: 6 additions & 1 deletion executor/jwt_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fdb1f4f

Please sign in to comment.