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

fix(feature): only relies on desired state for reconcilation #1103

Conversation

bartoszmajsak
Copy link
Contributor

@bartoszmajsak bartoszmajsak commented Jul 8, 2024

Description

This change ensures that the "management mode" is based exclusively on a resource defined as the desired state, i.e. the one provided by the controller itself. This can be, but is not limited to, manifest files provided through an embedded file system.

Although the actual instance on the cluster (the target) might be in a different state (the user might want to opt-out from reconcilation by changing the label), we intentionally do not address this scenario due to the lack of clear requirements on how users can modify such resources.

This change allows control over previously undefined resources, so those created by Feature API without explicit management state defined. As long as the original Feature does not have Managed() called in the builder chain, nor used manifests have the label explicitly defined the behaviour remains unchanged, which means the resources being part of such a feature are not managed and thus not reconciled after initial apply.

opendatahub.io/managed is already exposed as an annotation and used by other components.

Follow up to #974

How Has This Been Tested?

Integration tests are included in tests/integration/features/resources_int_test.go

Screenshot or short clip

Merge criteria

  • You have read the contributors guide.
  • Commit messages are meaningful - have a clear and concise summary and detailed explanation of what was changed and why.
  • Pull Request contains a description of the solution, a link to the JIRA issue, and to any dependent or related Pull Request.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@bartoszmajsak
Copy link
Contributor Author

Putting on hold until label/annotation confusion is addressed

This change ensures that management state is based exclusively on a
resource defined in desired state, i.e. the one provided by the
controller itself. This can be, but is not limited to, manifest files
provided through embedded file system.

Although the actual instance on the cluster (the target) might be
in a different state, we intentionally do not address this scenario due
to the lack of clear requirements on the extent to which users can
modify such resource.

This change allows to take control over previously undefined resources,
so those which are created by `Feature` API without explicit management
state defined. As long as original Feature does not have `Managed()`
called in the builder chain, nor used manifests have the label
explicitly defined the behaviour remain unchanged, that means the
resources being part of such a feature are not managed and thus not
reconciled after initial apply.

