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

Emit fewer OperatorPolicy events #208

Conversation

JustinKuli
Copy link
Member

Previously, every time the controller determined a piece of the status for an OperatorPolicy, it updated the policy status on the cluster, and emitted a compliance event. This made each condition's logic more self- contained, but leads to more API calls than necessary.

Now, each handle* function returns whether the status in the cluster needs to be updated, and the controller will make a maximum of one status update pre reconcile. That status update will update all of the conditions and related objects at once. It will also send one compliance event at that point, reflecting the "final" state of the policy.

Some handle* functions should emit multiple events: for example an enforced policy should report when something is missing, and then separately report if that resource was successfully created. So, some of the functions return "early" conditions, which the controller emits before the end of the reconcile. Compare this to "event batches" in ConfigurationPolicy.

earlyComplianceEvents = make([]metav1.Condition, 0)

desiredSub, desiredOG, changed, err := r.buildResources(policy)
condChanged = condChanged || changed
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
condChanged = condChanged || changed
condChanged = changed

func (r *OperatorPolicyReconciler) buildResources(ctx context.Context, policy *policyv1beta1.OperatorPolicy) (
*operatorv1alpha1.Subscription, *operatorv1.OperatorGroup, error,
func (r *OperatorPolicyReconciler) buildResources(policy *policyv1beta1.OperatorPolicy) (
*operatorv1alpha1.Subscription, *operatorv1.OperatorGroup, bool, error,
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 document the returned bool in the function doc comment?

}

if conditionChanged {
conditionsToEmit = append(conditionsToEmit, calculateComplianceCondition(policy))
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 add a comment indicating that this is the "final" compliance event to emit of the current policy state? It wasn't immediately obvious to me and that explains why conditionsToEmit is named as it is rather than earlyComplianceEvents.

mprahl
mprahl previously approved these changes Feb 21, 2024
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.

/hold for minor comments to be addressed

return reconcile.Result{}, utilerrors.NewAggregate(errs)
}

func (r *OperatorPolicyReconciler) handleResources(ctx context.Context, policy *policyv1beta1.OperatorPolicy) (
Copy link
Contributor

@yiraeChristineKim yiraeChristineKim Feb 21, 2024

Choose a reason for hiding this comment

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

Optional: Comment Missed? It would be good to me if this had a description

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me, very clear to understand! Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea

Previously, every time the controller determined a piece of the status
for an OperatorPolicy, it updated the policy status on the cluster, and
emitted a compliance event. This made each condition's logic more self-
contained, but leads to more API calls than necessary.

Now, each `handle*` function returns whether the status in the cluster
needs to be updated, and the controller will make a maximum of one
status update pre reconcile. That status update will update all of the
conditions and related objects at once. It will also send one compliance
event at that point, reflecting the "final" state of the policy.

Some `handle*` functions *should* emit multiple events: for example an
enforced policy should report when something is missing, and then
separately report if that resource was successfully created. So, some
of the functions return "early" conditions, which the controller emits
before the end of the reconcile. Compare this to "event batches" in
ConfigurationPolicy.

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
@openshift-ci openshift-ci bot added the lgtm label Feb 21, 2024
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.

/unhold

Copy link

openshift-ci bot commented Feb 21, 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 8afaf59 into open-cluster-management-io:main Feb 21, 2024
4 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.

3 participants