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

Fix 1592 empty source on error #1792

Merged
merged 15 commits into from
Nov 22, 2024

Conversation

wind57
Copy link
Contributor

@wind57 wind57 commented Nov 10, 2024

No description provided.

*
* @author wind57
*/
public class VisibleFabric8SecretsPropertySourceLocator extends Fabric8SecretsPropertySourceLocator {
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 one is in src/test/java and needed only for tests

* limitations under the License.
*/

package org.springframework.cloud.kubernetes.fabric8.config;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

its only in /src/test/java

@@ -162,6 +163,12 @@ else if (propertySource instanceof CompositePropertySource source) {
}

static boolean changed(List<? extends MapPropertySource> k8sSources, List<? extends MapPropertySource> appSources) {

if (k8sSources.stream().anyMatch(source -> source.getName().equals(SourceData.EMPTY_SOURCE_NAME_ON_ERROR))) {
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 actually the fix, we check to see if the source name that was generated is a well known one, that we create only when there was an error reading the configmaps/secrets from k8s

/**
* source name that is generated when there is an error reading the underlying
* configmap(s) or secret(s).
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

name to for the source when we failed reading from k8s api

Copy link
Contributor

Choose a reason for hiding this comment

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

We could have a source with this name. but I realize that might never happen. I wonder if another approach would be to subclass this class and call it ErrorSourceData and then just check if the source is an instance of that class. Thoughts?

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 exactly what I wanted to do initially, the issue is that at the time when we run a cycle, for example via polling reload, we do not deal with SourceData anymore, we deal with PropertySource(s).

Copy link
Contributor

Choose a reason for hiding this comment

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

Where does that translation from SourceData to PropertySource happen? Could we then create a ErrorPropertySource then?

Copy link
Contributor Author

@wind57 wind57 Nov 19, 2024

Choose a reason for hiding this comment

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

hmm, overall a very good idea. the issue is that SourceData is a record and that can not be extended, but I can try to add an enum to differentiate between them. I'll try to see if that is possible tomorrow and update you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so instead of having a source with a pre-defined name in case of error, add a property that would indicate that. Did I understand you correctly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for bugging you, but in this case we still need a name for it. So we have this code:

		catch (Exception e) {
			LOG.warn("failure in reading named sources");
			onException(failFast, e);
			return SourceData.emptyRecord(EMPTY_SOURCE_NAME_ON_ERROR);
		}

if we want to flip a property, we would still need to generate a name for this source data. We could have it exactly like the bug has it : configmap..default (yes, two dots there, since we do not know the name, there was an error after all).

In the end this name would be irrelevant, since we are not going to store such a property source in the environment, plus we are going to check for a property, not the name.

I just want to make sure we both are on par here

Copy link
Contributor

Choose a reason for hiding this comment

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

So really the only problem is that we log a message with funky looking name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me confused :) the problem is that in case of an error, we are going to put in our environment a property source with indeed a funky name. Putting it there means we break reload, forever from that point in time. And while writing this comment, I realized that your previous comment makes total sense and I can definitely flip a property...

I'll do that tomorrow

@@ -69,7 +70,9 @@ public final SourceData compute(String sourceName, ConfigUtils.Prefix prefix, St

}
catch (Exception e) {
LOG.warn("failure in reading named sources");
onException(failFast, e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in case of Exception, return a source with a known name that later can be checked for

@@ -54,28 +54,54 @@ class KubernetesClientSecretsPropertySourceLocatorTests {

private static final String LIST_API = "/api/v1/namespaces/default/secrets";

private static final String LIST_BODY = "{\n" + "\t\"kind\": \"SecretList\",\n" + "\t\"apiVersion\": \"v1\",\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just formatting, nothing else changed here

@@ -80,28 +80,54 @@ class KubernetesClientSecretsPropertySourceTests {

private static final String LIST_API_WITH_LABEL = "/api/v1/namespaces/default/secrets";

private static final String LIST_BODY = "{\n" + "\t\"kind\": \"SecretList\",\n" + "\t\"apiVersion\": \"v1\",\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

formatting only

@wind57 wind57 marked this pull request as ready for review November 19, 2024 08:10
@wind57
Copy link
Contributor Author

wind57 commented Nov 19, 2024

@ryanjbaxter this is ready to be looked at. The fix itself is not complicated, but testing was, since I did not want to add integration tests. Thank you

@ryanjbaxter
Copy link
Contributor

I LIKE IT!

@wind57
Copy link
Contributor Author

wind57 commented Nov 22, 2024

@ryanjbaxter this one is ready, but please do not close the bug just yet, because I need to look at something more, another minor PR might be needed. I will let you know

@ryanjbaxter ryanjbaxter merged commit b47f91d into spring-cloud:3.1.x Nov 22, 2024
13 checks passed
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.

In rare scenarios ConfigMap update is not updated using polling strategy
3 participants