`opendatahub.io/managed` is already exposed as an annotation and used by [other components](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/2.10/html/installing_and_uninstalling_openshift_ai_self-managed/preparing-openshift-ai-for-ibm-cpd_prepare-openshift-ai-ibm-cpd#editing-model-inferencing-configuration-ibm-cpd_prepare-openshift-ai-ibm-cpd).

Follow up to opendatahub-io#974
Comment on lines +120 to +122
if isUnmanaged(source) {
return false
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline with @zdtsw, this is somewhat redundant as we return false at the end. We do have this behaviour covered in tests, but I was wondering if it wouldn't be beneficial to keep this check in the original code as a contract so that when the requirements about relying on target state will become clear this will be explicitly visible. I am on the verge here.

@bartoszmajsak
Copy link
Contributor Author

Putting on hold until label/annotation confusion is addressed

that has been clarified now - annotation that is.

Copy link
Contributor

@israel-hdez israel-hdez left a comment

Choose a reason for hiding this comment

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

So, this changes from looking at the bundled manifests, rather than looking at the resource in the cluster.

I'm fine with the change, as it is backwards compatible. Although, it should be noted that in the documented case the annotation is editable by the user to disengage reconciliation, while in Features developers have the control. So, it is two different meanings. Just to keep in mind.

@bartoszmajsak
Copy link
Contributor Author

So, this changes from looking at the bundled manifests, rather than looking at the resource in the cluster.

Correct, and note it is not used anywhere in the Features yet (at least in the incubation branch). I have a fix for envoy filter coming which could use this though.

I'm fine with the change, as it is backwards compatible. Although, it should be noted that in the documented case the annotation is editable by the user to disengage reconciliation, while in Features developers have the control. So, it is two different meanings. Just to keep in mind.

This is why I mentioned in the godocs, that the requirements are not clear yet - we only handle it for one specific case for KServe kustomize manifests through deploy.go which got brought back in #1106. Perhaps the docs should mention it is only applicable for this very resource at the moment.

Copy link

openshift-ci bot commented Jul 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cam-garrison, israel-hdez, zdtsw

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit e12d7d7 into opendatahub-io:incubation Jul 10, 2024
8 checks passed
@israel-hdez
Copy link
Contributor

Perhaps the docs should mention it is only applicable for this very resource at the moment.

Here I have to defer to @zdtsw and @VaishnaviHire about the godocs. If you mean about the doc-comments in the code, I also appreciate clarification there for us, the developers. About the other docs mentioned in the main comment, I guess the policy is that only documented uses are supported; so those docs should be fine as is.

VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Jul 24, 2024
…ahub-io#1103)

This change ensures that management state is based exclusively on a
resource defined in desired state, i.e. the one provided by the
controller itself. This can be, but is not limited to, manifest files
provided through embedded file system.

Although the actual instance on the cluster (the target) might be
in a different state, we intentionally do not address this scenario due
to the lack of clear requirements on the extent to which users can
modify such resource.

This change allows to take control over previously undefined resources,
so those which are created by `Feature` API without explicit management
state defined. As long as original Feature does not have `Managed()`
called in the builder chain, nor used manifests have the label
explicitly defined the behaviour remain unchanged, that means the
resources being part of such a feature are not managed and thus not
reconciled after initial apply.

`opendatahub.io/managed` is already exposed as an annotation and used by [other components](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/2.10/html/installing_and_uninstalling_openshift_ai_self-managed/preparing-openshift-ai-for-ibm-cpd_prepare-openshift-ai-ibm-cpd#editing-model-inferencing-configuration-ibm-cpd_prepare-openshift-ai-ibm-cpd).

Follow up to opendatahub-io#974

(cherry picked from commit e12d7d7)
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Jul 24, 2024
…ahub-io#1103)

This change ensures that management state is based exclusively on a
resource defined in desired state, i.e. the one provided by the
controller itself. This can be, but is not limited to, manifest files
provided through embedded file system.

Although the actual instance on the cluster (the target) might be
in a different state, we intentionally do not address this scenario due
to the lack of clear requirements on the extent to which users can
modify such resource.

This change allows to take control over previously undefined resources,
so those which are created by `Feature` API without explicit management
state defined. As long as original Feature does not have `Managed()`
called in the builder chain, nor used manifests have the label
explicitly defined the behaviour remain unchanged, that means the
resources being part of such a feature are not managed and thus not
reconciled after initial apply.

`opendatahub.io/managed` is already exposed as an annotation and used by [other components](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/2.10/html/installing_and_uninstalling_openshift_ai_self-managed/preparing-openshift-ai-for-ibm-cpd_prepare-openshift-ai-ibm-cpd#editing-model-inferencing-configuration-ibm-cpd_prepare-openshift-ai-ibm-cpd).

Follow up to opendatahub-io#974

(cherry picked from commit e12d7d7)
func isManaged(obj *unstructured.Unstructured) bool {
managed, isDefined := obj.GetAnnotations()[annotations.ManagedByODHOperator]
return isDefined && managed == "true"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So, how is the 3rd state, !isDefined, which is neither managed nor unmanaged called? :)

Copy link
Member

Choose a reason for hiding this comment

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

then shouldReconcile() return false in the case of !IsDefined , right?

Copy link
Contributor

@ykaliuta ykaliuta Jul 30, 2024

Choose a reason for hiding this comment

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

then shouldReconcile() return false in the case of !IsDefined , right?

Yes. As far as I understand #1103 (comment) you discussed it offline and kept it on purpose. It just looks a bit weird from the reader's prospective :)

In general, as mentioned in the comment, shouldReconcile is just isManaged(), and Unmanaged probably means !isManaged().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I admit my 🧠 was tripping at the time of writing it. Happy to discuss how to make it better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants