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 relatedObjs to unnamed musthave object #182

Conversation

yiraeChristineKim
Copy link
Contributor

What the user wants:
When the object, even if no having name, turns compliant, appears in the list. We can see the object of Kind Node, compliant, and it does not match any specific name of the Kind object.

Ref: https://issues.redhat.com/browse/ACM-8782

test/e2e/case37_no_name_test.go Outdated Show resolved Hide resolved
case37PolicyCSName string = "case37-test-policy-clusterscope"
)

var _ = Describe("Test a namespace-scope policy that is missing name ", Ordered, func() {
Copy link
Member

Choose a reason for hiding this comment

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

These tests look great! I see tests for objects when it is compliant and when it is non-compliant (I was worried just looking through the code that it only covered one of those cases).

Do these changes also address similar cases for mustnothave policies?

Copy link
Contributor Author

@yiraeChristineKim yiraeChristineKim Dec 4, 2023

Choose a reason for hiding this comment

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

if objShouldExist {
.
.
.
				if objDetails.kind != "" && objDetails.name == "" {

It doesn't affect mustnothave. I thought mustnothave ok

Copy link
Member

Choose a reason for hiding this comment

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

I think when a mustnothave policy is Compliant, it would have a similar situation: its relatedObjects list would be empty. It doesn't look like it's necessary to address that for this issue, but it's something to consider in the future. I think it could be nice if there was always something in that list.

Copy link
Contributor Author

@yiraeChristineKim yiraeChristineKim Dec 4, 2023

Choose a reason for hiding this comment

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

Can you give me example relatedObjects when it is mustnothave? To me.. it is mustnothave so it is right that it should not show anything


// Change reason to Resource found but does not match
if len(objNames) > 0 {
shouldAddCondensedRelatedObj = true
Copy link
Member

Choose a reason for hiding this comment

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

Why not just always set this to true instead of duplicating the list query performed in getNamesOfKind?

Copy link
Contributor Author

@yiraeChristineKim yiraeChristineKim Dec 12, 2023

Choose a reason for hiding this comment

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

len(objNames) == 0 there is nothing to show on relatedobj. In other words, there is nothing to debug

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer if whenever the object template is not named and it's noncompliant, you just set shouldAddCondensedRelatedObj = true. Perhaps there are no objects, but that's okay. It makes the behavior consistent.

Also, I'm not sure if reasonWantFoundNoMatch is better than reasonWantFoundDNE, so if that's why you are duplicating the list query by calling getNamesOfKind again, then it's not worth it in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

um... to me, reasonWantFoundNoMatch is better. Because the name is * in relatedObj and users only see the reason on the console. reasonWantFoundNoMatch is for relatedObj.. isn't it? @JustinKuli how about yoiu

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After this poll, we should decide mustnothave reason too

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for slow response, if you're still looking for input, I think reasonWantFoundNoMatch makes more sense when the name is *. It doesn't make as much sense to say something "resource *, not found" when some instances of that resource do exist.

So for mustnothave, same kind of thing: if the names would be * or something similar, because some resources were found they just didn't fully match the policy criteria, then use a NoMatch kind of reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JustinKuli Thanks!

JustinKuli
JustinKuli previously approved these changes Jan 2, 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.

/hold

Looks good to me! I'm not sure if Matt had any remaining requirements

case37PolicyMustnothaveName, testNamespace, true, defaultTimeoutSeconds)
Expect(plc).ShouldNot(BeNil())
})
It("should have 0 Compliant relatedObject under the policy's status", func() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correctly describing the test since it's expecting related objects to have a length of 1. Could you please reword it?

return utils.GetComplianceState(managedPlc)
}, defaultTimeoutSeconds, 1).Should(Equal("Compliant"))

By("relatedObjects should not exist")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
By("relatedObjects should not exist")
By("relatedObjects should exist")

// Getting relatedObjects takes longer time
}, defaultTimeoutSeconds*2, 1).Should(HaveLen(1))

By("Check the reasons of relatedObjects")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
By("Check the reasons of relatedObjects")
By("Check the reason of the related object")


By("Check the reason of relatedObjects")
reason := relatedObjects[0].(map[string]interface{})["reason"].(string)
Expect(reason).Should(Equal("Resource found but should not exist"))
Copy link
Member

Choose a reason for hiding this comment

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

Could you please also test that the name is not * here?

Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

This looks great! Just a few minor comments in the tests.

Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

Looks great!

/hold for @JustinKuli to take another look

@openshift-ci openshift-ci bot added the lgtm label Jan 5, 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.

/unhold

Copy link

openshift-ci bot commented Jan 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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:
  • OWNERS [JustinKuli,mprahl,yiraeChristineKim]

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 7529c90 into open-cluster-management-io:main Jan 5, 2024
4 checks passed
Copy link
Member

Choose a reason for hiding this comment

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

@yiraeChristineKim I think this file shouldn't have been merged. Can you revert this, please?

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.

4 participants