Skip to content

Conversation

@dstandish
Copy link
Contributor

@dstandish dstandish commented Oct 18, 2022

In KPO, currently, if you do not provide namespace as a KPO arg (and it's not otherwise specified through pod template or full pod spec) the task will fail when trying to create the pod, because the kube client does not fill it in for you like e.g. kubectl does.

This PR makes it optional.

If it's not specified through KPO arg, or full pod spec, or pod template, then first we'll check the hook to see if you've configured a namespace there. And if that is unspecified, if we're in a cluster already, we'll check /var/run/secrets/kubernetes.io/serviceaccount/namespace for the value.

@boring-cyborg boring-cyborg bot added provider:cncf-kubernetes Kubernetes (k8s) provider related issues area:providers labels Oct 18, 2022
Copy link
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

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

Not a fan of using k as a variable name, but I know you did it to maintain consistency. Other than that, looks like a nice reasonable addition. 👍

@dstandish dstandish force-pushed the kpo-add-default-namespace branch from 102bea1 to 846646f Compare October 18, 2022 21:13
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here we remove the global hook patch because we rely on it for namespace test

Comment on lines -105 to -107
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of doing this, i just read the value from the actual hook (since we're no longer patching it globally)

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 see this added in many places because we're not patching it globally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when we're just building the pod object we don't need the full "run" method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is a get_namespace method on the hook but it's problematic. i may resolve that in future PR and then can update this. i'll resolve that and update this in a followup PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed so much boilerplate. 😍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now if only i can get the tests to pass...

@dstandish dstandish force-pushed the kpo-add-default-namespace branch from 53a1f5a to 230a255 Compare October 21, 2022 15:34
@dstandish dstandish changed the title Use current namespace if none provided in KPO Try to use hook namespace or infer from cluster if none provided in KPO Oct 21, 2022
@dstandish dstandish changed the title Try to use hook namespace or infer from cluster if none provided in KPO Make namespace fully optional for KPO Oct 21, 2022
@dstandish dstandish changed the title Make namespace fully optional for KPO Make namespace optional for KPO Oct 21, 2022
Copy link
Member

Choose a reason for hiding this comment

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

Should we document this priority?

Copy link
Member

Choose a reason for hiding this comment

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

@dstandish dstandish force-pushed the kpo-add-default-namespace branch from 192b65e to dd22bea Compare October 21, 2022 18:22
In KPO namespace is currently required, either through pod template file, airflow connection, or KPO arg.  If we're in the in_cluster scenario though, we should be able to derive the current namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace.  This seems like a reasonable thing to do as a default.
@dstandish dstandish force-pushed the kpo-add-default-namespace branch from 1395e13 to d0bb221 Compare October 22, 2022 18:47
@dstandish dstandish merged commit 3ecb8dd into apache:main Oct 22, 2022
@dstandish dstandish deleted the kpo-add-default-namespace branch October 22, 2022 19:27
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.

4 participants