Skip to content

WIP: unify configuration #1440

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

Closed
wants to merge 8 commits into from
Closed

WIP: unify configuration #1440

wants to merge 8 commits into from

Conversation

metacosm
Copy link
Collaborator

@metacosm metacosm commented Sep 2, 2022

  • refactor: cleaner separation between instantiation and configuration
  • refactor: move instantiation functionality to Utils
  • refactor: unify context information creation, move it to Utils
  • refactor: improve getFirstTypeArgumentFromInterface
  • feat: introduce AnnotationDependentResourceConfigurator concept

The idea is to be able to configure dependents using annotations
directly so that we can remove the special handling of
KubernetesDependentResource from AnnotationControllerConfiguration. This
results in dependent resources being instantiated and configured
directly when processed from the annotations in the managed case, thus
rendering the DependentResourceFactory concept obsolete. This should
also lead to further simplification later.
@metacosm metacosm force-pushed the unify-configuration branch from 6b1a0d4 to 46dea02 Compare September 5, 2022 07:56
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 12 Code Smells

67.8% 67.8% Coverage
0.0% 0.0% Duplication

Base automatically changed from next to main September 5, 2022 08:14
Copy link
Collaborator

@csviri csviri left a comment

Choose a reason for hiding this comment

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

Overall about the dynamic configuration and unification, what is a very good idea IMO, just few points / tech details (other than the comments):

  1. The DependentResourceConfigurator does not seems to be used anywhere directly, it's always at the end it's subinterface: AnnotationDependentResourceConfigurator

  2. What AnnotationDependentResourceConfigurator does it basically two responsibilities, creates the configuration from from annotation, and marks that which annotation is related to that configuration.
    Could we decouple this? Like having DependentResourceConfigurator interface, that receives the configuration. It does not need to be annotation it can go just from an override or anything. But would separate the creation maybe of the confoguration from annotation. One way would be maybe with a nice(?) is to put an new annotation for the configuration annotation, that says how to produce a config from this annotation. Like for @SchemaConfig:

@ConfigInput(configFactory = AnnotationSchemaConfigFactory.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface SchemaConfig {
 
  int pollPeriod() default DEFAULT_POLL_PERIOD;

 // omitted 
}

It will create the configuration instance from this annotation, calling a method on the factory: AnnotationSchemaConfigFactory

@@ -140,8 +140,9 @@ default ObjectMapper getObjectMapper() {
return Serialization.jsonMapper();
}

@Deprecated(forRemoval = true)
default DependentResourceFactory dependentResourceFactory() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if understand this. It's null since not used anymore I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Backwards compatibility :)

@@ -1,5 +1,9 @@
package io.javaoperatorsdk.operator.api.reconciler.dependent.managed;

import java.util.Optional;

public interface DependentResourceConfigurator<C> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really get this interface, it both can receive and produce a configuration? Its because AnnotationDependentResourceConfigurator needs to be supported to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Backwards compatibility.

@@ -24,13 +26,18 @@
import static io.javaoperatorsdk.operator.sample.dependent.SecretDependentResource.MYSQL_SECRET_USERNAME;
import static java.lang.String.format;

@SchemaConfig(pollPeriod = 700, host = "127.0.0.1",
port = SchemaDependentResource.LOCAL_PORT,
user = "root", password = "password") // NOSONAR: password is only used locally, example only
public class SchemaDependentResource
extends PerResourcePollingDependentResource<Schema, MySQLSchema>
implements EventSourceProvider<MySQLSchema>,
DependentResourceConfigurator<ResourcePollerConfig>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this can be removed, it's enough just to have AnnotationDependentResourceConfigurator ?

Copy link
Collaborator Author

@metacosm metacosm Sep 6, 2022

Choose a reason for hiding this comment

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

It is, but I wanted to make things backwards-compatible. Removing that constraint would simplify several things, actually.

@@ -24,13 +26,18 @@
import static io.javaoperatorsdk.operator.sample.dependent.SecretDependentResource.MYSQL_SECRET_USERNAME;
import static java.lang.String.format;

@SchemaConfig(pollPeriod = 700, host = "127.0.0.1",
port = SchemaDependentResource.LOCAL_PORT,
user = "root", password = "password") // NOSONAR: password is only used locally, example only
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the password here should have some placeholder value for "not set"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this isn't a realistic implementation, just showing here how it is possible to also use annotations to configure dependents.

@metacosm
Copy link
Collaborator Author

metacosm commented Sep 6, 2022

Overall about the dynamic configuration and unification, what is a very good idea IMO, just few points / tech details (other than the comments):

  1. The DependentResourceConfigurator does not seems to be used anywhere directly, it's always at the end it's subinterface: AnnotationDependentResourceConfigurator

It was kept for backwards compatibility.

  1. What AnnotationDependentResourceConfigurator does it basically two responsibilities, creates the configuration from from annotation, and marks that which annotation is related to that configuration.
    Could we decouple this? Like having DependentResourceConfigurator interface, that receives the configuration. It does not need to be annotation it can go just from an override or anything. But would separate the creation maybe of the confoguration from annotation. One way would be maybe with a nice(?) is to put an new annotation for the configuration annotation, that says how to produce a config from this annotation. Like for @SchemaConfig:
@ConfigInput(configFactory = AnnotationSchemaConfigFactory.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface SchemaConfig {
 
  int pollPeriod() default DEFAULT_POLL_PERIOD;

 // omitted 
}

It will create the configuration instance from this annotation, calling a method on the factory: AnnotationSchemaConfigFactory

That's an interesting idea but won't that make things complex to process because you'd need to do meta-annotation processing?

@metacosm
Copy link
Collaborator Author

metacosm commented Oct 7, 2022

Superseded by #1532

@metacosm metacosm closed this Oct 7, 2022
@metacosm metacosm deleted the unify-configuration branch October 7, 2022 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants