-
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.
Signed-off-by: Will Kutler <wkutler@redhat.com>
- Loading branch information
1 parent
1f2a2e8
commit 8f77229
Showing
4 changed files
with
122 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2020 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" | ||
) | ||
|
||
const ( | ||
case27ConfigPolicyName string = "policy-pod-create" | ||
case27CreateYaml string = "../resources/case27_showupdateinstatus/case27-create-pod-policy.yaml" | ||
case27UpdateYaml string = "../resources/case27_showupdateinstatus/case27-update-pod-policy.yaml" | ||
) | ||
|
||
var _ = Describe("Test cluster version obj template handling", func() { | ||
Describe("enforce patch on unnamespaced resource clusterversion "+testNamespace, func() { | ||
It("should be created properly on the managed cluster", func() { | ||
By("Creating " + case27ConfigPolicyName + " on managed") | ||
utils.Kubectl("apply", "-f", case27CreateYaml, "-n", testNamespace) | ||
plc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case27ConfigPolicyName, testNamespace, true, defaultTimeoutSeconds) | ||
Expect(plc).NotTo(BeNil()) | ||
Eventually(func() interface{} { | ||
managedPlc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case27ConfigPolicyName, testNamespace, true, defaultTimeoutSeconds) | ||
|
||
return utils.GetStatusMessage(managedPlc) | ||
}, 120, 1).Should(Equal( | ||
"pods [nginx-pod-e2e] in namespace default found as specified, therefore this Object template is compliant")) | ||
}) | ||
It("should be updated properly on the managed cluster", func() { | ||
By("Creating " + case27ConfigPolicyName + " on managed") | ||
utils.Kubectl("apply", "-f", case27UpdateYaml, "-n", testNamespace) | ||
Eventually(func() interface{} { | ||
managedPlc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case27ConfigPolicyName, testNamespace, true, defaultTimeoutSeconds) | ||
|
||
return utils.GetStatusMessage(managedPlc) | ||
}, 30, 0.5).Should(Equal( | ||
"pods [nginx-pod-e2e] in namespace default was updated successfully")) | ||
}) | ||
It("Cleans up", func() { | ||
deleteConfigPolicies([]string{case27ConfigPolicyName}) | ||
utils.Kubectl("delete", "pod", "nginx-pod-e2e") | ||
}) | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
test/resources/case27_showupdateinstatus/case27-create-pod-policy.yaml
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,22 @@ | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: policy-pod-create | ||
spec: | ||
remediationAction: enforce | ||
namespaceSelector: | ||
exclude: ["kube-*"] | ||
include: ["default"] | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-pod-e2e | ||
spec: | ||
containers: | ||
- image: nginx:1.7.9 | ||
name: nginx | ||
ports: | ||
- containerPort: 80 |
24 changes: 24 additions & 0 deletions
24
test/resources/case27_showupdateinstatus/case27-update-pod-policy.yaml
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: ConfigurationPolicy | ||
metadata: | ||
name: policy-pod-create | ||
spec: | ||
remediationAction: enforce | ||
namespaceSelector: | ||
exclude: ["kube-*"] | ||
include: ["default"] | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-pod-e2e | ||
labels: | ||
test: test | ||
spec: | ||
containers: | ||
- image: nginx:1.7.9 | ||
name: nginx | ||
ports: | ||
- containerPort: 80 |