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

Set parent policy label on template when updating #35

Conversation

willkutler
Copy link
Contributor

@willkutler willkutler commented Mar 1, 2023

Currently, the parent policy label on templates, which is used for #28 , is only set on template creation, which could cause issues with policies that have already been created. This fix verifies the necessary template labels are set when updating the template. It also includes a light refactor of the template equality check to make it look a little cleaner.

@willkutler willkutler force-pushed the set-parent-label-on-update branch 2 times, most recently from 969f8e7 to df4a698 Compare March 2, 2023 15:39
@willkutler willkutler force-pushed the set-parent-label-on-update branch 3 times, most recently from 8520fd2 to d876cae Compare March 2, 2023 19:22
Currently, the parent policy label on templates, which is used for open-cluster-management-io#28 , is only set on template creation, which could cause issues with policies that have already been created. This fix verifies the necessary template labels are set when updating the template.

Signed-off-by: Will Kutler <wkutler@redhat.com>
@@ -666,20 +666,24 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
log.Error(err, "Failed to apply defaults to the ConstraintTemplate for comparison. Continuing.")
}
}
// verify parent policy label is set properly
tObjectUnstructured.SetLabels(r.setDefaultTemplateLabels(instance, tObjectUnstructured.GetLabels()))
Copy link
Member

Choose a reason for hiding this comment

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

@willkutler, did you mean this instead?

Suggested change
tObjectUnstructured.SetLabels(r.setDefaultTemplateLabels(instance, tObjectUnstructured.GetLabels()))
tObjectUnstructured.SetLabels(r.setDefaultTemplateLabels(instance, eObject.GetLabels()))

Copy link
Contributor Author

@willkutler willkutler Mar 14, 2023

Choose a reason for hiding this comment

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

No, I think that line should be right - the code should retain any non-default labels specified in the template in case users edit a policy to add labels to the policy template. That line is just making sure the template labels have the default labels set too before we compare them with the existing template object's labels.

Signed-off-by: Will Kutler <wkutler@redhat.com>

review

Signed-off-by: Will Kutler <wkutler@redhat.com>
@openshift-ci
Copy link

openshift-ci bot commented Mar 14, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@openshift-merge-robot openshift-merge-robot merged commit a5ccb66 into open-cluster-management-io:main Mar 14, 2023
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