Skip to content

Dependent resources implementation #785

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 1 commit into from
Closed

Conversation

metacosm
Copy link
Collaborator

@metacosm metacosm commented Jan 3, 2022

Fixes #771

@metacosm metacosm self-assigned this Jan 3, 2022
@metacosm metacosm requested a review from csviri January 3, 2022 20:18
@metacosm metacosm marked this pull request as draft January 3, 2022 20:18
@metacosm metacosm force-pushed the dependent-resources-2 branch from 066e0fc to 300dbb6 Compare January 5, 2022 21:24
@metacosm metacosm force-pushed the dependent-resources-2 branch 3 times, most recently from dbab033 to 36df956 Compare January 7, 2022 17:31
@metacosm metacosm changed the title WIP: new dependent resources implementation Dependent resources implementation Jan 8, 2022
@metacosm metacosm marked this pull request as ready for review January 8, 2022 16:12
@metacosm metacosm force-pushed the dependent-resources-2 branch 4 times, most recently from d4ca4f4 to 3b7b59b Compare January 13, 2022 10:11
@csviri
Copy link
Collaborator

csviri commented Jan 13, 2022

One thing that popped up is that even for kubernetes resources we will need ordering, or the "depends on" notion. Like to create resource when other is already up and running.

@metacosm
Copy link
Collaborator Author

This implicitly managed at the moment by the declaring order of the dependents but we should probably make it explicit, indeed. That said, one step at a time. Let's get initial support in and then see what else is needed.

@csviri
Copy link
Collaborator

csviri commented Jan 13, 2022

This implicitly managed at the moment by the declaring order of the dependents but we should probably make it explicit, indeed. That said, one step at a time. Let's get initial support in and then see what else is needed.

yep, lets do this in interations. But this "depends-on" notions, makes a good selling point, without it it's not more powerful than a helm chart.

@metacosm
Copy link
Collaborator Author

This implicitly managed at the moment by the declaring order of the dependents but we should probably make it explicit, indeed. That said, one step at a time. Let's get initial support in and then see what else is needed.

yep, lets do this in interations. But this "depends-on" notions, makes a good selling point, without it it's not more powerful than a helm chart.

I beg to differ. You cannot reconcile dependent resources with a helm chart. It's a lot more complex than just installing dependent resources, it's also about managing them as they evolve at runtime.

@csviri
Copy link
Collaborator

csviri commented Jan 17, 2022

I beg to differ. You cannot reconcile dependent resources with a helm chart. It's a lot more complex than just installing dependent resources, it's also about managing them as they evolve at runtime.

What I mean is, that helm charts handles re-apply / changes nicely. It handles when you just apply a list or resources. What does not handle is the situation when you want to "create a resource after an other resource is in a certain state". Basically this is an analogy to depends_on from terraform.

tomcat.getMetadata().getName(),
tomcat.getMetadata().getNamespace(),
tomcat.getStatus().getReadyReplicas());
return UpdateControl.updateStatus(updatedTomcat);

Choose a reason for hiding this comment

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

Is the update method from the DependentResource called at this point ? like https://github.com/java-operator-sdk/java-operator-sdk/pull/785/files#diff-06a1ae70b5e55bf828c2120ae4525d9ad22cb82b526c6db644472ad46698f6f9R47
And how does it work when we have more than one secondary resource (like having 3 deployments) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At the moment the dependent resources are reconciled before we reconcile the primary one so any dependent needed to be created is created before the primary reconciler is called, similarly, any updates to secondary resources will be processed before the primary resource is reconciled.

We don't currently handle the case where you have several dependents of the same type very well. The previous version of the implementation allowed you to add a qualifier to your dependent definition specifically for this case. We have a name on EventSource for that purpose but it should indeed be exposed to the annotation.


import java.util.Optional;

