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

Simplify config data code a bit (CAN ONLY GO IN THE NEXT MAJOR RELEASE) #1189

Draft
wants to merge 370 commits into
base: main
Choose a base branch
from

Conversation

wind57
Copy link
Contributor

@wind57 wind57 commented Dec 30, 2022

No description provided.

bootstrapContext.registerIfAbsent(cls, BootstrapRegistry.InstanceSupplier.of(instance));
bootstrapContext.addCloseListener(event -> event.getApplicationContext().getBeanFactory()
.registerSingleton(name, event.getBootstrapContext().get(cls)));
if (instance != null && !bootstrapContext.isRegistered(cls)) {
Copy link
Contributor Author

@wind57 wind57 Dec 30, 2022

Choose a reason for hiding this comment

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

I've done two things here:

  • check if instance that is passed is null, so that it slightly simplifies callers.
  • check if class is already registered with !bootstrapContext.isRegistered(cls). We were already doing that via regsiterIfAbsent, but than we were calling addCloseListener, no matter if it was registered or not. Not a big deal, but this is cleaner, imo.

*
* holds properties needed for ConfigData.
*/
record Properties(KubernetesClientProperties clientProperties, ConfigMapConfigProperties configMapProperties,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted a class that deals with properties only, so that all properties are computed in a single place. The code has not changed at all, it was just moved to this class from other places and moved to a separate package.

&& secretsProperties.failFast();
}

private KubernetesNamespaceProvider kubernetesNamespaceProvider(Environment environment) {
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 was protected and overridden in both fabric8 and k8s-native clients, but the overridden version was exactly the same. Most probably an artifact of an initial thought process. I made it private here and dropped the methods in clients.

@@ -49,11 +49,10 @@ public Fabric8ConfigDataLocationResolver(DeferredLogFactory factory) {

@Override
protected void registerBeans(ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location,
Profiles profiles, KubernetesConfigDataLocationResolver.PropertyHolder propertyHolder,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it used to be KubernetesConfigDataLocationResolver.PropertyHolder and now it is ConfigDataProperties

ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles)
throws ConfigDataLocationNotFoundException {

ConfigDataProperties properties = ConfigDataProperties.of(resolverContext).register();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the logic in this class stays exactly the same, but now it's a lot shorter and easier to read. ConfigDataProperties.of(resolverContext).register() this both computed all 3 properties needed (client, configmap and secret ones) + registers them.

public record ConfigDataProperties(KubernetesClientProperties clientProperties,
ConfigMapConfigProperties configMapProperties, SecretsConfigProperties secretsProperties) {

static Registrar of(ConfigDataLocationResolverContext context) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the idea here is once you call of, the only option you have after is register (this is partial functions kind of), which will register the properties and give them back in form of the ConfigDataProperties instance. My sole purpose of the PR was around this thing, mainly, to decouple and make configdata slightly easier to reason about.

@wind57 wind57 changed the title Simplify config data code a bit Simplify config data code a bit (CAN ONLY GO IN THE NEXT MAJOR RELEASE) Dec 30, 2022
@@ -88,14 +86,6 @@ List<String> getAcceptedProfiles() {
return this.profiles.getAccepted();
}

public void setLog(Log log) {
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 are not using these, so I decided to remove them

return new KubernetesNamespaceProvider(environment);
}

private Environment environment(Map<String, Object> kubernetesConfigData, Profiles profiles) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

extract to a separate method, making resolveProfileSpecific even easier to read

wind57 added 17 commits May 22, 2023 18:18
wind57 added 30 commits June 11, 2024 07:18
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.

3 participants