...
1
16
17 package workloads
18
19 import (
20 "fmt"
21 "strings"
22 "time"
23
24 v1 "k8s.io/api/core/v1"
25 "k8s.io/apimachinery/pkg/api/resource"
26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27 kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
28 "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
29 imageutils "k8s.io/kubernetes/test/utils/image"
30 )
31
32
33
34 type npbEPWorkload struct{}
35
36
37 var _ NodePerfWorkload = &npbEPWorkload{}
38
39 func (w npbEPWorkload) Name() string {
40 return "npb-ep"
41 }
42
43 func (w npbEPWorkload) PodSpec() v1.PodSpec {
44 var containers []v1.Container
45 ctn := v1.Container{
46 Name: fmt.Sprintf("%s-ctn", w.Name()),
47 Image: imageutils.GetE2EImage(imageutils.NodePerfNpbEp),
48 Resources: v1.ResourceRequirements{
49 Requests: v1.ResourceList{
50 v1.ResourceName(v1.ResourceCPU): resource.MustParse("15000m"),
51 v1.ResourceName(v1.ResourceMemory): resource.MustParse("48Gi"),
52 },
53 Limits: v1.ResourceList{
54 v1.ResourceName(v1.ResourceCPU): resource.MustParse("15000m"),
55 v1.ResourceName(v1.ResourceMemory): resource.MustParse("48Gi"),
56 },
57 },
58 Command: []string{"/bin/sh"},
59 Args: []string{"-c", "/ep.D.x"},
60 }
61 containers = append(containers, ctn)
62
63 return v1.PodSpec{
64 RestartPolicy: v1.RestartPolicyNever,
65 Containers: containers,
66 }
67 }
68
69 func (w npbEPWorkload) Timeout() time.Duration {
70 return 10 * time.Minute
71 }
72
73 func (w npbEPWorkload) KubeletConfig(oldCfg *kubeletconfig.KubeletConfiguration) (newCfg *kubeletconfig.KubeletConfiguration, err error) {
74
75 newCfg = oldCfg.DeepCopy()
76
77 newCfg.CPUManagerPolicy = string(cpumanager.PolicyStatic)
78
79 newCfg.CPUManagerReconcilePeriod = metav1.Duration{Duration: 10 * time.Second}
80
81
82
83
84 if newCfg.KubeReserved == nil {
85 newCfg.KubeReserved = map[string]string{}
86 }
87
88 if _, ok := newCfg.KubeReserved["cpu"]; !ok {
89 newCfg.KubeReserved["cpu"] = "200m"
90 }
91
92 return newCfg, nil
93 }
94
95 func (w npbEPWorkload) PreTestExec() error {
96 cmd := "/bin/sh"
97 args := []string{"-c", "rm -f /var/lib/kubelet/cpu_manager_state"}
98 err := runCmd(cmd, args)
99
100 return err
101 }
102
103 func (w npbEPWorkload) PostTestExec() error {
104 cmd := "/bin/sh"
105 args := []string{"-c", "rm -f /var/lib/kubelet/cpu_manager_state"}
106 err := runCmd(cmd, args)
107
108 return err
109 }
110
111 func (w npbEPWorkload) ExtractPerformanceFromLogs(logs string) (perf time.Duration, err error) {
112 perfLine, err := getMatchingLineFromLog(logs, "Time in seconds =")
113 if err != nil {
114 return perf, err
115 }
116 perfStrings := strings.Split(perfLine, "=")
117 perfString := fmt.Sprintf("%ss", strings.TrimSpace(perfStrings[1]))
118 perf, err = time.ParseDuration(perfString)
119
120 return perf, err
121 }
122
View as plain text