-
Notifications
You must be signed in to change notification settings - Fork 222
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
WIP: unify configuration #1440
Conversation
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.
6b1a0d4
to
46dea02
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this 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):
-
The
DependentResourceConfigurator
does not seems to be used anywhere directly, it's always at the end it's subinterface:AnnotationDependentResourceConfigurator
-
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 havingDependentResourceConfigurator
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
It was kept for backwards compatibility.
That's an interesting idea but won't that make things complex to process because you'd need to do meta-annotation processing? |
Superseded by #1532 |