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

feat: sanitization of resources for matching #2042

Merged
merged 15 commits into from
Sep 12, 2023
Merged

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Sep 4, 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 Sep 4, 2023
@csviri csviri self-assigned this Sep 4, 2023
@csviri csviri force-pushed the automatic-corrections-dr branch from c0724cf to 3a352e1 Compare September 4, 2023 12:02
@csviri csviri linked an issue Sep 4, 2023 that may be closed by this pull request
@csviri csviri requested review from shawkins and metacosm September 4, 2023 12:03
@csviri
Copy link
Collaborator Author

csviri commented Sep 4, 2023

@metacosm @shawkins this is how we could fill data that is making mess now with SSA matching ( preprocess desired ). Pls let me know what do you think, we can discuss if we want to go this way.
Also make some checks on known issues

Also this is something that we would be able to turn off by feature flag.

@shawkins
Copy link
Collaborator

shawkins commented Sep 5, 2023

I'd still advocate for something like that update filter which will check to see if old and new are the same to help prevent reconciliation loops - with logging it could also help to capture additional cases that would need to be addressed by something like this pr.

Another consideration is making the use of SSA type based - in particular for Secrets. Upstream they certainly didn't feel there was much need to use SSA for every kind.

@@ -189,7 +192,11 @@ protected void addMetadata(boolean forMatch, R actualResource, final R target, P
addReferenceHandlingMetadata(target, primary);
}

