Skip to content

Commit 1b60f9f

Browse files
Merge pull request #825 from mrniranjan/bz_1967911
BZ 1967911: E2E Test cases for enabling unsafe sysctl in performance profile
2 parents 0aa227d + 81c0292 commit 1b60f9f

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package __performance_update
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strconv"
7+
"strings"
8+
9+
. "github.com/onsi/ginkgo"
10+
. "github.com/onsi/gomega"
11+
12+
corev1 "k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/api/resource"
14+
"k8s.io/apimachinery/pkg/types"
15+
"sigs.k8s.io/controller-runtime/pkg/client"
16+
17+
performancev2 "github.com/openshift-kni/performance-addon-operators/api/v2"
18+
testutils "github.com/openshift-kni/performance-addon-operators/functests/utils"
19+
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
20+
"github.com/openshift-kni/performance-addon-operators/functests/utils/discovery"
21+
"github.com/openshift-kni/performance-addon-operators/functests/utils/mcps"
22+
"github.com/openshift-kni/performance-addon-operators/functests/utils/nodes"
23+
"github.com/openshift-kni/performance-addon-operators/functests/utils/profiles"
24+
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
25+
)
26+
27+
var _ = Describe("[ref_id: 45487][performance]additional kubelet arguments", func() {
28+
var profile *performancev2.PerformanceProfile
29+
var workerRTNodes []corev1.Node
30+
var performanceMCP string
31+
32+
testutils.BeforeAll(func() {
33+
workerRTNodes, err := nodes.GetByLabels(testutils.NodeSelectorLabels)
34+
Expect(err).ToNot(HaveOccurred())
35+
36+
workerRTNodes, err = nodes.MatchingOptionalSelector(workerRTNodes)
37+
Expect(err).ToNot(HaveOccurred())
38+
39+
profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
40+
Expect(err).ToNot(HaveOccurred())
41+
42+
performanceMCP, err = mcps.GetByProfile(profile)
43+
Expect(err).ToNot(HaveOccurred())
44+
45+
// Verify that worker and performance MCP have updated state equals to true
46+
for _, mcpName := range []string{testutils.RoleWorker, performanceMCP} {
47+
mcps.WaitForCondition(mcpName, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
48+
}
49+
50+
})
51+
BeforeEach(func() {
52+
if discovery.Enabled() && testutils.ProfileNotFound {
53+
Skip("Discovery mode enabled, performance profile not found")
54+
}
55+
})
56+
Context("Additional kubelet arguments", func() {
57+
It("[test_id:45488]Test performance profile annotation for changing multiple kubelet settings", func() {
58+
sysctlAnnotations := map[string]string{
59+
"kubeletconfig.experimental": "{\"allowedUnsafeSysctls\":[\"net.core.somaxconn\",\"kernel.msg*\"],\"systemReserved\":{\"memory\":\"300Mi\"},\"kubeReserved\":{\"memory\":\"768Mi\"},\"imageMinimumGCAge\":\"3m\"}",
60+
}
61+
profile.SetAnnotations(sysctlAnnotations)
62+
By("Applying changes in performance profile and waiting until mcp will start updating")
63+
profiles.UpdateWithRetry(profile)
64+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdating, corev1.ConditionTrue)
65+
By("Waiting when mcp finishes updates")
66+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
67+
for _, node := range workerRTNodes {
68+
kubeletConfig, err := nodes.GetKubeletConfig(&node)
69+
Expect(err).ToNot(HaveOccurred())
70+
sysctlsValue := kubeletConfig.AllowedUnsafeSysctls
71+
Expect(sysctlsValue).Should(ContainElements("net.core.somaxconn", "kernel.msg*"))
72+
Expect(kubeletConfig.KubeReserved["memory"]).To(Equal("768Mi"))
73+
Expect(kubeletConfig.ImageMinimumGCAge.Seconds()).To(Equal(180))
74+
}
75+
kubeletArguments := []string{"/bin/bash", "-c", "ps -ef | grep kubelet | grep config"}
76+
for _, node := range workerRTNodes {
77+
stdout, err := nodes.ExecCommandOnNode(kubeletArguments, &node)
78+
Expect(err).ToNot(HaveOccurred())
79+
Expect(strings.Contains(stdout, "300Mi")).To(BeTrue())
80+
}
81+
})
82+
Context("When setting cpu manager related parameters", func() {
83+
It("[test_id:45493]Should not override performance-addon-operator values", func() {
84+
cpuManagerAnnotation := map[string]string{
85+
"kubeletconfig.experimental": "{\"cpuManagerPolicy\":\"static\",\"cpuManagerReconcilePeriod\":\"5s\"}",
86+
}
87+
profile.SetAnnotations(cpuManagerAnnotation)
88+
By("Applying changes in performance profile and waiting until mcp will start updating")
89+
profiles.UpdateWithRetry(profile)
90+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdating, corev1.ConditionTrue)
91+
By("Waiting when mcp finishes updates")
92+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
93+
for _, node := range workerRTNodes {
94+
kubeletConfig, err := nodes.GetKubeletConfig(&node)
95+
Expect(err).ToNot(HaveOccurred())
96+
Expect(kubeletConfig.CPUManagerPolicy).Should(Equal("static"))
97+
Expect(kubeletConfig.CPUManagerReconcilePeriod.Seconds()).To(Equal(5))
98+
}
99+
})
100+
})
101+
It("[test_id:45490]Test memory reservation changes", func() {
102+
// In this test case we are testing if after applying reserving memory for
103+
// systemReserved and KubeReserved, the allocatable is reduced and Allocatable
104+
// Verify that Allocatable = Node capacity - (kubereserved + systemReserved + EvictionMemory)
105+
memoryAnnotation := map[string]string{
106+
"kubeletconfig.experimental": "{\"systemReserved\":{\"memory\":\"300Mi\"},\"kubeReserved\":{\"memory\":\"768Mi\"}}",
107+
}
108+
profile.SetAnnotations(memoryAnnotation)
109+
By("Applying changes in performance profile and waiting until mcp will start updating")
110+
profiles.UpdateWithRetry(profile)
111+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdating, corev1.ConditionTrue)
112+
By("Waiting when mcp finishes updates")
113+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
114+
for _, node := range workerRTNodes {
115+
kubeletConfig, err := nodes.GetKubeletConfig(&node)
116+
Expect(err).ToNot(HaveOccurred())
117+
totalCapactity := node.Status.Capacity.Memory().MilliValue()
118+
evictionMemory := kubeletConfig.EvictionHard["memory.available"]
119+
kubeReserved := kubeletConfig.KubeReserved["memory"]
120+
evictionMemoryInt, err := strconv.ParseInt(strings.TrimSuffix(evictionMemory, "Mi"), 10, 64)
121+
kubeReservedMemoryInt, err := strconv.ParseInt(strings.TrimSuffix(kubeReserved, "Mi"), 10, 64)
122+
systemReservedResource := resource.NewQuantity(300*1024*1024, resource.BinarySI)
123+
kubeReservedMemoryResource := resource.NewQuantity(kubeReservedMemoryInt*1024*1024, resource.BinarySI)
124+
evictionMemoryResource := resource.NewQuantity(evictionMemoryInt*1024*1024, resource.BinarySI)
125+
totalKubeMemory := systemReservedResource.MilliValue() + kubeReservedMemoryResource.MilliValue() + evictionMemoryResource.MilliValue()
126+
calculatedAllocatable := totalCapactity - totalKubeMemory
127+
currentAllocatable := node.Status.Allocatable.Memory().MilliValue()
128+
Expect(calculatedAllocatable).To(Equal(currentAllocatable))
129+
}
130+
})
131+
It("[test_id:45495] Test setting PAO managed parameters", func() {
132+
paoAnnotation := map[string]string{
133+
"kubeletconfig.experimental": "{\"topologyManagerPolicy\":\"single-numa-node\"}",
134+
}
135+
profile.SetAnnotations(paoAnnotation)
136+
By("Applying changes in performance profile and waiting until mcp will start updating")
137+
profiles.UpdateWithRetry(profile)
138+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdating, corev1.ConditionTrue)
139+
By("Waiting when mcp finishes updates")
140+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
141+
for _, node := range workerRTNodes {
142+
kubeletConfig, err := nodes.GetKubeletConfig(&node)
143+
Expect(err).ToNot(HaveOccurred())
144+
Expect(kubeletConfig.TopologyManagerPolicy).To(Equal("single-numa-node"))
145+
}
146+
})
147+
It("[test_id:45489] Verify settings are reverted to default profile", func() {
148+
By("Reverting the Profile")
149+
Expect(testclient.Client.Patch(context.TODO(), profile,
150+
client.RawPatch(
151+
types.JSONPatchType,
152+
[]byte(fmt.Sprintf(`[{ "op": "remove", "path": "/metadata/annotations/kubeletconfig.experimental"}]`)),
153+
),
154+
)).ToNot(HaveOccurred())
155+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
156+
kubeletArguments := []string{"/bin/bash", "-c", "ps -ef | grep kubelet | grep config"}
157+
for _, node := range workerRTNodes {
158+
kubeletConfig, err := nodes.GetKubeletConfig(&node)
159+
Expect(err).ToNot(HaveOccurred())
160+
Expect(kubeletConfig.AllowedUnsafeSysctls).To(Equal(nil))
161+
Expect(kubeletConfig.KubeReserved["memory"]).ToNot(Equal("768Mi"))
162+
Expect(kubeletConfig.ImageMinimumGCAge.Seconds()).ToNot(Equal(180))
163+
}
164+
for _, node := range workerRTNodes {
165+
stdout, err := nodes.ExecCommandOnNode(kubeletArguments, &node)
166+
Expect(err).ToNot(HaveOccurred())
167+
Expect(strings.Contains(stdout, "300Mi")).To(BeTrue())
168+
}
169+
170+
})
171+
172+
})
173+
})

0 commit comments

Comments
 (0)