Set the default namespace with OPENFAAS_NS - #1028
Conversation
This comment has been minimized.
This comment has been minimized.
Use OPENFAAS_NS when a namespace-aware command has no explicit namespace. This avoids implicitly targeting the cluster default for users who work in another namespace while preserving existing flag and stack precedence. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Query every namespace resolved by the functions in a stack instead of listing functions from only one namespace. Key each deployed function by the namespace used for its query so a same-named function in another namespace cannot satisfy the wrong stack entry. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
143b5d3 to
1259b6d
Compare
AI Pull Request OverviewDisclaimer: This review was generated by automated AI and may contain errors. Do not trust its outputs without human verification. Summary
Approval rating (1-10)9/10. The change is cohesive and well-covered; I found no blocking correctness issues in the scoped diff. Summary per fileSummary per file
Overall AssessmentThe PR implements the intended precedence consistently: explicit namespace flags remain strongest, stack namespaces still override defaults, and Detailed ReviewDetailed ReviewNo blocking findings. The central The The The README addition is accurate for the feature. It is brief, but it fits the existing environment variable list format and does not introduce a rendering or content issue. AI agent details. |
alexellis
left a comment
There was a problem hiding this comment.
Unsure on approach, but if it works, we'll ship it.
| // Check if there is a functionNamespace flag passed, if so, override the namespace value | ||
| // defined in the stack.yaml | ||
| function.Namespace = getNamespace(functionNamespace, function.Namespace) | ||
| function.Namespace = getNamespace(functionNamespace, function.Namespace, os.Getenv(openFaaSNamespaceEnvironment)) |
There was a problem hiding this comment.
I don't think I would have added os.Getenv(openFaaSNamespaceEnvironment) to every callsight - given it's consistent I would have perhaps not even have changed the signature at all and have had it self-contained.
Go unit tests can setenv dynamically when needed.
Description
Add support for the
OPENFAAS_NSenvironment variable as the defaultnamespace for namespace-aware commands (
up,deploy,describe,diff,invoke,list,logs,ready,removeand thesecretcommands).
Namespace resolution precedence is unchanged: the
--namespaceflagwins, then the stack.yaml namespace, then
OPENFAAS_NS, then thecluster default namespace.
diffpreviously listed deployed functions from a single namespaceonly: the
--namespaceflag value, or the cluster default if the flagwas not set. For a stack that spans multiple namespaces this meant
deployed functions in other namespaces were invisible, so
diffwouldreport them as not deployed. It now collects the set of namespaces
that the stack's functions resolve to (applying the same precedence)
and lists deployed functions from each of them, so every deployed
function that a stack function could match is found.
Also fixes
invoketo use the resolved namespace on the 401 retrypath, which previously used the raw
--namespaceflag and dropped thestack.yaml and
OPENFAAS_NSvalues.Motivation and Context
Users with access to a non-default namespace, e.g. a per-user
namespace on a shared cluster, currently have to pass
--namespaceto every command. Setting
OPENFAAS_NSin the environment lets theircommands avoid implicitly targeting the cluster default namespace.
How Has This Been Tested?
namespaces, logs resolution, and multi-namespace
diffbehavior.that omit the function namespace.
OPENFAAS_NSend to end with deploy, store deploy, list,describe, ready, invoke, logs, remove, and the secret lifecycle.
--namespaceoverrides the environment and that existingstack namespace precedence is preserved.
diffwith a stack spanning multiple namespaces. The old CLImissed namespaced functions, while the updated CLI matched each function
to its queried namespace and reported only genuinely missing functions.
Types of changes
Checklist:
git commit -s