Skip to content

Commit e9a8b4e

Browse files
jan-lawopenshift-merge-bot[bot]
authored andcommitted
Omit dry run matching field when not in use
ref: https://issues.redhat.com/browse/ACM-14577 Signed-off-by: Janelle Law <[email protected]>
1 parent d252b39 commit e9a8b4e

11 files changed

+32
-30
lines changed

api/v1/configurationpolicy_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ type ObjectProperties struct {
418418
// cluster.
419419
Diff string `json:"diff,omitempty"`
420420

421-
// MatchesAfterDryRun indicates whether the dry run update matches the policy assessment. If false,
421+
// MatchesAfterDryRun indicates whether the object matches the policy after the dry run update. If true,
422422
// there was an initial mismatch between the policy and object, but the dry run update produced
423423
// a compliant result.
424424
MatchesAfterDryRun bool `json:"matchesAfterDryRun,omitempty"`

controllers/configurationpolicy_controller.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
31893189
if obj.existingObj == nil {
31903190
log.Info("Skipping update: Previous object retrieval from the API server failed")
31913191

3192-
return false, "", "", false, nil, true
3192+
return false, "", "", false, nil, false
31933193
}
31943194

31953195
var res dynamic.ResourceInterface
@@ -3211,7 +3211,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
32113211
objectT.MetadataComplianceType,
32123212
)
32133213
if errMsg != "" {
3214-
return true, errMsg, "", true, nil, true
3214+
return true, errMsg, "", true, nil, false
32153215
}
32163216

32173217
recordDiff := objectT.RecordDiffWithDefault()
@@ -3231,7 +3231,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
32313231

32323232
r.setEvaluatedObject(obj.policy, obj.existingObj, !throwSpecViolation, "")
32333233

3234-
return throwSpecViolation, "", diff, updateNeeded, updatedObj, true
3234+
return throwSpecViolation, "", diff, updateNeeded, updatedObj, false
32353235
}
32363236

32373237
if updateNeeded {
@@ -3275,7 +3275,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
32753275
r.setEvaluatedObject(obj.policy, obj.existingObj, false, message)
32763276
}
32773277

3278-
return true, message, "", updateNeeded, nil, true
3278+
return true, message, "", updateNeeded, nil, false
32793279
}
32803280

32813281
// If an update is invalid (i.e. modifying Pod spec fields), then return noncompliant since that
@@ -3301,7 +3301,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
33013301

33023302
r.setEvaluatedObject(obj.policy, obj.existingObj, false, message)
33033303

3304-
return true, message, diff, false, nil, true
3304+
return true, message, diff, false, nil, false
33053305
}
33063306

33073307
mergedObjCopy := obj.existingObj.DeepCopy()
@@ -3327,7 +3327,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
33273327
// Assume object is compliant by inverting the value of throwSpecViolation
33283328
r.setEvaluatedObject(obj.policy, obj.existingObj, !throwSpecViolation, "")
33293329

3330-
matchesAfterDryRun = false
3330+
matchesAfterDryRun = true
33313331

33323332
return throwSpecViolation, "", diff, updateNeeded, updatedObj, matchesAfterDryRun
33333333
}
@@ -3339,7 +3339,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
33393339
if isInform {
33403340
r.setEvaluatedObject(obj.policy, obj.existingObj, false, "")
33413341

3342-
return true, "", diff, false, nil, true
3342+
return true, "", diff, false, nil, matchesAfterDryRun
33433343
}
33443344

33453345
// If it's not inform (i.e. enforce), update the object
@@ -3359,7 +3359,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
33593359
if err != nil && !k8serrors.IsNotFound(err) {
33603360
message = fmt.Sprintf(`%s failed to delete when recreating with the error %v`, getMsgPrefix(&obj), err)
33613361

3362-
return true, message, "", updateNeeded, nil, true
3362+
return true, message, "", updateNeeded, nil, matchesAfterDryRun
33633363
}
33643364

33653365
attempts := 0
@@ -3377,7 +3377,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
33773377
message = getMsgPrefix(&obj) + " timed out waiting for the object to delete during recreate, " +
33783378
"will retry on the next policy evaluation"
33793379

3380-
return true, message, "", updateNeeded, nil, true
3380+
return true, message, "", updateNeeded, nil, matchesAfterDryRun
33813381
}
33823382

33833383
time.Sleep(time.Second)
@@ -3413,14 +3413,14 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
34133413
message = fmt.Sprintf("%s failed to %s with the error `%v`", getMsgPrefix(&obj), action, err)
34143414
}
34153415

3416-
return true, message, diff, updateNeeded, nil, true
3416+
return true, message, diff, updateNeeded, nil, matchesAfterDryRun
34173417
}
34183418

34193419
if !statusMismatch {
34203420
r.setEvaluatedObject(obj.policy, updatedObj, true, message)
34213421
}
34223422

3423-
return throwSpecViolation, "", diff, updateNeeded, updatedObj, true
3423+
return throwSpecViolation, "", diff, updateNeeded, updatedObj, matchesAfterDryRun
34243424
}
34253425

34263426
func getMsgPrefix(obj *singleObject) string {

deploy/crds/kustomize_configurationpolicy/policy.open-cluster-management.io_configurationpolicies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ spec:
479479
type: string
480480
matchesAfterDryRun:
481481
description: |-
482-
MatchesAfterDryRun indicates whether the dry run update matches the policy assessment. If false,
482+
MatchesAfterDryRun indicates whether the object matches the policy after the dry run update. If true,
483483
there was an initial mismatch between the policy and object, but the dry run update produced
484484
a compliant result.
485485
type: boolean

deploy/crds/kustomize_operatorpolicy/kustomization.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ patches:
1414
version: v1
1515
kind: CustomResourceDefinition
1616
name: operatorpolicies.policy.open-cluster-management.io
17+
- path: remove-matches-after-dry-run.json
18+
target:
19+
group: apiextensions.k8s.io
20+
version: v1
21+
kind: CustomResourceDefinition
22+
name: operatorpolicies.policy.open-cluster-management.io

deploy/crds/kustomize_operatorpolicy/policy.open-cluster-management.io_operatorpolicies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ spec:
386386
type: string
387387
matchesAfterDryRun:
388388
description: |-
389-
MatchesAfterDryRun indicates whether the dry run update matches the policy assessment. If false,
389+
MatchesAfterDryRun indicates whether the object matches the policy after the dry run update. If true,
390390
there was an initial mismatch between the policy and object, but the dry run update produced
391391
a compliant result.
392392
type: boolean
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"op": "remove",
4+
"path": "/spec/versions/0/schema/openAPIV3Schema/properties/status/properties/relatedObjects/items/properties/properties/properties/matchesAfterDryRun"
5+
}
6+
]

deploy/crds/policy.open-cluster-management.io_configurationpolicies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ spec:
486486
type: string
487487
matchesAfterDryRun:
488488
description: |-
489-
MatchesAfterDryRun indicates whether the dry run update matches the policy assessment. If false,
489+
MatchesAfterDryRun indicates whether the object matches the policy after the dry run update. If true,
490490
there was an initial mismatch between the policy and object, but the dry run update produced
491491
a compliant result.
492492
type: boolean

deploy/crds/policy.open-cluster-management.io_operatorpolicies.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,6 @@ spec:
381381
CreatedByPolicy reports whether the object was created by the configuration policy, which is
382382
important when pruning is configured.
383383
type: boolean
384-
matchesAfterDryRun:
385-
description: |-
386-
MatchesAfterDryRun indicates whether the dry run update matches the policy assessment. If false,
387-
there was an initial mismatch between the policy and object, but the dry run update produced
388-
a compliant result.
389-
type: boolean
390384
uid:
391385
description: |-
392386
UID stores the object UID to help track object ownership for deletion when pruning is

pkg/dryrun/policy.open-cluster-management.io_configurationpolicies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ spec:
486486
type: string
487487
matchesAfterDryRun:
488488
description: |-
489-
MatchesAfterDryRun indicates whether the dry run update matches the policy assessment. If false,
489+
MatchesAfterDryRun indicates whether the object matches the policy after the dry run update. If true,
490490
there was an initial mismatch between the policy and object, but the dry run update produced
491491
a compliant result.
492492
type: boolean

test/e2e/case20_delete_objects_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ var _ = Describe("Test Object deletion", Ordered, func() {
160160
uid, found, _ := unstructured.NestedString(relatedObj, "properties", "uid")
161161
Expect(found).To(BeTrue())
162162
Expect(uid).ToNot(BeEmpty())
163-
164-
matchesAfterDryRun, found, _ := unstructured.NestedBool(relatedObj, "properties", "matchesAfterDryRun")
165-
Expect(found).To(BeTrue())
166-
Expect(matchesAfterDryRun).To(BeTrue())
167163
})
168164
AfterAll(func() {
169165
policies := []string{

0 commit comments

Comments
 (0)