-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an error when apiVersion is missing
The apiVersion field is generally required by kubernetes objects... it's surprising that this situation wasn't already caught by an error when decoding or getting a mapping. Refs: - https://issues.redhat.com/browse/ACM-7127 Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
- Loading branch information
1 parent
de86a78
commit 819021e
Showing
5 changed files
with
127 additions
and
0 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2023 Red Hat, Inc. | ||
// Copyright Contributors to the Open Cluster Management project | ||
|
||
package e2e | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"open-cluster-management.io/config-policy-controller/test/utils" | ||
) | ||
|
||
var _ = Describe("Test a policy with an objectDefinition that is missing apiVersion", Ordered, func() { | ||
const ( | ||
rsrcPath = "../resources/case35_no_apiversion/" | ||
policyYAML = rsrcPath + "policy.yaml" | ||
policyName = "case35-parent" | ||
cfgPlcYAML = rsrcPath + "config-policy.yaml" | ||
cfgPlcName = "case35-cfgpol" | ||
) | ||
|
||
It("Should have the expected events", func() { | ||
By("Setting up the policy") | ||
createConfigPolicyWithParent(policyYAML, policyName, cfgPlcYAML) | ||
|
||
By("Checking there is a NonCompliant event on the policy") | ||
Eventually(func() interface{} { | ||
return utils.GetMatchingEvents(clientManaged, testNamespace, | ||
policyName, cfgPlcName, "^NonCompliant;.*missing apiVersion", defaultTimeoutSeconds) | ||
}, defaultTimeoutSeconds, 5).ShouldNot(BeEmpty()) | ||
|
||
By("Checking there are no Compliant events on the policy") | ||
Consistently(func() interface{} { | ||
return utils.GetMatchingEvents(clientManaged, testNamespace, | ||
policyName, cfgPlcName, "^Compliant;", defaultTimeoutSeconds) | ||
}, defaultTimeoutSeconds, 5).Should(BeEmpty()) | ||
}) | ||
|
||
AfterAll(func() { | ||
utils.Kubectl("delete", "policy", policyName, "-n", "managed", "--ignore-not-found") | ||
configPlc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
cfgPlcName, "managed", false, defaultTimeoutSeconds, | ||
) | ||
Expect(configPlc).To(BeNil()) | ||
utils.Kubectl("delete", "event", "--field-selector=involvedObject.name="+policyName, "-n", "managed") | ||
utils.Kubectl("delete", "event", "--field-selector=involvedObject.name="+cfgPlcName, "-n", "managed") | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: case35-cfgpol | ||
ownerReferences: | ||
- apiVersion: policy.open-cluster-management.io/v1 | ||
blockOwnerDeletion: false | ||
controller: true | ||
kind: Policy | ||
name: case35-parent | ||
uid: 08bae967-4262-498a-84e9-d1f0e321b41e # to be replaced! | ||
spec: | ||
remediationAction: enforce | ||
severity: low | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
kind: ConfigMap | ||
metadata: | ||
name: case35-cfgmap | ||
namespace: default | ||
data: | ||
foo: bar |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: Policy | ||
metadata: | ||
name: case35-parent | ||
spec: | ||
disabled: false | ||
remediationAction: enforce | ||
policy-templates: | ||
- objectDefinition: | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: case35-cfgpol | ||
spec: | ||
remediationAction: enforce | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
kind: ConfigMap | ||
metadata: | ||
name: case35-cfgmap | ||
namespace: default | ||
data: | ||
foo: bar |