Skip to content

Comments

KPO should use hook's get namespace method to get namespace#27516

Merged
dstandish merged 1 commit intoapache:mainfrom
astronomer:kpo-better-get-namespace
Nov 6, 2022
Merged

KPO should use hook's get namespace method to get namespace#27516
dstandish merged 1 commit intoapache:mainfrom
astronomer:kpo-better-get-namespace

Conversation

@dstandish
Copy link
Contributor

@dstandish dstandish commented Nov 5, 2022

Recently hook was updated to allow non-prefixed extra fields. So we need to check non-prefixed also. Best to use the hook's "get namespace" method. But the public one has a problem; it defaults to default, so we don't know if it was set to that intentionally. So we use the "protected" method _get_namespace, which doesn't return a default. This allows us, in this case to check if we can derive from cluster, and only then default to default.
In 6.0, get_namespace will have the correct behavior, and we'll update this again to use it instead.

Recently hook was updated to allow non-prefixed extra fields.  So we need to check non-prefixed also.  Best to use the hook's "get namespace" method.  But the public one has a problem; it defaults to `default`, so we don't know if it was set to that intentionally.  So we use the "protected" method `_get_namespace`, which doesn't return a default.  This allows us, in this case to check if we can derive from cluster, and only _then_ default to `default`.
@boring-cyborg boring-cyborg bot added provider:cncf-kubernetes Kubernetes (k8s) provider related issues area:providers labels Nov 5, 2022
@eladkal eladkal linked an issue Nov 5, 2022 that may be closed by this pull request
2 tasks
hook_namespace = self.hook.conn_extras.get("extra__kubernetes__namespace")
# todo: replace with call to `hook.get_namespace` in 6.0, when it doesn't default to `default`.
# if namespace not actually defined in hook, we want to check k8s if in cluster
hook_namespace = self.hook._get_namespace()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this method should be made public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it should. it will happen after 6.0 when we replace the current get_namespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some test to validate or we already have one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we have one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean to remind us to update those in 6.0? yes, we do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and then when user removes _get_namespace, they'll see this reference and presumably read the todo and update it)

@dstandish dstandish merged commit 20ecefa into apache:main Nov 6, 2022
@dstandish dstandish deleted the kpo-better-get-namespace branch November 6, 2022 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KPO do not use namespace setting from kubernetes_conn_id

3 participants