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 status reporting inconsistency in mustnothave mode #240

Merged

Conversation

zyjjay
Copy link
Contributor

@zyjjay zyjjay commented May 2, 2024

Mostly for handling of deployments and catalogsources

@zyjjay
Copy link
Contributor Author

zyjjay commented May 2, 2024

@JustinKuli This is pretty much what I had in mind for fixing consistency issues around the relatedObjects for deployments and catalogsources. I realized now that these changes might hurt the readability of the code in exchange for reporting finer details in the relatedObjects field. A simpler alternative is to just create a more "barebones" relatedObject that tells users the controller doesn't handle these objects in mustnothavemode, without caring too much about the granular details (like the name/namespace where the object can be found in). Let me know what you think!

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.

I think this is on the right track, I think it is a better approach than just always wiping out the related object with a no-name not-applicable one.

// reason = "Resource not found but should exist"/"Resource not found as expected"
// based on the complianceType specified by the policy
// Note: These relatedObjects are not applicable *only* in mustnothave mode
func missingNotApplicableObj(name string, namespace string, complianceType policyv1.ComplianceType, gvk schema.GroupVersionKind) policyv1.RelatedObject {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be renamed to just missingObj? Since it doesn't use the NotApplicable reason, it seems odd.

Comment on lines 1640 to 1651
// Mustnothave
var relObj policyv1.RelatedObject
cond := notApplicableCond("CatalogSource")
cond.Status = metav1.ConditionFalse // CatalogSource condition has the opposite polarity

if isMissing {
relObj = missingNotApplicableObj(catalogName, catalogNS, policyv1.MustNotHave, catalogSrcGVK)
} else {
relObj = foundNotApplicableObj(catalogSrc)
}

changed := updateStatus(policy, catalogSourceFindCond(isUnhealthy, isMissing, catalogName),
catalogSourceObj(catalogName, catalogNS, isUnhealthy, isMissing))
changed := updateStatus(policy, cond, relObj)
Copy link
Member

Choose a reason for hiding this comment

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

Since mustnothave mode does not need to check if the catalogsource is healthy, can it be handled earlier? I have a feeling it would clean up some of this. Right now, in particular, I needed to double-check that the catalogSrc here wasn't a nil pointer - but I think it could've just used foundCatalogSrc?

@zyjjay
Copy link
Contributor Author

zyjjay commented May 3, 2024

handleCatalogSource look a lot cleaner now IMO. Going to modify the tests now to account for the condition/related object changes.

Changes:
- Added new conditions and related objects to account for scenarios where resources are not handled in mustnothave mode
- Modified and refactored code for handling CatalogSource and Deployment
- Modified e2e test to account for status reporting changes

ref: https://issues.redhat.com/browse/ACM-11410
Signed-off-by: Jason Zhang <jaszhang@redhat.com>
@zyjjay zyjjay marked this pull request as ready for review May 7, 2024 13:44
@zyjjay zyjjay changed the title [WIP] Fix consistency of relatedObjects in mustnothave mode Fix status reporting inconsistency in mustnothave mode May 7, 2024
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.

LGTM!

Copy link

openshift-ci bot commented May 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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

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.

3 participants