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

Fabric8 LeaderProperties.getNamespace(defaultValue) no longer falls back to given default when namespace is undefined #1661

Closed
kzander91 opened this issue May 31, 2024 · 2 comments · Fixed by #1662
Labels
Milestone

Comments

@kzander91
Copy link

kzander91 commented May 31, 2024

Describe the bug
Starting with Spring Cloud 2023.0.2/Spring Cloud Kubernetes 3.1.2, LeaderProperties.getNamespace(String default) is broken. As of commit 53fa5555, the method no longer falls back to the given defaultValue when namespace is not defined.

With 3.1.1, we return the defaultValue if the namespace is undefined (as expected):

public String getNamespace(String defaultValue) {
if (this.namespace == null || this.namespace.isEmpty()) {
return defaultValue;
}
return this.namespace;
}

With 3.1.2, we return the namespace if the defaultValue is defined (unexpected):
public String getNamespace(String defaultValue) {
if (!StringUtils.hasText(defaultValue)) {
return defaultValue;
}
return namespace;
}

This was likely the intention:

public String getNamespace(String defaultValue) {
	if (!StringUtils.hasText(namespace)) {
		return defaultValue;
	}

	return namespace;
}

Applications that are not configuring spring.cloud.kubernetes.leader.namespace explicitly, relying on the auto-detected current namespace as the default will no longer work.

This is was accidentally introduced by the Fabric8 Leader refactoring made with #1648.

Impact
My application fails to start with this error:

io.fabric8.kubernetes.client.KubernetesClientException: namespace cannot be null
	at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.inNamespace(BaseOperation.java:252)
	at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.inNamespace(BaseOperation.java:97)
	at org.springframework.cloud.kubernetes.fabric8.leader.Fabric8LeaderRecordWatcher.lambda$start$1(Fabric8LeaderRecordWatcher.java:63)
	at org.springframework.cloud.kubernetes.commons.leader.LeaderUtils.guarded(LeaderUtils.java:51)
	at org.springframework.cloud.kubernetes.fabric8.leader.Fabric8LeaderRecordWatcher.start(Fabric8LeaderRecordWatcher.java:59)
	at org.springframework.cloud.kubernetes.commons.leader.LeaderInitiator.start(LeaderInitiator.java:62)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:288)
@kzander91 kzander91 changed the title Fabric8 LeaderProperties no longer auto-detect the current Kubernetes Namespace Fabric8 LeaderProperties.getNamespace(defaultValue) no longer falls back to given default when namespace is undefined May 31, 2024
@wind57
Copy link
Contributor

wind57 commented May 31, 2024

oh snap! you're right, I introduced this one.

I'll fix it and add tests for it, apparently we had none covering this case...

Thank you for raising this!

@ryanjbaxter can you add the bug label here please?

@wind57
Copy link
Contributor

wind57 commented Jun 5, 2024

I have a fix ready here

Also, I am trying to get a different (native) approach on the leader election process here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants