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

discriminator improvements #2013

Merged
merged 4 commits into from
Aug 14, 2023
Merged

discriminator improvements #2013

merged 4 commits into from
Aug 14, 2023

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Aug 11, 2023

No description provided.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 11, 2023
@csviri csviri self-assigned this Aug 11, 2023
@csviri csviri linked an issue Aug 11, 2023 that may be closed by this pull request
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;

public class IndexDiscriminator<R extends HasMetadata, P extends HasMetadata>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some documentation to explain what this does and why it's useful would be helpful for users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@metacosm
Copy link
Collaborator

LGTM otherwise.

@csviri csviri requested a review from metacosm August 11, 2023 10:41
@csviri
Copy link
Collaborator Author

csviri commented Aug 11, 2023

cc @shawkins

@csviri csviri marked this pull request as ready for review August 11, 2023 10:43
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 11, 2023
@shawkins
Copy link
Collaborator

With simple usage we'll have something like:

@ControllerConfiguration(
    dependents = {
        @Dependent(type = KeycloakServiceDependentResource.class, useEventSourceWithName = "serviceSource"),
        @Dependent(type = KeycloakDiscoveryServiceDependentResource.class, useEventSourceWithName = "serviceSource")
    })
...

Then

@KubernetesDependent(labelSelector = Constants.DEFAULT_LABELS_AS_STRING, resourceDiscriminator = KeycloakDiscoveryServiceDependentResource.NameResourceDiscriminator.class)
public class KeycloakDiscoveryServiceDependentResource extends CRUDKubernetesDependentResource<Service, Keycloak> {

    public static class NameResourceDiscriminator extends ResourceIDMatcherDiscriminator<Service, Keycloak>
        public NameResourceDiscriminator() {
            super("serviceSource", KeycloakDiscoveryServiceDependentResource::getName);
        } 
    }

   ...

Creating a constant for the event source name will help, but it looks like we've spread some knowledge in two places. Can we instead do:

@KubernetesDependent(labelSelector = Constants.DEFAULT_LABELS_AS_STRING)
public class KeycloakDiscoveryServiceDependentResource extends CRUDKubernetesDependentResource<Service, Keycloak> implements ResourceDiscriminatorInitializer<Service, Keycloak> {

    public void useEventSourceWithName(String name) {
        super.useEventSourceWithName(name);
        setResourceDiscriminator(new ResourceIDMatcherDiscriminator<>(name, KeycloakDiscoveryServiceDependentResource::getName));
    }
    ...

Or are methods like useEventSourceWithName not to be tampered with?

@csviri
Copy link
Collaborator Author

csviri commented Aug 11, 2023

Wasn't really tested that way. TBH I don't like that much this annotation style definitions, basically because of these inflexibilities. But it is how it is, we can think to change appraoches for v5.

return context.getSecondaryResourcesAsStream(resource)
.filter(resourceID::isSameResource)
.findFirst();
if (eventSourceName != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the keycloak case there is only a single Service event source, so eventSourceName doesn't seem required in all cases. Could it test for, or catch the exception, if there are multiple sources for the given type before resorting to the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, changed, pls check if this looks to you

Copy link
Collaborator

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

LGTM, this latest change helps side step the issue of passing around the eventSourceName.

@csviri
Copy link
Collaborator Author

csviri commented Aug 14, 2023

LGTM, this latest change helps side step the issue of passing around the eventSourceName.

Originally tbh was thinking that since discriminators are just used with DR with "same type", that means not with bulk resources for example, there will be always a very small amount of them, but it's still true that it's better not loop though of those.

@csviri csviri merged commit d7b5b87 into next Aug 14, 2023
17 checks passed
@csviri csviri deleted the discriminator-improvements branch August 14, 2023 12:17
csviri added a commit that referenced this pull request Aug 15, 2023
csviri added a commit that referenced this pull request Aug 22, 2023
csviri added a commit that referenced this pull request Aug 28, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Aug 29, 2023
csviri added a commit that referenced this pull request Aug 29, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 4, 2023
csviri added a commit that referenced this pull request Sep 4, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 4, 2023
csviri added a commit that referenced this pull request Sep 4, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
csviri added a commit that referenced this pull request Sep 4, 2023
csviri added a commit that referenced this pull request Sep 4, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
csviri added a commit that referenced this pull request Sep 4, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 4, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 11, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 11, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 12, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 12, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
metacosm pushed a commit that referenced this pull request Sep 15, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
metacosm pushed a commit that referenced this pull request Sep 15, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 18, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 18, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 18, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Sep 18, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Oct 3, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Oct 3, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
shawkins added a commit to shawkins/java-operator-sdk that referenced this pull request Oct 4, 2023
* feat: create resource only if not exists (operator-framework#2001)

* feat: leader election callbacks (operator-framework#2015)

* discriminator improvements (operator-framework#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Steve Hawkins <[email protected]>
csviri added a commit that referenced this pull request Oct 4, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Oct 4, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Oct 18, 2023
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
csviri added a commit that referenced this pull request Oct 18, 2023
* feat: create resource only if not exists (#2001)

* feat: leader election callbacks (#2015)

* discriminator improvements (#2013)

* generalization of the update matcher

* consolidating the diffs

also adding a test that removes a field not present in the desired

---------

Co-authored-by: Attila Mészáros <[email protected]>
Signed-off-by: csviri <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
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.

Add the ability to directly discrimate on name
3 participants