-
Notifications
You must be signed in to change notification settings - Fork 140
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(tracker): allows to define ownerReferences for FeatureTrackers #1228
feat(tracker): allows to define ownerReferences for FeatureTrackers #1228
Conversation
Introduces ability to define owner reference for FeatureTracker (internal custom resource). This enables garbage collection of resources belonging to the given Feature when its owner such as DSC or DSCI has been removed. When Features are grouped through means of `FeatureHandler`s, the ownership is defined under the hood, linking it to DSCI or DSC, depending on the type used. In addition, this PR simplifies how Feature relies on `client.Client` instance. Instead of creating its own instance it expects to have one passed as part of the builder call chain. It creates a default one otherwise. With that we can rely on a client configured for controllers with the right schemas, caching rules etc. As a consequence the change of retry logic for status needed to adjusted. Besides a conflict it needs to be triggered on NotFound error, as shared client's cache might not have yet an instance of FeatureTracker created just before the condition is reported. The reason why it was working before is the fact that Feature has its own simple client instance w/o caching. > [!IMPORTANT] > > With DSCI and DSC becoming owners of particular FeatureTrackers > `func (c *Component) Cleanup` called in finalizer block becomes > somewhat speculative. The only use case where custom function is > invoked is unpatching SMCP authorization provider. This was based > on early assumption that we might want to plug into customer's > existing SMCP instance. It's unclear to me if this is still long-term > thinking so we might want to revisit need for this function. > > From the completness point of view, if we allow to create/manipulate > resources programatically as part of the Feature DSL, we should be able > to register cleanup counter-part functions, especially if we cannot simply > remove them (as this is handled through ownership of associated > FeatureTracker). > > There is, however, a need to perform cleanup when particular > component is "Removed" (not managed anymore). Right now this is > handled inside its Reconcile function. Fixes [RHOAIENG-8629](https://issues.redhat.com/browse/RHOAIENG-8629) Relates to opendatahub-io#1192 (comment) Co-authored-by: Bartosz Majsak <[email protected]>
I don't have the full context but the PR looks sensible to me. One minor question would be if, instead of storing the client and eventually creating a new one as part of the |
@lburgazzoli We could pass it along, and at the surface, this will require changes to There's a But with all that said, I would prefer to make it a separate PR. |
That would be perfectly fine with me. I let others to chime in for an actual review as I don't have the full context. |
@lburgazzoli In the same line of thinking we should pass the logger along, so the origins of Apply/Cleanup are more accurate. Also another PR. Can do both. |
I'm wondering how that cache works. For my understanding of caching in general, cache miss causes look up to the main storage and reporting absence only after that. |
return cli.Update(ctx, smcp) | ||
// Update the ServiceMeshControlPlane with the removed extension provider. | ||
// As it could have been updated by another controller in the meantime, we need to retry on conflict. | ||
return retry.RetryOnConflict(retry.DefaultBackoff, func() error { |
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's an additional fix, right?
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, discovered during testing of this change. We can extract it to a tiny PR but it's a bit overdoing in my eyes.
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 mostly wanted to confirm that I did not myself miss the point from the patch :)
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.
PS: and it deserve to be separated just because it is not part of the PR's change, not because of the size
/me hides :)))
}) | ||
dsci.APIVersion = dsciv1.GroupVersion.String() | ||
dsci.Kind = gvk.DSCInitialization.Kind | ||
return dsci, err |
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.
Did not get why you need to return dsci if you modifying it inplace.
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.
Spec: dsciv1.DSCInitializationSpec{ | ||
} | ||
|
||
_, errCreate := controllerutil.CreateOrUpdate(ctx, cli, dsci, func() error { |
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.
Why it's needed?
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.
To have proper UID created by kube-apiserver
, as DSCI is now used as owner-ref.
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.
Got it. I'm not big fan of mixing allocating and k8s creation in New* function (even if it causes less code changes), but it's up to your conventions :)
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.
Fair enough, but that's a different question :) We can split it up.
The cache in
This means the controller might read stale data, leading to operations based on an outdated state. This behavior is precisely why the retry logic needed adjustment, to address potential inconsistencies between the cached data and the actual state in the API server. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ykaliuta The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
10dd554
into
opendatahub-io:incubation
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.
lgtm
Including the client in the function signature makes its usage explicit and more idiomatic. This approach clarifies that the client is intended for use within the function. Decoupling the client from Feature struct enhances code readability. It's a follow-up to PR [opendatahub-io#1228](opendatahub-io#1228 (comment)).
Including the client in the function signature makes its usage explicit and more idiomatic. This approach clarifies that the client is intended for use within the function. Decoupling the client from Feature struct enhances code readability. It's a follow-up to PR [opendatahub-io#1228](opendatahub-io#1228 (comment)).
Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as opendatahub-io#1222 introduced validation check to ensure AppNamespace is immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI.
Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as opendatahub-io#1222 introduced validation check to ensure AppNamespace is immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI.
Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as opendatahub-io#1222 introduced validation check to ensure AppNamespace is immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI.
Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as #1222 introduced validation check to ensure AppNamespace is immutable, but #1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI.
Including the client in the function signature makes its usage explicit and more idiomatic. This approach clarifies that the client is intended for use within the function. Decoupling the client from Feature struct enhances code readability. It's a follow-up to PR [#1228](#1228 (comment)).
…pendatahub-io#1228) * feat(tracker): feature tracker can have ownerReferences Introduces ability to define owner reference for FeatureTracker (internal custom resource). This enables garbage collection of resources belonging to the given Feature when its owner such as DSC or DSCI has been removed. When Features are grouped through means of `FeatureHandler`s, the ownership is defined under the hood, linking it to DSCI or DSC, depending on the type used. In addition, this PR simplifies how Feature relies on `client.Client` instance. Instead of creating its own instance it expects to have one passed as part of the builder call chain. It creates a default one otherwise. With that we can rely on a client configured for controllers with the right schemas, caching rules etc. As a consequence the change of retry logic for status needed to adjusted. Besides a conflict it needs to be triggered on NotFound error, as shared client's cache might not have yet an instance of FeatureTracker created just before the condition is reported. The reason why it was working before is the fact that Feature has its own simple client instance w/o caching. > [!IMPORTANT] > > With DSCI and DSC becoming owners of particular FeatureTrackers > `func (c *Component) Cleanup` called in finalizer block becomes > somewhat speculative. The only use case where custom function is > invoked is unpatching SMCP authorization provider. This was based > on early assumption that we might want to plug into customer's > existing SMCP instance. It's unclear to me if this is still long-term > thinking so we might want to revisit need for this function. > > From the completness point of view, if we allow to create/manipulate > resources programatically as part of the Feature DSL, we should be able > to register cleanup counter-part functions, especially if we cannot simply > remove them (as this is handled through ownership of associated > FeatureTracker). > > There is, however, a need to perform cleanup when particular > component is "Removed" (not managed anymore). Right now this is > handled inside its Reconcile function. Fixes [RHOAIENG-8629](https://issues.redhat.com/browse/RHOAIENG-8629) Relates to opendatahub-io#1192 (comment) Co-authored-by: Bartosz Majsak <[email protected]> * fix: no need to return dsci --------- Co-authored-by: Cameron Garrison <[email protected]> (cherry picked from commit 10dd554)
…1235) Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as opendatahub-io#1222 introduced validation check to ensure AppNamespace is immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI. (cherry picked from commit df1add0)
Including the client in the function signature makes its usage explicit and more idiomatic. This approach clarifies that the client is intended for use within the function. Decoupling the client from Feature struct enhances code readability. It's a follow-up to PR [opendatahub-io#1228](opendatahub-io#1228 (comment)). (cherry picked from commit fde5d69)
…pendatahub-io#1228) * feat(tracker): feature tracker can have ownerReferences Introduces ability to define owner reference for FeatureTracker (internal custom resource). This enables garbage collection of resources belonging to the given Feature when its owner such as DSC or DSCI has been removed. When Features are grouped through means of `FeatureHandler`s, the ownership is defined under the hood, linking it to DSCI or DSC, depending on the type used. In addition, this PR simplifies how Feature relies on `client.Client` instance. Instead of creating its own instance it expects to have one passed as part of the builder call chain. It creates a default one otherwise. With that we can rely on a client configured for controllers with the right schemas, caching rules etc. As a consequence the change of retry logic for status needed to adjusted. Besides a conflict it needs to be triggered on NotFound error, as shared client's cache might not have yet an instance of FeatureTracker created just before the condition is reported. The reason why it was working before is the fact that Feature has its own simple client instance w/o caching. > [!IMPORTANT] > > With DSCI and DSC becoming owners of particular FeatureTrackers > `func (c *Component) Cleanup` called in finalizer block becomes > somewhat speculative. The only use case where custom function is > invoked is unpatching SMCP authorization provider. This was based > on early assumption that we might want to plug into customer's > existing SMCP instance. It's unclear to me if this is still long-term > thinking so we might want to revisit need for this function. > > From the completness point of view, if we allow to create/manipulate > resources programatically as part of the Feature DSL, we should be able > to register cleanup counter-part functions, especially if we cannot simply > remove them (as this is handled through ownership of associated > FeatureTracker). > > There is, however, a need to perform cleanup when particular > component is "Removed" (not managed anymore). Right now this is > handled inside its Reconcile function. Fixes [RHOAIENG-8629](https://issues.redhat.com/browse/RHOAIENG-8629) Relates to opendatahub-io#1192 (comment) Co-authored-by: Bartosz Majsak <[email protected]> * fix: no need to return dsci --------- Co-authored-by: Cameron Garrison <[email protected]> (cherry picked from commit 10dd554)
…1235) Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as opendatahub-io#1222 introduced validation check to ensure AppNamespace is immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI. (cherry picked from commit df1add0)
Including the client in the function signature makes its usage explicit and more idiomatic. This approach clarifies that the client is intended for use within the function. Decoupling the client from Feature struct enhances code readability. It's a follow-up to PR [opendatahub-io#1228](opendatahub-io#1228 (comment)). (cherry picked from commit fde5d69)
…pendatahub-io#1228) * feat(tracker): feature tracker can have ownerReferences Introduces ability to define owner reference for FeatureTracker (internal custom resource). This enables garbage collection of resources belonging to the given Feature when its owner such as DSC or DSCI has been removed. When Features are grouped through means of `FeatureHandler`s, the ownership is defined under the hood, linking it to DSCI or DSC, depending on the type used. In addition, this PR simplifies how Feature relies on `client.Client` instance. Instead of creating its own instance it expects to have one passed as part of the builder call chain. It creates a default one otherwise. With that we can rely on a client configured for controllers with the right schemas, caching rules etc. As a consequence the change of retry logic for status needed to adjusted. Besides a conflict it needs to be triggered on NotFound error, as shared client's cache might not have yet an instance of FeatureTracker created just before the condition is reported. The reason why it was working before is the fact that Feature has its own simple client instance w/o caching. > [!IMPORTANT] > > With DSCI and DSC becoming owners of particular FeatureTrackers > `func (c *Component) Cleanup` called in finalizer block becomes > somewhat speculative. The only use case where custom function is > invoked is unpatching SMCP authorization provider. This was based > on early assumption that we might want to plug into customer's > existing SMCP instance. It's unclear to me if this is still long-term > thinking so we might want to revisit need for this function. > > From the completness point of view, if we allow to create/manipulate > resources programatically as part of the Feature DSL, we should be able > to register cleanup counter-part functions, especially if we cannot simply > remove them (as this is handled through ownership of associated > FeatureTracker). > > There is, however, a need to perform cleanup when particular > component is "Removed" (not managed anymore). Right now this is > handled inside its Reconcile function. Fixes [RHOAIENG-8629](https://issues.redhat.com/browse/RHOAIENG-8629) Relates to opendatahub-io#1192 (comment) Co-authored-by: Bartosz Majsak <[email protected]> * fix: no need to return dsci --------- Co-authored-by: Cameron Garrison <[email protected]> (cherry picked from commit 10dd554)
…1235) Ensures each tests uses different DSCI instance as a test fixture. Without this tests are failing (as they do in latest incubation commit), as opendatahub-io#1222 introduced validation check to ensure AppNamespace is immutable, but opendatahub-io#1228 is trying to update DSCI violating new constraint. With this change each test uses dedicated DSCI. (cherry picked from commit df1add0)
Including the client in the function signature makes its usage explicit and more idiomatic. This approach clarifies that the client is intended for use within the function. Decoupling the client from Feature struct enhances code readability. It's a follow-up to PR [opendatahub-io#1228](opendatahub-io#1228 (comment)). (cherry picked from commit fde5d69)
Description
Introduces the ability to define owner reference for FeatureTracker (internal custom resource). This enables garbage collection of resources belonging to the given Feature when its owner such as DSC or DSCI has been removed.
When Features are grouped through means of
FeatureHandler
s, the ownership is defined under the hood, linking it to DSCI or DSC, depending on the type used.In addition, this PR simplifies how Feature relies on
client.Client
instance. Instead of creating its own instance, it expects to have one passed as part of the builder call chain. It creates a default one otherwise. With that we can rely on a client configured for controllers with the right schemas, caching rules, etc. As a consequence the change of retry logic for status needed to be adjusted. Besides a conflict, it needs to be triggered on theNotFound
error, as a shared client's cache might not have yet an instance of FeatureTracker created just before the condition is reported. The reason why it was working before is the fact that Feature has its own simple client instance w/o caching.Important
With DSCI and DSC becoming owners of particular FeatureTrackers,
func (c *Component) Cleanup
defined forComponentInterface
becomes somewhat speculative. It's been used in the finalizer block for respective controllers to ensure that FTs have been removed, but it also calls any other custom cleanup code attached to a Feature.The only use case where the custom function is invoked at this moment is unpatching/removing custom authorization provider added to SMCP. This was based on an early assumption that we might want to plug into customers' existing SMCP instance. It's unclear to me if this is still long-term thinking so we might want to revisit the need for this functionality.
From the completeness point of view, if we allow to create/manipulate resources programmatically as part of the Feature DSL, we should be able to register cleanup counter-part functions, especially if we cannot simply remove them (as this is handled through ownership of associated FeatureTracker).
There is, however, a need to perform cleanup when the particular component is "Removed" (not managed anymore). Right now this is handled inside its
Reconcile
function.Fixes RHOAIENG-8629
Relates to #1192 (comment)
How Has This Been Tested?
make test
but also:
Screenshot or short clip
Merge criteria