Skip to content

Commit

Permalink
Add DeprecationsPresent to ComplianceConfigAction
Browse files Browse the repository at this point in the history
Add DeprecationsPresent to ComplianceConfigAction
Signed-off-by: yiraeChristineKim <[email protected]>
  • Loading branch information
yiraeChristineKim authored and openshift-merge-bot[bot] committed Jan 28, 2025
1 parent 5515623 commit c3c1716
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
7 changes: 7 additions & 0 deletions api/v1beta1/operatorpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ type ComplianceConfig struct {
//
//+kubebuilder:default=Compliant
UpgradesAvailable ComplianceConfigAction `json:"upgradesAvailable,omitempty"`
// DeprecationsPresent specifies how the overall policy compliance is affected by deprecations.
// The default value is `Compliant`. If any deprecations are detected
// while DeprecationsPresent = NonCompliant,
// then the policy compliance will be set to `NonCompliant`.
//
// +kubebuilder:default=Compliant
DeprecationsPresent ComplianceConfigAction `json:"deprecationsPresent,omitempty"`
}

// OperatorPolicySpec defines the desired state of a particular operator on the cluster.
Expand Down
3 changes: 2 additions & 1 deletion controllers/operatorpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ func calculateComplianceCondition(policy *policyv1beta1.OperatorPolicy) metav1.C
}

idx, cond = policy.Status.GetCondition(deprecationType)
if !policy.Spec.ComplianceType.IsMustNotHave() {
if !policy.Spec.ComplianceType.IsMustNotHave() &&
policy.Spec.ComplianceConfig.DeprecationsPresent == "NonCompliant" {
if idx == -1 {
messages = append(messages, "The deprecation status is unknown")
foundNonCompliant = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ spec:
- Compliant
- NonCompliant
type: string
deprecationsPresent:
default: Compliant
description: |-
DeprecationsPresent specifies how the overall policy compliance is affected by deprecations.
The default value is `Compliant`. If any deprecations are detected
while DeprecationsPresent = NonCompliant,
then the policy compliance will be set to `NonCompliant`.
enum:
- Compliant
- NonCompliant
type: string
upgradesAvailable:
default: Compliant
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ spec:
- Compliant
- NonCompliant
type: string
deprecationsPresent:
default: Compliant
description: |-
DeprecationsPresent specifies how the overall policy compliance is affected by deprecations.
The default value is `Compliant`. If any deprecations are detected
while DeprecationsPresent = NonCompliant,
then the policy compliance will be set to `NonCompliant`.
enum:
- Compliant
- NonCompliant
type: string
upgradesAvailable:
default: Compliant
description: |-
Expand Down
31 changes: 28 additions & 3 deletions test/e2e/case38_install_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3766,7 +3766,7 @@ var _ = Describe("Testing OperatorPolicy", Ordered, Label("supports-hosted"), fu
[]policyv1.RelatedObject{},
metav1.Condition{
Type: "NoDeprecations",
Status: metav1.ConditionTrue,
Status: metav1.ConditionFalse,
Reason: "PackageDeprecated",
Message: "the requested deprecation-operator Package was deprecated. " +
"deprecation-operator is end of life. Please don't use this package.",
Expand All @@ -3787,7 +3787,7 @@ var _ = Describe("Testing OperatorPolicy", Ordered, Label("supports-hosted"), fu
[]policyv1.RelatedObject{},
metav1.Condition{
Type: "NoDeprecations",
Status: metav1.ConditionTrue,
Status: metav1.ConditionFalse,
Reason: "ChannelDeprecated",
Message: "the requested alpha Channel was deprecated. " +
"channel alpha is no longer supported. Please switch to channel 'stable'",
Expand All @@ -3808,7 +3808,32 @@ var _ = Describe("Testing OperatorPolicy", Ordered, Label("supports-hosted"), fu
[]policyv1.RelatedObject{},
metav1.Condition{
Type: "NoDeprecations",
Status: metav1.ConditionTrue,
Status: metav1.ConditionFalse,
Reason: "BundleDeprecated",
Message: "the requested dep-bundle-operator.v0.0.1 Bundle was deprecated. " +
"dep-bundle-operator.v0.0.1 bundle is no longer supported.",
},
"",
)
})
It("Should have deprecation message is displayed and policy compliance is Compliant "+
"when bundle is deprecated and deprecationAvaliable is set to NonCompliant",
func(_ SpecContext) {
createObjWithParent(parentPolicyYAML, parentPolicyName,
bundlePolYAML, testNamespace, gvrPolicy, gvrOperatorPolicy)

utils.Kubectl("patch", "operatorpolicy", bundlePolName, "-n", testNamespace, "--type=json", "-p",
`[{"op": "replace",
"path": "/spec/complianceConfig/deprecationsPresent",
"value": "NonCompliant"}]`)

check(
bundlePolName,
true,
[]policyv1.RelatedObject{},
metav1.Condition{
Type: "NoDeprecations",
Status: metav1.ConditionFalse,
Reason: "BundleDeprecated",
Message: "the requested dep-bundle-operator.v0.0.1 Bundle was deprecated. " +
"dep-bundle-operator.v0.0.1 bundle is no longer supported.",
Expand Down

0 comments on commit c3c1716

Please sign in to comment.