19
19
package preemption_test
20
20
21
21
import (
22
+ "fmt"
22
23
"path/filepath"
24
+ "runtime"
25
+ "strings"
23
26
"testing"
24
27
25
28
"github.com/onsi/ginkgo/v2"
26
29
"github.com/onsi/ginkgo/v2/reporters"
27
30
"github.com/onsi/gomega"
31
+ v1 "k8s.io/api/core/v1"
28
32
33
+ "github.com/apache/yunikorn-k8shim/pkg/common/constants"
29
34
"github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager"
35
+ "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common"
36
+ "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s"
37
+ "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn"
30
38
)
31
39
32
40
func init () {
@@ -48,3 +56,76 @@ func TestPreemption(t *testing.T) {
48
56
49
57
var Ω = gomega .Ω
50
58
var HaveOccurred = gomega .HaveOccurred
59
+
60
+ var _ = ginkgo .BeforeSuite (func () {
61
+ _ , filename , _ , _ := runtime .Caller (0 )
62
+ suiteName = common .GetSuiteName (filename )
63
+ // Initializing kubectl client
64
+ kClient = k8s.KubeCtl {}
65
+ Ω (kClient .SetClient ()).To (gomega .BeNil ())
66
+ // Initializing rest client
67
+ restClient = yunikorn.RClient {}
68
+ Ω (restClient ).NotTo (gomega .BeNil ())
69
+
70
+ yunikorn .EnsureYuniKornConfigsPresent ()
71
+
72
+ ginkgo .By ("Port-forward the scheduler pod" )
73
+ var err = kClient .PortForwardYkSchedulerPod ()
74
+ Ω (err ).NotTo (gomega .HaveOccurred ())
75
+
76
+ var nodes * v1.NodeList
77
+ nodes , err = kClient .GetNodes ()
78
+ Ω (err ).NotTo (gomega .HaveOccurred ())
79
+ Ω (len (nodes .Items )).NotTo (gomega .BeZero (), "Nodes cant be empty" )
80
+
81
+ // Extract node allocatable resources
82
+ for _ , node := range nodes .Items {
83
+ // skip master if it's marked as such
84
+ node := node
85
+ if k8s .IsMasterNode (& node ) || ! k8s .IsComputeNode (& node ) {
86
+ continue
87
+ }
88
+ if Worker == "" {
89
+ Worker = node .Name
90
+ } else {
91
+ nodesToTaint = append (nodesToTaint , node .Name )
92
+ }
93
+ }
94
+ Ω (Worker ).NotTo (gomega .BeEmpty (), "Worker node not found" )
95
+
96
+ ginkgo .By ("Tainting some nodes.." )
97
+ err = kClient .TaintNodes (nodesToTaint , taintKey , "value" , v1 .TaintEffectNoSchedule )
98
+ Ω (err ).NotTo (gomega .HaveOccurred ())
99
+
100
+ nodesDAOInfo , err := restClient .GetNodes (constants .DefaultPartition )
101
+ Ω (err ).NotTo (gomega .HaveOccurred ())
102
+ Ω (nodesDAOInfo ).NotTo (gomega .BeNil ())
103
+
104
+ for _ , node := range * nodesDAOInfo {
105
+ if node .NodeID == Worker {
106
+ WorkerMemRes = node .Available ["memory" ]
107
+ }
108
+ }
109
+ WorkerMemRes /= (1000 * 1000 ) // change to M
110
+ fmt .Fprintf (ginkgo .GinkgoWriter , "Worker node %s available memory %dM\n " , Worker , WorkerMemRes )
111
+
112
+ sleepPodMemLimit = int64 (float64 (WorkerMemRes ) / 3 )
113
+ Ω (sleepPodMemLimit ).NotTo (gomega .BeZero (), "Sleep pod memory limit cannot be zero" )
114
+ fmt .Fprintf (ginkgo .GinkgoWriter , "Sleep pod limit memory %dM\n " , sleepPodMemLimit )
115
+
116
+ sleepPodMemLimit2 = int64 (float64 (WorkerMemRes ) / 4 )
117
+ Ω (sleepPodMemLimit2 ).NotTo (gomega .BeZero (), "Sleep pod memory limit cannot be zero" )
118
+ fmt .Fprintf (ginkgo .GinkgoWriter , "Sleep pod limit memory %dM\n " , sleepPodMemLimit2 )
119
+ })
120
+
121
+ var _ = ginkgo .AfterSuite (func () {
122
+
123
+ ginkgo .By ("Untainting some nodes" )
124
+ err := kClient .UntaintNodes (nodesToTaint , taintKey )
125
+ Ω (err ).NotTo (gomega .HaveOccurred (), "Could not remove taint from nodes " + strings .Join (nodesToTaint , "," ))
126
+
127
+ ginkgo .By ("Check Yunikorn's health" )
128
+ checks , err := yunikorn .GetFailedHealthChecks ()
129
+ Ω (err ).NotTo (gomega .HaveOccurred ())
130
+ Ω (checks ).To (gomega .Equal ("" ), checks )
131
+ })
0 commit comments