private boolean useSSA(Context<P> context) {
protected void sanitizeDesired(R desired, R actual, P primary, Context<P> context) {
DesiredResourceSanitizer.sanitizeDesired(desired, actual, primary, context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Design-wise, this shouldn't be a static call, but rather a per-type instance so that we use polymorphism instead of having a big if-else cascade based on type with a default no-op being used in most cases.

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 would not complicate that for now, until this is small, we can refactor when we have more of it.

@csviri
Copy link
Collaborator Author

csviri commented Sep 6, 2023

I'd still advocate for something like that update filter which will check to see if old and new are the same to help prevent reconciliation loops - with logging it could also help to capture additional cases that would need to be addressed by something like this pr.

yes, this is also something that we should consider, but also these are not necessary mutual exclusive, or? I mean the reconciliation will be triggered by other sources and then matching will fail.

Another consideration is making the use of SSA type based - in particular for Secrets. Upstream they certainly didn't feel there was much need to use SSA for every kind.

This is a good question/point, how should we approach that case. If we don't really advise to do SSA for certain resource type. Should be this something pre-configured? or just documented?

@shawkins
Copy link
Collaborator

shawkins commented Sep 6, 2023

yes, this is also something that we should consider, but also these are not necessary mutual exclusive, or? I mean the reconciliation will be triggered by other sources and then matching will fail.

I'm not saying they are exclusive - just want to make sure it's included in comprehensively addressing the problems.

There is the problem behavior of performing a SSA when one is not needed. There are two possible consequences:

  • nothing happens on the server side, which the kubernetes folks say should have about the same performance as a get call. So avoiding this is good, but it will really only cause users problem in situations where there's a lot of api server load.
  • a new revision is created (that's the behavior that's been noted with at least Secrets, Ingress). This is dangerous as it can cause the operator sdk to simply keep reconciling.

@metacosm
Copy link
Collaborator

metacosm commented Sep 6, 2023

To me, all this is sounding like SSA is not really ready for mainstream usage. It's too fraught with subtleties and edge cases that can get you in trouble.

@csviri
Copy link
Collaborator Author

csviri commented Sep 6, 2023

I'm not saying they are exclusive - just want to make sure it's included in comprehensively addressing the problems.

Yes, I think there is a separate PR for that, I agree with that part, only we have to take a look there to automatically add such filter and put it behind a feature flag.

@shawkins
Copy link
Collaborator

shawkins commented Sep 6, 2023

This is a good question/point, how should we approach that case. If we don't really advise to do SSA for certain resource type. Should be this something pre-configured? or just documented?

I'd opt for pre-configured in the case of Secrets rather than defaulting to an error condition if stringData is used. Out of an abundance of caution, ConfigMaps should be treated similarly.

To me, all this is sounding like SSA is not really ready for mainstream usage. It's too fraught with subtleties and edge cases that can get you in trouble.

Right and the feedback upstream is just to not use it when it's not working as expected.

An alternative is to change SSA to opt-in per DR rather than opt-out.

@csviri
Copy link
Collaborator Author

csviri commented Sep 6, 2023

I'd opt for pre-configured in the case of Secrets rather than defaulting to an error condition if stringData is used. Out of an abundance of caution, ConfigMaps should be treated similarly.

I think those are two different things again. I agree that we could say that Secrets and config maps by default should not use SSA. But if we introduce a feature flag, someone could turn it on and still use stringData, than we can still throw the exception, but if some does not use the string data is should work as expected.

In other words I prefer such documentation as a code, if it does not bring too much complexity.

@shawkins
Copy link
Collaborator

shawkins commented Sep 6, 2023

I think those are two different things again.

Not entirely. In practical terms, what is the advantage of using SSA with a Secret? I'd argue that it's very minimal.

@csviri
Copy link
Collaborator Author

csviri commented Sep 7, 2023

I think those are two different things again.

Not entirely. In practical terms, what is the advantage of using SSA with a Secret? I'd argue that it's very minimal.

I agree, although I can imaging that multiple controllers fill some values in a secret or config map, independently.

So basically I would say have it there both, so don't use ssa by default for secret and configmap, but if somebody turns it on, we can still throw the exception if it uses stringdata.

or do you think this is an overkill approach?
I see dependent resources is the high level approach where, the framework handles such common mistakes instead of user, so helps them also understand the issues, and by default works as it is intended. (Although what is intended might be sometimes bury in k8s)

@shawkins
Copy link
Collaborator

shawkins commented Sep 7, 2023

I agree, although I can imaging that multiple controllers fill some values in a secret or config map, independently.

They can, but the existing merging strategies are pretty straight-forward for doing that.

@csviri
Copy link
Collaborator Author

csviri commented Sep 7, 2023

I agree, although I can imaging that multiple controllers fill some values in a secret or config map, independently.

They can, but the existing merging strategies are pretty straight-forward for doing that.

So what are the alternatives, shouldn't we allow to use CM/Secret with SSA?

Or just set it by default non-SSA, and that is it?

@shawkins
Copy link
Collaborator

shawkins commented Sep 8, 2023

Or just set it by default non-SSA, and that is it?

I'm fine with the operator framework being opinionated - whatever is likely to be the best / simplest solution should be the default. For Secrets that would be to not use SSA. That way noone will be surprised when migrating from an earlier JOSDK version that they need to change their logic away from using stringData or have to turn off SSA.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 9, 2023
@csviri csviri force-pushed the automatic-corrections-dr branch from 3a352e1 to f31b5ce Compare September 11, 2023 12:15
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 11, 2023
@csviri csviri requested a review from metacosm September 11, 2023 12:49
@csviri csviri marked this pull request as ready for review September 11, 2023 12:49
@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 Sep 11, 2023
@openshift-ci openshift-ci bot requested a review from adam-sandor September 11, 2023 12:49
@csviri
Copy link
Collaborator Author

csviri commented Sep 11, 2023

@metacosm @shawkins I added additional config that will opt out by default Secret and ConfigMap. The additional checks still there. So for now taking the "cover every aspect" approach. Thus check everything that we can, since this does not increase complexity that much. Most of these checks are trivial to read and understand.

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, just one nit. Do you want me to refine the #2028 into something that will automatically detect/prevent reconciliation loops with SSA?

Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
Signed-off-by: Attila Mészáros <[email protected]>
@csviri csviri force-pushed the automatic-corrections-dr branch from 926ae47 to 34874e0 Compare September 12, 2023 11:37
Signed-off-by: Attila Mészáros <[email protected]>
@metacosm metacosm force-pushed the automatic-corrections-dr branch from 08a0f4a to 5fb89ea Compare September 12, 2023 14:16
@metacosm metacosm force-pushed the automatic-corrections-dr branch from 5fb89ea to 0c4db58 Compare September 12, 2023 14:19
@csviri csviri merged commit 2827206 into next Sep 12, 2023
@csviri csviri deleted the automatic-corrections-dr branch September 12, 2023 15:00
metacosm pushed a commit that referenced this pull request Sep 15, 2023
csviri added a commit that referenced this pull request Sep 18, 2023
csviri added a commit that referenced this pull request Sep 18, 2023
csviri added a commit that referenced this pull request Oct 3, 2023
shawkins pushed a commit to shawkins/java-operator-sdk that referenced this pull request Oct 4, 2023
csviri added a commit that referenced this pull request Oct 4, 2023
csviri added a commit that referenced this pull request Oct 4, 2023
csviri added a commit that referenced this pull request Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants