Skip to content

Fix 1757 #1914

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

Merged
merged 11 commits into from
May 6, 2025
Merged

Fix 1757 #1914

merged 11 commits into from
May 6, 2025

Conversation

wind57
Copy link
Contributor

@wind57 wind57 commented Apr 8, 2025

No description provided.

@@ -18,17 +18,11 @@

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("green-purple-secret.green-purple-secret-k8s.green-secret.green-secret-k8s.green-secret-prod")
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 is an example of a test that fixes the problem

@@ -390,7 +399,7 @@ public static final class Prefix {
/**
* prefix is known at the callsite.
*/
public static Prefix KNOWN;
public static Prefix KNOWN = new Prefix(() -> "", "KNOWN");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a minor bug fix, that someone was not found until now, not really related to the fix itself

@wind57 wind57 changed the title Fix 1757 a dummy try Fix 1757 May 5, 2025
@wind57
Copy link
Contributor Author

wind57 commented May 5, 2025

The entire fix of the issue is based on the fact that we can (ab)use MultipleSourcesContainer. Its definition is:

public record MultipleSourcesContainer(LinkedHashSet<String> names, Map<String, Object> data) {

What we used to do, is keep inside names things like : my-configmap, my-configmap-k8s and in the data the actual data from both configmap. We would later use this info to compute a single property source and this is what the issue is really complaining about (and for good reason).

What I am proposing to do (and it would not be a breaking change, since public APIs don't break), is to still capture in names : my-configmap, my-configmap-k8s. But, in data we capture:

{
   my-configmap : [DATA_FROM_MY_CONFIGMAP],
   my-configmap-k8s : [DATA_FROM_MY_CONFIGMAP_K8S]
}

and yes, later in the code have a few casts. The idea is that is not going to be a breaking change anymore, granted, it is a bit ugly. But this "ugliness" can be re-factored away (which I will do of course) and be merged in the next major, without the casts and to slightly adjust the code.

Everything in this PR comes from this idea, all changes are reflecting it.


I also took a chance to refactor some of the code. Over the years (I can't believe its been years tbh!), we have fixed a few issues around NamedSourceData and LabeledSourceData and things got messy there. IMHO, this:

https://github.com/spring-cloud/spring-cloud-kubernetes/blob/cf8b2d54b112658895f4cae3d7fec7eb5b480380/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/NamedSourceData.java

Now looks a lot easier to maintain.

I did the same clean-up for LabeledSourceData, just a simple flow to be able to understand the code faster.


I do understand that there are a lot of files to look at, but the vast majority are tests and if you start from the idea above, it might be not that complicated to grok them.

@ryanjbaxter

@wind57 wind57 marked this pull request as ready for review May 5, 2025 14:12
@wind57
Copy link
Contributor Author

wind57 commented May 5, 2025

btw, there is no documentation for this PR, which I wanted to make a PR immediately after this one

Signed-off-by: wind57 <[email protected]>
* When there is no data, the name of the property source is made from provided
* labels, unlike when the data is present: when we use secret names.
*/
private SourceData emptySourceData(Map<String, String> labels, String target, String namespace) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't the secret still have a name in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

imho, in this case it does not matter, as there is nothing to wire from such sources, they are empty, so this bug does not affect these cases

Copy link
Contributor

Choose a reason for hiding this comment

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

But did the name of the empty property source also have the same problem as non-empty property sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really. The name matters only when there is data also, but in this case data does not exist. Also, imo, this clearly denotes that : "we searched by these labels" and did not find anything... I hope I understood your question correctly.

sourceDataForSourceName, prefix.prefixProvider().get()));
}

if (prefix.getName().equals(Prefix.DELAYED.getName())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a delayed prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we had this for a while, I am not introducing it.

It's for the cases when you enabled "use-name-as-prefix", but the search happens based on labels, so the actual prefix is "delayed". Meaning we do not know it upfront, we will later, when we actually read by labels and find those names

Copy link
Contributor

Choose a reason for hiding this comment

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

ok i just needed a refresher because its been a while

Copy link

@jnodorp-jaconi jnodorp-jaconi left a comment

Choose a reason for hiding this comment

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

I reviewed this PR with respect to wether it fixes the issue we face (#1757), which it does.

@wind57 wind57 requested a review from ryanjbaxter May 6, 2025 14:43
@wind57
Copy link
Contributor Author

wind57 commented May 6, 2025

thank you for looking at it @jnodorp-jaconi

@ryanjbaxter ryanjbaxter linked an issue May 6, 2025 that may be closed by this pull request
@ryanjbaxter ryanjbaxter merged commit e34c892 into spring-cloud:3.1.x May 6, 2025
18 checks passed
@wind57
Copy link
Contributor Author

wind57 commented May 6, 2025

I am aware that PR failed, I am looking into why and update

@wind57
Copy link
Contributor Author

wind57 commented May 6, 2025

@ryanjbaxter all PRs failed (3.1.x , 3.2.x and main) because of some github internal issue. You might want to re-trigger builds

@ryanjbaxter
Copy link
Contributor

@wind57 yes I will try in a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use-name-as-prefix does not work as expected
4 participants