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

Add support for approving InstallPlans with multiple CSVs #260

Merged

Conversation

mprahl
Copy link
Member

@mprahl mprahl commented Jun 6, 2024

First Commit

The operatorpolicy.policy.open-cluster-management.io/managed label is set to an empty value on the Subscription. The
operatorpolicy.policy.open-cluster-management.io/managed annotation is set to ..

The label doesn't set a value because the value could be too long.

This will allow querying for subscriptions managed by operator policies.

Second Commit

When an InstallPlan contains multiple CSVs, it will be approved if all CSVs can be approved by the current operator policies.

Rather than query the operator policies directly, the subscriptions in the namespace that are managed by an operator policy are queried and then their associated operator policies are queried to avoid having to resolve templates.

Relates:
https://issues.redhat.com/browse/ACM-11981

The operatorpolicy.policy.open-cluster-management.io/managed label is
set to an empty value on the Subscription. The
operatorpolicy.policy.open-cluster-management.io/managed annotation
is set to <policy name>.<policy namespace>.

The label doesn't set a value because the value could be too long.

This will allow querying for subscriptions managed by operator policies.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
@mprahl mprahl force-pushed the multiple-csvs-ip branch 2 times, most recently from 1462df0 to 522a4f6 Compare June 6, 2024 20:47
if containsCurrentCSV {
phase, _, _ := unstructured.NestedString(installPlans[i].Object, "status", "phase")
ipInstalling := string(operatorv1alpha1.InstallPlanPhaseInstalling)
ipComplete := string(operatorv1alpha1.InstallPlanPhaseComplete)
Copy link
Member

Choose a reason for hiding this comment

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

I understand prioritizing the Installing plan, but why also Complete plans? It feels like there can be multiple old InstallPlans that have that one, if the operator is done installing?

Copy link
Member Author

@mprahl mprahl Jun 7, 2024

Choose a reason for hiding this comment

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

@JustinKuli if an InstallPlan is complete for currentCSV (not installedCSV) then that means this InstallPlan successfully installed the latest CSV in the channel for this subscription. Otherwise, due to OLM race conditions and also just how it works, it's possible that there are multiple InstallPlans for currentCSV where one is approved and completed and one is awaiting approval.

@mprahl
Copy link
Member Author

mprahl commented Jun 7, 2024

@JustinKuli not sure what is going on in the tests in GitHub since it was saying that the test was expecting the InstallPlan to be NonCompliant but after rebasing to include #252, I pushed then it failed. Then I changed the InstallPlan to be Compliant in check and the test failure still said it expected the InstallPlan to be NonCompliant.

I can't reproduce it locally, so I am rerunning it now.


// If there is more than one CSV in the InstallPlan, make sure this CSV failed before marking it as
// noncompliant.
for _, step := range latestInstallPlan.Status.Plan {
Copy link
Member Author

@mprahl mprahl Jun 7, 2024

Choose a reason for hiding this comment

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

@JustinKuli I read the OLM code and it seems that the only successful final states are created and present (already there or updated). Do you think it's best to do this filtering or should we just mark the InstallPlan as failed even if this operator was successful?

I don't really know how I can get test coverage on this because clusterServiceVersionNames order in the InstallPlan are not deterministic so even if I have an InstallPlan with a failing operator, that one may have been processed first and not move on to the successful operator. I suppose I could modify the InstallPlan status to order the expected successful one but that seems quite hacky.

Copy link
Member

@JustinKuli JustinKuli Jun 7, 2024

Choose a reason for hiding this comment

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

I didn't fully understand this part, so if you think it can work without it, that would be fine? I don't love the idea of modifying the InstallPlan status

Copy link
Member Author

Choose a reason for hiding this comment

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

@JustinKuli to clarify, modifying the InstallPlan status would be for test coverage.

So the question is, should an InstallPlan be marked as failed in the OperatorPolicy if the overall InstallPlan failed but the part for the operator being managed by OperatorPolicy succeeded?

@mprahl mprahl force-pushed the multiple-csvs-ip branch 2 times, most recently from cb9e08a to acfa895 Compare June 7, 2024 13:23
Comment on lines +1782 to +1791
allowedCSVs := make([]policyv1.NonEmptyString, 0, len(policy.Spec.Versions)+1)
allowedCSVs = append(allowedCSVs, policy.Spec.Versions...)

if sub.Spec.StartingCSV != "" {
allowedCSVs = append(allowedCSVs, policyv1.NonEmptyString(sub.Spec.StartingCSV))
}
Copy link
Member

Choose a reason for hiding this comment

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

As a weird note, previously allowedVersions was the variable name.

In this review, it is difficult to tell what is new-new code and what is small changes to existing pieces. At least in GH, it's not very good at aligning the old and new... This is obviously not a major issue, but if there were some additional "anchor points" where there weren't changes (these six lines, for example), it might help git blame in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

The side by side diff is easier for this.

Comment on lines +1790 to +1798
if len(policy.Spec.Versions) == 0 {
// currentCSV is the CSV related to the latest InstallPlan
if sub.Status.CurrentCSV != "" {
return sub.Status.CurrentCSV
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a guarantee that sub.Status.CurrentCSV is in csvNames?

Copy link
Member

Choose a reason for hiding this comment

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

It feels like there could be items in csvNames that "should" be approved by a policy with no versions specified - I thought we were considering some sort of name matching in this case. Is that somewhere else? Or is it not necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

@JustinKuli right. The OLM logic is that if the latest CSV for the channel in the catalog doesn't match sub.Status.CurrentCSV or sub.Status.CurrentCSV does not point to an existing CSV object in the namespace, sub.Status.CurrentCSV gets set to the latest and that CSV is put in the InstallPlan.

Copy link
Member Author

Choose a reason for hiding this comment

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

@JustinKuli I'll revise my statement of "latest in the channel" but rather the latest that replaces the current version.

When an InstallPlan contains multiple CSVs, it will be approved if all
CSVs can be approved by the current operator policies.

Rather than query the operator policies directly, the subscriptions in
the namespace that are managed by an operator policy are queried and
then their associated operator policies are queried to avoid having to
resolve templates to see if they manage a subscription in the namespace.

Relates:
https://issues.redhat.com/browse/ACM-11981

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
Copy link
Member

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

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

/hold

Copy link

openshift-ci bot commented Jun 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JustinKuli, mprahl

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

@JustinKuli
Copy link
Member

/unhold

@openshift-merge-bot openshift-merge-bot bot merged commit 4f7cda6 into open-cluster-management-io:main Jun 7, 2024
9 checks passed
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.

2 participants