You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by "FrankYang0529 (via GitHub)" <gi...@apache.org> on 2023/06/06 12:33:33 UTC

[GitHub] [yunikorn-k8shim] FrankYang0529 commented on a diff in pull request #608: [YUNIKORN-1471] add preemption e2e test

FrankYang0529 commented on code in PR #608:
URL: https://github.com/apache/yunikorn-k8shim/pull/608#discussion_r1219562736


##########
test/e2e/preemption/preemption_test.go:
##########
@@ -0,0 +1,337 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package preemption_test
+
+import (
+	"fmt"
+	"strings"
+	"time"
+
+	"github.com/onsi/ginkgo/v2"
+	"github.com/onsi/gomega"
+	v1 "k8s.io/api/core/v1"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+	"github.com/apache/yunikorn-k8shim/pkg/common/constants"
+	tests "github.com/apache/yunikorn-k8shim/test/e2e"
+	"github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager"
+	"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common"
+	"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s"
+	"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn"
+)
+
+var kClient k8s.KubeCtl
+var restClient yunikorn.RClient
+var ns *v1.Namespace
+var dev = "dev" + common.RandSeq(5)
+var oldConfigMap = new(v1.ConfigMap)
+var annotation = "ann-" + common.RandSeq(10)
+
+// Nodes
+var Worker = ""
+var WorkerMemRes int64
+var sleepPodMemLimit int64
+var taintKey = "e2e_test_preemption"
+var nodesToTaint []string
+
+// Queues
+var preemptionQueueYamlFormat = `
+partitions:
+  - name: default
+    queues:
+      - name: root
+        submitacl: '*'
+        queues:
+          - name: sandbox1
+            submitacl: '*'
+            properties:
+              preemption.delay: 1s
+            resources:
+              guaranteed:
+                memory: %dM
+          - name: sandbox2
+            submitacl: '*'
+            properties:
+              preemption.policy: %s
+              preemption.delay: 1s
+            resources:
+              guaranteed:
+                memory: %dM
+`
+
+var _ = ginkgo.BeforeSuite(func() {
+	// Initializing kubectl client
+	kClient = k8s.KubeCtl{}
+	Ω(kClient.SetClient()).To(gomega.BeNil())
+	// Initializing rest client
+	restClient = yunikorn.RClient{}
+	Ω(restClient).NotTo(gomega.BeNil())
+
+	annotation = "ann-" + common.RandSeq(10)
+	yunikorn.EnsureYuniKornConfigsPresent()
+	yunikorn.UpdateConfigMapWrapper(oldConfigMap, "", annotation)
+
+	ginkgo.By("Port-forward the scheduler pod")
+	var err = kClient.PortForwardYkSchedulerPod()
+	Ω(err).NotTo(gomega.HaveOccurred())
+
+	ginkgo.By("create development namespace")
+	ns, err = kClient.CreateNamespace(dev, nil)
+	gomega.Ω(err).NotTo(gomega.HaveOccurred())
+	gomega.Ω(ns.Status.Phase).To(gomega.Equal(v1.NamespaceActive))
+
+	var nodes *v1.NodeList
+	nodes, err = kClient.GetNodes()
+	Ω(err).NotTo(gomega.HaveOccurred())
+	Ω(len(nodes.Items)).NotTo(gomega.BeZero(), "Nodes cant be empty")
+
+	// Extract node allocatable resources
+	for _, node := range nodes.Items {
+		// skip master if it's marked as such
+		node := node
+		if k8s.IsMasterNode(&node) || !k8s.IsComputeNode(&node) {
+			continue
+		}
+		if Worker == "" {
+			Worker = node.Name
+		} else {
+			nodesToTaint = append(nodesToTaint, node.Name)
+		}
+	}
+	Ω(Worker).NotTo(gomega.BeEmpty(), "Worker node not found")
+
+	ginkgo.By("Tainting some nodes..")

Review Comment:
   I prefer to taint nodes because [cross-node preemption](https://yunikorn.apache.org/docs/next/design/preemption#non-goals) is in non-goals. I added `TaintNodes` and `UntaintNodes` to reduce some duplicated code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org