Skip to content

redesign #906

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

Merged
merged 7 commits into from
Feb 4, 2022
Merged

redesign #906

merged 7 commits into from
Feb 4, 2022

Conversation

metacosm
Copy link
Collaborator

@metacosm metacosm commented Feb 3, 2022

  • fix: fail explicitly if current namespace is requested but not available
  • fix: retain annotation for reflective access
  • feat: add desired and matches methods on DependentResource

@metacosm metacosm self-assigned this Feb 3, 2022
@metacosm metacosm requested a review from csviri February 3, 2022 08:56
* the specified primary resource, {@code false} otherwise
*/
default boolean match(R actual, P primary, Context context) {
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't we use equals here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, see the javadoc 😉

Copy link
Collaborator

Choose a reason for hiding this comment

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

for typical Kubernetes resource implementations, simply calling
   * {@code desired(primary, context).equals(actual)} is not enough because metadata will usually be
   * different.

This is true, but in a default implementation I would just compare specs. And in reconcile, would merge the target resource with the actual from the server. Thus just override the spec, add other fields if new to metadata (and override if some is generated). Would also make this behavior customizable (already is, some can override), to make a custom comaparator.

  * The default implementation always return {@code true}, which corresponds to the behavior where
   * the dependent never needs to be updated after it's been created.   

Why should be this the default?

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 true, but in a default implementation I would just compare specs. And in reconcile, would merge the target resource with the actual from the server. Thus just override the spec, add other fields if new to metadata (and override if some is generated). Would also make this behavior customizable (already is, some can override), to make a custom comaparator.

That's a good point

Why should be this the default?

Why shouldn't it? 😄
More seriously what do you think the default behavior should be? Not updating the resource after it's been created sounds like a reasonable default which covers a lot of use cases (for example, pretty much all our samples), imo.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The default should be to generate the target default with desired, and compare the specs.

The reason is that I think the default use case should be what we have in WebPage (what actally needs some cleanup), but basically that the reconciler manages all the resources. That is not that strong assumption IMHO, sure there are cases where not, but this would be quite sensible default.

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.

LGTM


private final Builder<R, P> builder;
private final Updater<R, P> updater;
private final Cleaner<R, P> cleaner;
private final Persister<R, P> persister;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need the persister?

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 for non-Kubernetes resources, see the MySQL sample

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 it make sense for kubernetes objects; maybe we should have this just implicit in the reconcile function. Or just have it for a subclass for non-kubernetes objects and get called from reconcile in that impl.

Copy link
Collaborator Author

@metacosm metacosm Feb 3, 2022

Choose a reason for hiding this comment

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

Kubernetes resources get one automatically

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could probably remove the Persister interface but I think that would require people defining Kubernetes dependents to either extend a class that would provide the behavior as it exists right now or do more work to implement the methods that are currently in Persister.

* (or ever)
*/
default Optional<R> desired(P primary, Context context) {
return Optional.empty();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should not have a default implementation.

The most common case is like in the WebPage, when all the resources are managed by the operator, IMHO that should be the default approach. If the resource is not managed by us (so not created and not updated) should be probably a feature flag/mode on the resources. Maybe eventually a different type of resource.

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 I follow. If we're not creating, nor updating the resource, why would it even be a dependent?

Copy link
Collaborator

Choose a reason for hiding this comment

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

To get input from it, like not sure from nodes or other configurations of the cluster. But something like this happens also in the tomcat example too if remember correctly.

@csviri
Copy link
Collaborator

csviri commented Feb 4, 2022

Made one more comment, I think we can merge it. Made a comment, but probably the best appraoch would be to fine tune it in a subsequent PRs.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

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

29.3% 29.3% Coverage
0.8% 0.8% Duplication

@metacosm metacosm marked this pull request as ready for review February 4, 2022 14:15
@metacosm metacosm merged commit 6ee3173 into next Feb 4, 2022
@metacosm metacosm deleted the redesign branch February 4, 2022 14:18
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