Skip to content

Commit e62600f

Browse files
dhaiducekopenshift-merge-bot[bot]
authored andcommitted
Add test for configuring add-ons
ref: https://issues.redhat.com/browse/ACM-17979 Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
1 parent 86c9bfb commit e62600f

File tree

7 files changed

+227
-0
lines changed

7 files changed

+227
-0
lines changed

test/common/gvr.go

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ var (
157157
Version: "v1alpha1",
158158
Resource: "clustermanagementaddons",
159159
}
160+
GvrManagedClusterAddOn = schema.GroupVersionResource{
161+
Group: "addon.open-cluster-management.io",
162+
Version: "v1alpha1",
163+
Resource: "managedclusteraddons",
164+
}
160165
GvrManagedClusterSetBinding = schema.GroupVersionResource{
161166
Group: "cluster.open-cluster-management.io",
162167
Version: "v1beta2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright (c) 2022 Red Hat, Inc.
2+
// Copyright Contributors to the Open Cluster Management project
3+
4+
package integration
5+
6+
import (
7+
"encoding/json"
8+
9+
. "github.com/onsi/ginkgo/v2"
10+
. "github.com/onsi/gomega"
11+
appsv1 "k8s.io/api/apps/v1"
12+
corev1 "k8s.io/api/core/v1"
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
15+
"github.com/stolostron/governance-policy-framework/test/common"
16+
)
17+
18+
var _ = Describe("GRC: [P1][Sev1][policy-grc] Test add-on configuration", Serial, Label("SVT"), func() {
19+
BeforeEach(func(ctx SpecContext) {
20+
DeferCleanup(func() {
21+
_, _ = common.OcHub("delete", "namespace", "grc-addon-config-test")
22+
})
23+
24+
By("Deploying AddonDeploymentConfig grc-addon-config")
25+
_, _ = common.OcHub("create", "namespace", "grc-addon-config-test")
26+
_, err := common.OcHub(
27+
"apply",
28+
"-n=grc-addon-config-test",
29+
"-f=../resources/addon_configuration/addondeploymentconfig.yaml")
30+
Expect(err).ToNot(HaveOccurred())
31+
})
32+
33+
DescribeTable("",
34+
addonTest,
35+
Entry(nil, "governance-policy-framework"),
36+
Entry(nil, "config-policy-controller"),
37+
Entry(nil, "cert-policy-controller"),
38+
)
39+
})
40+
41+
var addonTest = func(ctx SpecContext, addOn string) {
42+
var (
43+
expectedResources = `{"limits":{"memory":"1Gi"},"requests":{"memory":"512Mi"}}`
44+
expectedNodeSelector = `{"kubernetes.io/os":"linux"}`
45+
expectedTolerations = `[{"key":"dedicated","operator":"Equal","value":"something-else","effect":"NoSchedule"}]`
46+
)
47+
48+
// Restore AddOns regardless of test result
49+
DeferCleanup(func() {
50+
_, _ = common.OcHub(
51+
"patch",
52+
"managedclusteraddon",
53+
"-n", clusterNamespace,
54+
addOn,
55+
"--type=json",
56+
"--patch-file=../resources/addon_configuration/mcao_restore_patch.json",
57+
)
58+
_, _ = common.OcHub(
59+
"patch",
60+
"clustermanagementaddon",
61+
addOn,
62+
"--type=json",
63+
"--patch-file=../resources/addon_configuration/cmao_restore_patch.json",
64+
)
65+
})
66+
67+
fetchDeployment := func(g Gomega) (*appsv1.Deployment, corev1.Container) {
68+
deployment, err := clientManaged.AppsV1().Deployments(ocmAddonNS).Get(ctx, addOn, metav1.GetOptions{})
69+
Expect(err).ToNot(HaveOccurred())
70+
container := deployment.Spec.Template.Spec.Containers
71+
g.Expect(container).To(HaveLen(1))
72+
73+
return deployment, container[0]
74+
}
75+
76+
By("Fetching Deployment to determine default configuration")
77+
baseDeployment, baseContainer := fetchDeployment(Default)
78+
79+
By("Attaching the AddOnDeploymentConfig to the ManagedClusterAddOn for " + addOn)
80+
_, err := common.OcHub(
81+
"patch",
82+
"managedclusteraddon",
83+
"-n", clusterNamespace,
84+
addOn,
85+
"--type=json",
86+
"--patch-file=../resources/addon_configuration/mcao_config_patch.json",
87+
)
88+
Expect(err).ToNot(HaveOccurred())
89+
Eventually(func(g Gomega) {
90+
deployment, container := fetchDeployment(g)
91+
// Check Resources
92+
g.Expect(json.Marshal(container.Resources)).Should(BeEquivalentTo(expectedResources))
93+
// Check NodeSelector
94+
g.Expect(json.Marshal(deployment.Spec.Template.Spec.NodeSelector)).Should(BeEquivalentTo(expectedNodeSelector))
95+
// Check Tolerations
96+
g.Expect(json.Marshal(deployment.Spec.Template.Spec.Tolerations)).Should(BeEquivalentTo(expectedTolerations))
97+
}, defaultTimeoutSeconds*2, 1).Should(Succeed())
98+
99+
By("Restoring the ManagedClusterAddOn for " + addOn)
100+
_, err = common.OcHub(
101+
"patch",
102+
"managedclusteraddon",
103+
"-n", clusterNamespace,
104+
addOn,
105+
"--type=json",
106+
"--patch-file=../resources/addon_configuration/mcao_restore_patch.json",
107+
)
108+
Expect(err).ToNot(HaveOccurred())
109+
Eventually(func(g Gomega) {
110+
deployment, container := fetchDeployment(g)
111+
g.Expect(
112+
deployment.Spec.Template.Spec.NodeSelector,
113+
).Should(Equal(
114+
baseDeployment.Spec.Template.Spec.NodeSelector,
115+
))
116+
g.Expect(container.Resources).Should(Equal(baseContainer.Resources))
117+
}, defaultTimeoutSeconds*2, 1).Should(Succeed())
118+
119+
By("Attaching the AddOnDeploymentConfig to the ClusterManagementAddOn for " + addOn)
120+
_, err = common.OcHub(
121+
"patch",
122+
"clustermanagementaddon",
123+
addOn,
124+
"--type=json",
125+
"--patch-file=../resources/addon_configuration/cmao_config_patch.json",
126+
)
127+
Expect(err).ToNot(HaveOccurred())
128+
Eventually(func(g Gomega) {
129+
deployment, container := fetchDeployment(g)
130+
// Check Resources
131+
g.Expect(json.Marshal(container.Resources)).Should(BeEquivalentTo(expectedResources))
132+
// Check NodeSelector
133+
g.Expect(json.Marshal(deployment.Spec.Template.Spec.NodeSelector)).Should(BeEquivalentTo(expectedNodeSelector))
134+
// Check Tolerations
135+
g.Expect(json.Marshal(deployment.Spec.Template.Spec.Tolerations)).Should(BeEquivalentTo(expectedTolerations))
136+
}, defaultTimeoutSeconds*2, 1).Should(Succeed())
137+
138+
By("Restoring the ManagedClusterAddOn for " + addOn)
139+
_, err = common.OcHub(
140+
"patch",
141+
"clustermanagementaddon",
142+
addOn,
143+
"--type=json",
144+
"--patch-file=../resources/addon_configuration/cmao_restore_patch.json",
145+
)
146+
Expect(err).ToNot(HaveOccurred())
147+
Eventually(func(g Gomega) {
148+
deployment, container := fetchDeployment(g)
149+
g.Expect(
150+
deployment.Spec.Template.Spec.NodeSelector,
151+
).Should(Equal(
152+
baseDeployment.Spec.Template.Spec.NodeSelector,
153+
))
154+
g.Expect(container.Resources).Should(Equal(baseContainer.Resources))
155+
}, defaultTimeoutSeconds*2, 1).Should(Succeed())
156+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: addon.open-cluster-management.io/v1alpha1
2+
kind: AddOnDeploymentConfig
3+
metadata:
4+
name: grc-addon-config
5+
spec:
6+
nodePlacement:
7+
nodeSelector:
8+
"kubernetes.io/os": "linux"
9+
tolerations:
10+
- key: "dedicated"
11+
operator: "Equal"
12+
value: "something-else"
13+
effect: "NoSchedule"
14+
resourceRequirements:
15+
- containerID: "*:*:*"
16+
resources:
17+
requests:
18+
memory: 512Mi
19+
limits:
20+
memory: 1Gi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"op": "replace",
4+
"path": "/spec/supportedConfigs",
5+
"value": [
6+
{
7+
"group": "addon.open-cluster-management.io",
8+
"resource": "addondeploymentconfigs",
9+
"defaultConfig": { "name": "grc-addon-config", "namespace": "grc-addon-config-test" }
10+
}
11+
]
12+
}
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"op": "replace",
4+
"path": "/spec/supportedConfigs",
5+
"value": [
6+
{
7+
"group": "addon.open-cluster-management.io",
8+
"resource": "addondeploymentconfigs"
9+
}
10+
]
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"op": "replace",
4+
"path": "/spec/configs",
5+
"value": [
6+
{
7+
"group": "addon.open-cluster-management.io",
8+
"resource": "addondeploymentconfigs",
9+
"name": "grc-addon-config",
10+
"namespace": "grc-addon-config-test"
11+
}
12+
]
13+
}
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "replace",
4+
"path": "/spec/configs",
5+
"value": []
6+
}
7+
]

0 commit comments

Comments
 (0)