Skip to content

Commit

Permalink
Include the CSV name in compliance messages
Browse files Browse the repository at this point in the history
Relates:
https://issues.redhat.com/browse/ACM-11026

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl authored and openshift-merge-bot[bot] committed Apr 24, 2024
1 parent 5fdf739 commit 8206ac6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
11 changes: 7 additions & 4 deletions controllers/operatorpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,11 +1413,14 @@ func (r *OperatorPolicyReconciler) mustnothaveCSV(
return nil, updateStatus(policy, keptCond("ClusterServiceVersion"), relatedCSVs...), nil
}

csvNames := make([]string, 0, len(csvList))

for i := range csvList {
relatedCSVs = append(relatedCSVs, foundNotWantedObj(&csvList[i]))
csvNames = append(csvNames, csvList[i].GetName())
}

changed := updateStatus(policy, foundNotWantedCond("ClusterServiceVersion"), relatedCSVs...)
changed := updateStatus(policy, foundNotWantedCond("ClusterServiceVersion", csvNames...), relatedCSVs...)

if policy.Spec.RemediationAction.IsInform() {
return nil, changed, nil
Expand All @@ -1441,7 +1444,7 @@ func (r *OperatorPolicyReconciler) mustnothaveCSV(

err := r.Delete(ctx, &csvList[i])
if err != nil {
changed := updateStatus(policy, foundNotWantedCond("ClusterServiceVersion"), relatedCSVs...)
changed := updateStatus(policy, foundNotWantedCond("ClusterServiceVersion", csvNames...), relatedCSVs...)

if anyAlreadyDeleting {
// reset the "early" conditions to avoid flapping
Expand All @@ -1459,10 +1462,10 @@ func (r *OperatorPolicyReconciler) mustnothaveCSV(
// reset the "early" conditions to avoid flapping
earlyConds = []metav1.Condition{}

return earlyConds, updateStatus(policy, deletingCond("ClusterServiceVersion"), relatedCSVs...), nil
return earlyConds, updateStatus(policy, deletingCond("ClusterServiceVersion", csvNames...), relatedCSVs...), nil
}

updateStatus(policy, deletedCond("ClusterServiceVersion"), relatedCSVs...)
updateStatus(policy, deletedCond("ClusterServiceVersion", csvNames...), relatedCSVs...)

return earlyConds, true, nil
}
Expand Down
44 changes: 37 additions & 7 deletions controllers/operatorpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,22 @@ func missingNotWantedCond(kind string) metav1.Condition {

// foundNotWantedCond returns a NonCompliant condition with a Reason like '____Present'
// and a Message like 'the ____ is present'
func foundNotWantedCond(kind string) metav1.Condition {
func foundNotWantedCond(kind string, identifiers ...string) metav1.Condition {
var extraInfo string

if len(identifiers) == 1 {
extraInfo = fmt.Sprintf(" (%s) is", identifiers[0])
} else if len(identifiers) > 1 {
extraInfo = fmt.Sprintf("s (%s) are", strings.Join(identifiers, ", "))
} else {
extraInfo = " is"
}

return metav1.Condition{
Type: condType(kind),
Status: metav1.ConditionFalse,
Reason: kind + "Present",
Message: "the " + kind + " is present",
Message: "the " + kind + extraInfo + " present",
}
}

Expand All @@ -450,23 +460,43 @@ func createdCond(kind string) metav1.Condition {

// deletedCond returns a Compliant condition, with a Reason like '____Deleted',
// and a Message like 'the ____ was deleted'
func deletedCond(kind string) metav1.Condition {
func deletedCond(kind string, identifiers ...string) metav1.Condition {
var extraInfo string

if len(identifiers) == 1 {
extraInfo = fmt.Sprintf(" (%s) was", identifiers[0])
} else if len(identifiers) > 1 {
extraInfo = fmt.Sprintf("s (%s) were", strings.Join(identifiers, ", "))
} else {
extraInfo = " was"
}

return metav1.Condition{
Type: condType(kind),
Status: metav1.ConditionTrue,
Reason: kind + "Deleted",
Message: "the " + kind + " was deleted",
Message: "the " + kind + extraInfo + " deleted",
}
}

// deletingCond returns a NonCompliant condition, with a Reason like '____Deleting',
// and a Message like 'the ____ has a deletion timestamp'
func deletingCond(kind string) metav1.Condition {
func deletingCond(kind string, identifiers ...string) metav1.Condition {
var extraInfo string

if len(identifiers) == 1 {
extraInfo = fmt.Sprintf(" (%s) has", identifiers[0])
} else if len(identifiers) > 1 {
extraInfo = fmt.Sprintf("s (%s) have", strings.Join(identifiers, ", "))
} else {
extraInfo = " has"
}

return metav1.Condition{
Type: condType(kind),
Status: metav1.ConditionFalse,
Reason: kind + "Deleting",
Message: "the " + kind + " has a deletion timestamp",
Message: "the " + kind + extraInfo + " a deletion timestamp",
}
}

Expand Down Expand Up @@ -687,7 +717,7 @@ func buildCSVCond(csv *operatorv1alpha1.ClusterServiceVersion) metav1.Condition
Type: condType(csv.Kind),
Status: status,
Reason: string(csv.Status.Reason),
Message: "ClusterServiceVersion - " + csv.Status.Message,
Message: "ClusterServiceVersion (" + csv.Name + ") - " + csv.Status.Message,
}
}

Expand Down
33 changes: 19 additions & 14 deletions test/e2e/case38_install_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,15 @@ var _ = Describe("Testing OperatorPolicy", Ordered, func() {
Reason: "InstallSucceeded",
}},
metav1.Condition{
Type: "ClusterServiceVersionCompliant",
Status: metav1.ConditionTrue,
Reason: "InstallSucceeded",
Message: "ClusterServiceVersion - install strategy completed with no errors",
Type: "ClusterServiceVersionCompliant",
Status: metav1.ConditionTrue,
Reason: "InstallSucceeded",
Message: "ClusterServiceVersion (quay-operator.v3.8.13) - install strategy completed with " +
"no errors",
},
"ClusterServiceVersion - install strategy completed with no errors",
regexp.QuoteMeta(
"ClusterServiceVersion (quay-operator.v3.8.13) - install strategy completed with no errors",
),
)
})

Expand Down Expand Up @@ -863,11 +866,13 @@ var _ = Describe("Testing OperatorPolicy", Ordered, func() {
Type: "ClusterServiceVersionCompliant",
Status: metav1.ConditionFalse,
Reason: "UnsupportedOperatorGroup",
Message: "ClusterServiceVersion - AllNamespaces InstallModeType not supported," +
" cannot configure to watch all namespaces",
Message: "ClusterServiceVersion (etcdoperator.v0.9.2) - AllNamespaces InstallModeType not " +
"supported, cannot configure to watch all namespaces",
},
"ClusterServiceVersion - AllNamespaces InstallModeType not supported,"+
" cannot configure to watch all namespaces",
regexp.QuoteMeta(
"ClusterServiceVersion (etcdoperator.v0.9.2) - AllNamespaces InstallModeType not supported,"+
" cannot configure to watch all namespaces",
),
)
})

Expand Down Expand Up @@ -1808,9 +1813,9 @@ var _ = Describe("Testing OperatorPolicy", Ordered, func() {
Type: "ClusterServiceVersionCompliant",
Status: metav1.ConditionFalse,
Reason: "ClusterServiceVersionPresent",
Message: "the ClusterServiceVersion is present",
Message: "the ClusterServiceVersion (quay-operator.v3.8.13) is present",
},
`the ClusterServiceVersion is present`,
regexp.QuoteMeta("the ClusterServiceVersion (quay-operator.v3.8.13) is present"),
)
check(
opPolName,
Expand Down Expand Up @@ -2142,9 +2147,9 @@ var _ = Describe("Testing OperatorPolicy", Ordered, func() {
Type: "ClusterServiceVersionCompliant",
Status: metav1.ConditionFalse,
Reason: "ClusterServiceVersionDeleting",
Message: "the ClusterServiceVersion has a deletion timestamp",
Message: "the ClusterServiceVersion (" + csvName + ") has a deletion timestamp",
},
`the ClusterServiceVersion was deleted`,
regexp.QuoteMeta("the ClusterServiceVersion ("+csvName+") was deleted"),
)
desiredCRDObjects := make([]policyv1.RelatedObject, 0)
for _, name := range crdNames {
Expand Down Expand Up @@ -2275,7 +2280,7 @@ var _ = Describe("Testing OperatorPolicy", Ordered, func() {
Reason: "ClusterServiceVersionNotPresent",
Message: "the ClusterServiceVersion is not present",
},
`the ClusterServiceVersion was deleted`,
regexp.QuoteMeta("the ClusterServiceVersion (quay-operator.v3.8.13) was deleted"),
)
check(
opPolName,
Expand Down

0 comments on commit 8206ac6

Please sign in to comment.