Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

choosing a namespace in a consistent fashion across fabric8 and k8s-native clients #859

Closed
3 of 5 tasks
wind57 opened this issue Aug 27, 2021 · 5 comments · Fixed by #860 or #865
Closed
3 of 5 tasks

choosing a namespace in a consistent fashion across fabric8 and k8s-native clients #859

wind57 opened this issue Aug 27, 2021 · 5 comments · Fixed by #860 or #865

Comments

@wind57
Copy link
Contributor

wind57 commented Aug 27, 2021

We can set the namespace property for a certain secret/config map at this level:

spring.cloud.kubernetes.secrets.namespace or spring.cloud.kubernetes.secrets.sources[].namespace. This is how a NormalizedSource::namespace is populated (same logic is applied for config maps) This is easy.

Suppose that I do not set it in neither of the above.

In such a case, we will reach KubernetesClientSecretsPropertySourceLocator.

Which says that if normalized source is not set, we will use fallbackNamespace and this is where I would like to look more closely. This property is :

String fallbackNamespace = kubernetesNamespaceProvider != null ? kubernetesNamespaceProvider.getNamespace()
				: kubernetesClientProperties.getNamespace();

It is understandable why we use both kubernetesNamespaceProvider and kubernetesClientProperties to find the namespace. There are two constructors in KubernetesClientSecretsPropertySourceLocator, and one takes a property or the other.

Now the first (1) nitpick is that the constructor that takes a KubernetesClientProperties as input is not used by us - so let's deprecate it (I would very much rather prefer we delete it). Moreover internally it uses spring.cloud.kubernetes.client.namespace property, one that is documented in general, but it is not documented in our project. That is a nitpick/question (2).

And a final (3) question here is : fabric8 client does not read such a property at all (spring.cloud.kubernetes.client.namespace), so this seems a bit odd as there is a discrepancy between the two clients that we use. This is either a bug in fabric8 implementation or it needs to be clearly stipulated in the documentation.

The other constructor that takes KubernetesNamespaceProvider as input, we do use it.

Now let's get back to that :

String fallbackNamespace = kubernetesNamespaceProvider != null ? kubernetesNamespaceProvider.getNamespace()
				: kubernetesClientProperties.getNamespace();

So if provider is present, let's read the namespace from :

  • spring.cloud.kubernetes.client.namespace, if not present:
  • spring.cloud.kubernetes.client.serviceAccountNamespacePath, if not present:
  • /var/run/secrets/kubernetes.io/serviceaccount/namespace

So we say that if it is not present in spring.cloud.kubernetes.client.namespace, let's do two more checks for a path. But, we do not do that when provider is null, and we defer to kubernetesClientProperties. So in one case, we check also paths, but not in the other. Also nothing close to this is done in fabric8 client.


Now, what are we going to do to properly solve this? I have been thinking about this for quite some days, and this is the PR that I propose: #860

The overall idea is this:

  • clearly deprecate the constructors that we do not use internally and only exist for backward compatibility. Document the limitation that they might impose and generally "discourage" their usage.
  • make fabric8 and k8s clients work in the same exact manner when searching for a namespace. The order is explained above.
  • k8s-client does not need structural changes, fabric8 does. As such this is a breaking change - in the sense that if someone relies on beans of the locator of fabric8 (or those classes, etc), their code will break. The chances are very slim and we can document that in the upgrade of the next version clearly.
  • throw an Exception when we can't find a namespace in the cases above (this is not done in the PR that I have mentioned), as it needs a confirmation here/talk here first
  • add proper notes on how a namespace is chosen in the documentation. Again, not done, as I would like to get some input first.
@wind57 wind57 changed the title k8s-client secrets functionality, choosing namespace choosing a namespace in a consistent fashion across fabric8 and k8s-native clients Aug 27, 2021
@wind57
Copy link
Contributor Author

wind57 commented Sep 9, 2021

@ryanjbaxter not going to nag on this one, just a friendly reminder that I am still "active" and waiting on these for further talk/resolution. no rush what-so-ever, thank you.

@ryanjbaxter ryanjbaxter linked a pull request Sep 9, 2021 that will close this issue
@ryanjbaxter
Copy link
Contributor

I merged #860 let me know if there are other PRs related to this I need to look at.

@wind57
Copy link
Contributor Author

wind57 commented Sep 10, 2021

nice. thank you for merging and thus agreeing on the proposal. the nitpick is that the PR was more of a proposal PR, it needs more things added, mainly documentation and some tests. A PR is coming soon

@wind57
Copy link
Contributor Author

wind57 commented Sep 15, 2021

@ryanjbaxter the final PR that should close this namespace subject. #865

@ryanjbaxter ryanjbaxter linked a pull request Sep 15, 2021 that will close this issue
@wind57
Copy link
Contributor Author

wind57 commented Sep 15, 2021

this can be closed as fixed.

@ryanjbaxter ryanjbaxter added this to To do in 2020.0.4 via automation Sep 15, 2021
@ryanjbaxter ryanjbaxter added this to To do in 2021.0.0-M2 via automation Sep 15, 2021
@ryanjbaxter ryanjbaxter added this to the 2.0.4 milestone Sep 15, 2021
@spencergibb spencergibb moved this from To do to Done in 2021.0.0-M2 Sep 17, 2021
@ryanjbaxter ryanjbaxter moved this from To do to Done in 2020.0.4 Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
2020.0.4
  
Done
2021.0.0-M2
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants