-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix constraints not satisfiable message causing compliance flood #220
Merged
openshift-merge-bot
merged 1 commit into
open-cluster-management-io:main
from
zyjjay:ACM-10204
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |
"fmt" | ||
"reflect" | ||
"regexp" | ||
"slices" | ||
"strings" | ||
|
||
operatorv1 "github.com/operator-framework/api/pkg/operators/v1" | ||
operatorv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" | ||
|
@@ -653,19 +655,17 @@ func (r *OperatorPolicyReconciler) handleSubscription( | |
} | ||
|
||
if includesSubscription { | ||
cond := metav1.Condition{ | ||
Type: subConditionType, | ||
Status: metav1.ConditionFalse, | ||
Reason: subResFailed.Reason, | ||
Message: subResFailed.Message, | ||
// a "constraints not satisfiable" message has nondeterministic clauses, and thus | ||
// need to be sorted in order to check that they are not duplicates of the current message. | ||
if constraintMessageMatch(policy, &subResFailed) { | ||
return mergedSub, nil, false, nil | ||
} | ||
|
||
if subResFailed.LastTransitionTime != nil { | ||
cond.LastTransitionTime = *subResFailed.LastTransitionTime | ||
} | ||
|
||
return mergedSub, nil, updateStatus(policy, cond, nonCompObj(foundSub, subResFailed.Reason)), nil | ||
return mergedSub, nil, updateStatus( | ||
policy, subResFailedCond(subResFailed), nonCompObj(foundSub, subResFailed.Reason)), nil | ||
} | ||
|
||
return mergedSub, nil, false, nil | ||
} | ||
|
||
return mergedSub, nil, updateStatus(policy, matchesCond("Subscription"), matchedObj(foundSub)), nil | ||
|
@@ -727,6 +727,37 @@ func messageIncludesSubscription(subscription *operatorv1alpha1.Subscription, me | |
return regexp.MatchString(regex, message) | ||
} | ||
|
||
// constraintMessageMatch checks if the ConstraintsNotSatisfiable message is actually different | ||
// from the old one by sorting the clauses of the message | ||
func constraintMessageMatch(policy *policyv1beta1.OperatorPolicy, cond *operatorv1alpha1.SubscriptionCondition) bool { | ||
const cnfPrefix = "constraints not satisfiable: " | ||
|
||
var policyMessage, subMessage string | ||
|
||
for _, statusCond := range policy.Status.Conditions { | ||
if strings.Contains(statusCond.Message, cnfPrefix) { | ||
policyMessage = statusCond.Message | ||
} | ||
} | ||
|
||
if policyMessage == "" || !strings.Contains(cond.Message, cnfPrefix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better! |
||
return false | ||
} | ||
|
||
policyMessage = strings.TrimPrefix(policyMessage, cnfPrefix) | ||
subMessage = strings.TrimPrefix(cond.Message, cnfPrefix) | ||
|
||
// The ConstraintsNotSatisfiable message is always formatted as follows: | ||
// constraints not satisfiable: clause1, clause2, clause3 ... | ||
policyMessageSlice := strings.Split(policyMessage, ", ") | ||
slices.Sort(policyMessageSlice) | ||
|
||
subMessageSlice := strings.Split(subMessage, ", ") | ||
slices.Sort(subMessageSlice) | ||
|
||
return reflect.DeepEqual(policyMessageSlice, subMessageSlice) | ||
} | ||
|
||
func (r *OperatorPolicyReconciler) handleInstallPlan( | ||
ctx context.Context, policy *policyv1beta1.OperatorPolicy, sub *operatorv1alpha1.Subscription, | ||
) (bool, error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
Is there a reason not to break out of the loop after this assignment?