feat(backend): Support KALE_KFP_NAMESPACE for configurable KFP server namespace#875
feat(backend): Support KALE_KFP_NAMESPACE for configurable KFP server namespace#875harshhh817 wants to merge 3 commits into
Conversation
The KFP client namespace was hardcoded in two places: the KFPServerConfig Field default and a fallback in get_kfp_client(). This made multi-cluster deployments painful, since KFP lives in different namespaces across clusters (kubeflow, kubeflow-pipelines, or custom) and every user had to hand-edit their config file. Introduce a single canonical default (DEFAULT_NAMESPACE) plus a get_default_namespace() helper that reads the KALE_KFP_NAMESPACE environment variable. load_config() now resolves the namespace with this precedence (highest first): explicit namespace= argument > JSON config file > KALE_KFP_NAMESPACE env var > canonical in-code default. The duplicate hardcoded fallback in kfp_client_factory.py is removed. Adds unit tests for unset env (default), env override, config-file override, config file without namespace falling back to env, and explicit-parameter override. Closes kubeflow#798 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Harsh Gupta <harshgupta93198@gmail.com>
fdd0a4c to
84e5a12
Compare
ada333
left a comment
There was a problem hiding this comment.
hi @harshhh817 from quick look the code looks good - please also add the env var to documentation (https://github.com/kubeflow/kale/blob/main/docs/source/user-guide/running-pipelines.md?plain=1#L104)
Signed-off-by: Harsh Gupta <harshgupta93198@gmail.com>
|
Thanks for the review @ada333! Added |
There was a problem hiding this comment.
LGTM - I tried setting up the env var and running Kale to see if the target namespace changes, thanks for working on this @harshhh817
jesuino
left a comment
There was a problem hiding this comment.
Hello,
The changes looks good and it seems to work well. I have a possible suggestion to avoid code duplication, would you please check it?
Thanks!
| if not os.path.exists(config_path): | ||
| log.debug("No KFP server config found at %s, using defaults", config_path) | ||
| return KFPServerConfig() | ||
| return _apply_default_namespace(KFPServerConfig()) |
There was a problem hiding this comment.
I see multiple calls to this method, could this be done in the _postprocess method? learn more about it in kale/config/config.py:
Validators are useful for single-field checks. To performs post
initialization/validation checks, over multiple fields, or postprocess the
validated fields, override the `_validate` and `_postprocess` functions,
respectively.
Here's a suggested solution (not tested):
def _postprocess(self):
"""Fill in the default namespace if not explicitly set."""
if self.namespace is None:
self.namespace = get_default_namespace()
Move the unset-namespace fallback into KFPServerConfig._postprocess so the resolution lives in one place, per review feedback. This removes the _apply_default_namespace helper and its three call sites in load_config; _postprocess runs after validation on every construction, so all callers get a concrete namespace without repeating the fallback. Signed-off-by: Harsh Gupta <harshgupta93198@gmail.com>
|
Thanks @jesuino! Moved the default-namespace resolution into |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
What this does
Adds support for a
KALE_KFP_NAMESPACEenvironment variable so the Kubernetes namespace used for KFP API operations is configurable without hardcoding it in Kale's server config or asking every user to hand-editkfp_server_config.json.Closes #798
Why
KFP is not installed in the same namespace across environments (
kubeflow,kubeflow-pipelines, or custom). With the namespace hardcoded, pipeline upload/list/run operations target the wrong namespace and users hit 404s, permission errors, or empty experiment lists even when host and auth are correct. An env var is much easier to standardize fleet-wide (viaPodDefault, deployment env, or CI secrets) than baking a per-cluster config file.Changes
kale/config/kfp_server_config.pyDEFAULT_NAMESPACEand aget_default_namespace()helper that readsKALE_KFP_NAMESPACE.namespaceFielddefault toNonesoload_config()can distinguish "user didn't set a namespace" from "user explicitly chose the default", then resolves it via_apply_default_namespace().kale/common/kfp_client_factory.py"kubeflow"fallback.load_config()now returns an already-resolved namespace; an explicitnamespace=argument still wins.kale/tests/unit_tests/test_kfp_server_config.pynamespacefalling back to the env var, and explicit-parameter override.Resolution order (highest priority first)
namespace=argument toget_kfp_client()"namespace"in the JSON config file (KALE_CONFIG_PATH)KALE_KFP_NAMESPACEenvironment variableDEFAULT_NAMESPACE)This mirrors how Kale already configures paths (
KALE_CONFIG_PATH).Testing
Note
The issue mentions some branches default to
kubeflow-pipelines, butmaincurrently defaults tokubeflow, so I keptkubeflowas the canonical default to avoid changing existing behavior. Happy to switch the default if maintainers prefer.