-
Notifications
You must be signed in to change notification settings - Fork 27
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 rule type change detection in profile parse #401
Add rule type change detection in profile parse #401
Conversation
7cb8d66
to
dcd2c5d
Compare
Testing profiles
Expected Behavior:
|
/hold for test |
ff78432
to
66a2bc6
Compare
Didn't get expected result with commit 66a2bc6
|
66a2bc6
to
339a7ac
Compare
I think you need to rerun the updated PB so the rule with get updated with correct annotation, it will be like a operator upgrade @xiaojiey |
Just updated the e2e, I think it will cover some of the upgrade cases. |
339a7ac
to
c4b5e89
Compare
/retest |
e8d273a
to
8b7d445
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vincent056 These are the comments I have so far.
I'll continue reviewing tomorrow.
tests/e2e/parallel/main_test.go
Outdated
modPb.Spec.ContentImage = modifiedImage | ||
if err := f.Client.Update(context.TODO(), modPb); err != nil { | ||
t.Fatalf("failed to update ProfileBundle %s: %s", modPb.Name, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a difference between the following?
- deep copying
modPb
, creating it and updating.Spec.ContentImage
- deep copying
modPb
, updating the.Spec.ContentImage
and creating it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so what we are doing here is first to make a copy of original profile bundle cr instance and then fetch profile bundle CR, and change the content image of the original image, in the end we update the CR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the pb is already there, we are not creating a new one, but to make change to the existing one
82bf9bb
to
26c74b3
Compare
tests/e2e/parallel/main_test.go
Outdated
@@ -2431,6 +2570,9 @@ func TestManualRulesTailoredProfile(t *testing.T) { | |||
ObjectMeta: metav1.ObjectMeta{ | |||
Name: suiteName, | |||
Namespace: f.OperatorNamespace, | |||
Labels: map[string]string{ | |||
compv1alpha1.OutdatedReferenceValidationDisable: "true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we need to disable validation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good catch, I will remove it. It was left from the last approach, where we manually mark migrated rules, now we will not have these issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is marked as as outdated, but still seems to be there at:
https://github.com/ComplianceAsCode/compliance-operator/pull/401/files#diff-a5334e69e88b595448bc22c081212911d6b0f04c2e91752ac2ef1ef7cb68c9edR2664
Is is expected to be there?
54a4159
to
a55b8f3
Compare
Adding more test results:
|
a55b8f3
to
34617c6
Compare
34617c6
to
178535d
Compare
My editor automatically picked up these changes when I was making some modifications locally. Pulling them in a separate commit.
We were using tpSingleNoPrune as a variable in the test, but the actual tailored profile was using multiple rules. This commit updates the variable to reflect that.
} else if isValidationRequired(instance) { | ||
reqLogger.Info("Validating TailoredProfile") | ||
pruneOutdated := false | ||
if _, ok := ann[cmpv1alpha1.PruneOutdatedReferencesAnnotationKey]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only checks if the annotation exists, but in our tests we're setting this to true
at times. Which should we be using?
Setting it to true
feels more explicit to me, with the absence or false
value being the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think I'd follow the same pattern done for rescan=
annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense here
This migration/feature adds new annotations that help users manage their TailoredProfiles. For example, they can set an annotation that automatically prune outdated rule references from the TailoredProfile. Previously, we were only checking the presence of these annotations on the TailoredProfile. This meant users should invoke the behavior with an empty string (""), or a truthy value ("true"), or even a falsy ("false) value. This commit explicitly checks the value of the annotation and makes sure it's set to true before invoking the behavior.
We can improve the readability of the test, especially since rule change from Platfrom to Node type, by having dedicated assertions for checking that attribute. This commit uses those assertions in the end-to-end test so it's easier for readers to know when that type change happens.
We have a pretty good understanding of how to migrate rules from one type (Node) to another (Platform), but initially we included some thoughts on how to handle deprecated rules and variables. However, up to this point, we don't have a way to flag deprecated rules or variables in the content, which is what's needed to annotate them accordingly. Since this code is involving a separate case (deprecation), and the current migration e2e tests pass without it, let's remove it so we can come up with a dedicated approach for it later. This cuts down on the overall patch size, making it more digestable for reviewers, especially since it wasn't fully tested.
@yuumasato and I walked through the code and found a few things to adjust, but we can step through them together next week, too. I just wanted to get the updates we discussed proposed before the break. Each is its own commit, which we can evaluate and consider incorporating if we all agree they're addressing legitimate concerns. Overall, we cleaned up some of e2e test to include some additional assertions, added strict checks on the annotation, and reduced the overall patch size by removing untested code for deprecating variables and rules. |
This code was unused and untested, and we don't have a consistent, or agreed upon way for deprecating rules and variables in the content. Let's remove this for now so that we don't make the patch more complicated. We can always come back to this functionality later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I have suggested some changes to the warning. As the word "migrated" may not mean much to users.
/retest |
@@ -2439,3 +2439,25 @@ func (f *Framework) AssertScanDoesNotContainCheck(scanName, checkName, namespace | |||
} | |||
return nil | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, I think those make sense
Improve warning message on rule type change, explain to user what they might need to do on those rules
/label qe-approved
|
/unhold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/px-approved
Applying PX approved since we walked through this approach with @mkumku
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhmdnd, Vincent056 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 |
8cd35fa
into
ComplianceAsCode:master
We went through migration cases for the new KubeletConfig changes. We decided to handle the TailoredProfile migration on the operator instead.
This fixes future rule checkType change migration issues as well as rule/variables deprecation issues.
To spot deprecated variables and rules, we'll use annotations derived from the content:
compliance.openshift.io/deprecated
During the profileParser upgrade, we'll detect rule TypeChanges by comparing existing rule types against the new updates. If there's a change, the annotation
compliance.openshift.io/rule-last-check-type
will be added to the rule.We will issues event and show warning in the TailoredProfile Status, if there are any deprecated or migrated rules/variables in the TailoredProfile, and user can also choose to set following annotation on the tailoredProfile:
compliance.openshift.io/prune-outdated-references
, so that the tailoredProfile controller will removal of all deprecated rules and variables along with migrated rules references from that specific tailoredProfile object.To bypass migration and deprecation validation on specific TailoredProfile object, add the tag:
compliance.openshift.io/disable-outdated-reference-validation
.Testing Profiles:
Check comment for testing profiles