Skip to content

Aggregate Pending status from replicated policies #64

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

Conversation

JustinKuli
Copy link
Member

When a replicated policy is in the Pending state, and all others for that root policy are Compliant, then the root policy should be Pending.

This change extracts some other aggregation logic in a way that should be more testable, and adds unit tests for some previous existing behavior.

Refs:

Signed-off-by: Justin Kulikauskas [email protected]

policiesv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
"open-cluster-management.io/governance-policy-propagator/controllers/common"
)

Copy link
Member Author

Choose a reason for hiding this comment

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

I extracted calculatePerClusterStatus as a separate function with the intention of unit testing it, but I couldn't get the fakeclient to work with the List call that this makes. Using envtest would probably work, but would take more setup than I wanted to do here.

@JustinKuli JustinKuli requested a review from willkutler October 31, 2022 15:23
@JustinKuli JustinKuli force-pushed the aggregate-pending-status branch from e0f452f to 863a3f5 Compare October 31, 2022 15:36
When a replicated policy is in the Pending state, and all others for
that root policy are Compliant, then the root policy should be Pending.

This change extracts some other aggregation logic in a way that should
be more testable, and adds unit tests for some previous existing
behavior.

Refs:
 - stolostron/backlog#26182

Signed-off-by: Justin Kulikauskas <[email protected]>
@JustinKuli JustinKuli force-pushed the aggregate-pending-status branch from 863a3f5 to 9018d65 Compare October 31, 2022 17:54
return nil, err
}

status := make([]*policiesv1.CompliancePerClusterStatus, 0, len(replicatedPlcList.Items)+len(failedClusters))
Copy link
Contributor

Choose a reason for hiding this comment

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

nice improvement

})
}

sort.Slice(status, func(i, j int) bool {
Copy link
Contributor

@ChunxiAlexLuo ChunxiAlexLuo Nov 2, 2022

Choose a reason for hiding this comment

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

Is there any need to do sorting here? I know it would be looks nice but the overhead seems unnecessary for the usage of calculatePerClusterStatus.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's necessary because the list is copied into the status after this. If the order was inconsistent, the status might be updated when there aren't really any changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's necessary because the list is copied into the status after this. If the order was inconsistent, the status might be updated when there aren't really any changes.

Got it.

}

// calculateRootCompliance uses the input per-cluster statuses to determine what a root policy's
// ComplianceState should be. General precedence is: NonCompliant > Pending > Unknown > Compliant.
Copy link
Contributor

@ChunxiAlexLuo ChunxiAlexLuo Nov 2, 2022

Choose a reason for hiding this comment

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

The logic in calculateRootCompliance looks good to me.

case2PolicyName string = "case2-test-policy"
case2PolicyYaml string = "../resources/case2_aggregation/case2-test-policy.yaml"
)

var _ = Describe("Test policy status aggregation", func() {
Copy link
Contributor

@ChunxiAlexLuo ChunxiAlexLuo Nov 2, 2022

Choose a reason for hiding this comment

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

Have you tested the unknown case here

Copy link
Member Author

Choose a reason for hiding this comment

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

Not here, but it is tested in the unit-style test TestCalculateRootCompliance

Copy link
Contributor

@ChunxiAlexLuo ChunxiAlexLuo left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented Nov 2, 2022

[APPROVALNOTIFIER] This PR is APPROVED

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

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 [ChunxiAlexLuo,JustinKuli]

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