question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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: https://github.com/spring-cloud/spring-cloud-kubernetes/pull/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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wind57commented, 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

0reactions
wind57commented, Sep 15, 2021

this can be closed as fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing deployments, namespace and services in ... - Medium
Managing deployments, namespace and services in Kubernetes using Fabric8 client — Java. Dynamic way to create, delete and scale your applications using fabric8....
Read more >
Spring Cloud 2020.0.4 has been released
Spring Cloud Kubernetes. Choose namespace in a consistent fashion across fabric8 and k8s-native clients (#859). The following modules were ...
Read more >
Accessing Kubernetes Programatically - Think Microservices
PodList pods = api.pods().inAnyNamespace().list(); Unless you have a compulsion to count method arguments, the fabric8 client is easier to write ...
Read more >
homebrew-core - Homebrew Formulae
a2ps 4.14 Any‑to‑PostScript filter aacgain 1.8 AAC‑supporting version of mp3gain aalib 1.4rc5 Portable ASCII art graphics library aamath 0.3 Renders mathematical expressions as ASCII art
Read more >
DevConf.IN'19: Full Schedule
Some users / customers want to leverage more than one OpenShift cluster in their ... like Kubernetes and Red Hat Openshift, using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found