Skip to content

Commit 6aba0c5

Browse files
author
Niranjan M.R
committed
E2E Test cases for enabling unsafe sysctl in performance profile
Signed-off-by: Niranjan M.R <[email protected]> Minor fixes based on review comments Signed-off-by: Niranjan M.R <[email protected]>
1 parent 20493dd commit 6aba0c5

File tree

1 file changed

+177
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)