public interface AttributeHolder {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that this is used in the context only. WHat is the purpose here? Maybe describe it also in javadoc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is also used by the EventSourceContext

@@ -0,0 +1,5 @@
package io.javaoperatorsdk.operator.api.reconciler;

public interface EventSourceContextInjector {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be probably a generics on the EvenSourceContext not sure if also on the interface itself too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure I understand here…

Copy link
Collaborator

Choose a reason for hiding this comment

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

IntelliJ complains that EventSourceContext is without a generics

}

@SuppressWarnings("unchecked")
protected Persister<R, P> initPersister(DependentResource<R, P> delegate) {
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 about this part, if it needs to implement persister why it can be configured separatelly. Also why is not directly on DependentResource

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure either anymore, tbh… 😅

extends DefaultResourceConfiguration<R> {

private final PrimaryResourcesRetriever<R> secondaryToPrimaryResourcesIdSet;
private final AssociatedSecondaryResourceIdentifier<P> associatedWith;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not abbe associatedDependentResource?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what you mean…

Copy link
Collaborator

@csviri csviri Jan 21, 2022

Choose a reason for hiding this comment

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

It's about naming, but I;m probably wrong. So I guess it's already this way to some extent, but:

  1. The resources that are managed by dependent resources we can call "dependent resources"
  2. And the secondary resource that is the resource managed by te controller by not the dependent resources mecahnism directly?

Or should not be rather managed dependent resource and dependent resources?
So sometimes the naming is confusing for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The naming is indeed not great… we should probably settle on using dependent or secondary everywhere.

import io.javaoperatorsdk.operator.processing.event.source.ResourceCache;
import io.javaoperatorsdk.operator.processing.event.source.UpdatableCache;

public class InformerManager<T extends HasMetadata, C extends ResourceConfiguration<T>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing Unit tests.

private final AssociatedSecondaryResourceIdentifier<P> associatedWith;
private final boolean skipUpdateEventPropagationIfNoChange;

public InformerConfiguration(ConfigurationService service, String labelSelector,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The configuration service is a little bit weird here a little bit. Especially if somebody wants to create an Informer without Depdendent resources.

@csviri
Copy link
Collaborator

csviri commented Jan 20, 2022

It's not easy to review this big change. What I would like (maybe just temporarily) is also have there the samples without the dependent resources. Since there are some places, where it's not clear (like the informers) how that would work without dependent resources. So that would help.

Also miss unit tests in some cases.

@csviri
Copy link
Collaborator

csviri commented Jan 20, 2022

So a goal should be also to preserve the current "low" level API clear and available. Ideally make it clear where is the difference.

@csviri
Copy link
Collaborator

csviri commented Jan 20, 2022

Also we should add docs soons, this is clear how to use. Also update the internal docs:

https://javaoperatorsdk.io/docs/architecture-and-internals

Since this is quite massive change.

@csviri
Copy link
Collaborator

csviri commented Jan 20, 2022

Pls add also the description of the scope this PR.

@metacosm
Copy link
Collaborator Author

Pls add also the description of the scope this PR.

I need to update it but the scope is defined in #771.

@metacosm
Copy link
Collaborator Author

So a goal should be also to preserve the current "low" level API clear and available. Ideally make it clear where is the difference.

As mentioned several times already, this is completely opt-in. If you don't want to use the dependent resources support, you can keep doing what was done before.

@metacosm
Copy link
Collaborator Author

It's not easy to review this big change. What I would like (maybe just temporarily) is also have there the samples without the dependent resources. Since there are some places, where it's not clear (like the informers) how that would work without dependent resources. So that would help.

Easy enough: there is no change. You can use the previous version of the examples without any issue because this is completely opt-in.

Also miss unit tests in some cases.

Definitely but that will come after the approach is validated.

@csviri
Copy link
Collaborator

csviri commented Jan 20, 2022

It's not easy to review this big change. What I would like (maybe just temporarily) is also have there the samples without the dependent resources. Since there are some places, where it's not clear (like the informers) how that would work without dependent resources. So that would help.

Easy enough: there is no change. You can use the previous version of the examples without any issue because this is completely opt-in.

Also miss unit tests in some cases.

Definitely but that will come after the approach is validated.

I commented in one place the InformerEventSource for example seems to have completetly different API

- Kubernetes-native resources are automatically handled without users
  having to deal with explicit event sources
- Reconcilers and event sources can exchange information via the
  `EventSourceContext`
- Declarative management is completely opt-in and can cohabit with
  "traditional" handling i.e. it's possible to have only part of the
  dependents being declared via annotations and others explicitly
  handled (though from a maintenance perspective it's better to stick
  to one approach or the other)
@metacosm metacosm force-pushed the dependent-resources-2 branch from cadae26 to 7f1cdca Compare January 21, 2022 12:53
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 19 Code Smells

28.0% 28.0% Coverage
0.9% 0.9% Duplication

@metacosm
Copy link
Collaborator Author

metacosm commented Jan 21, 2022

This PR is now merged in the next branch where we will work on the next 2.1 release.

@metacosm metacosm closed this Jan 21, 2022
@metacosm metacosm deleted the dependent-resources-2 branch January 21, 2022 12:57
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.

Dependent resources initial support
3 participants