This is an automated email from the ASF dual-hosted git repository.

ccondit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git


The following commit(s) were added to refs/heads/master by this push:
     new be76576d [YUNIKORN-2931] Create foreign pod e2e tests (#932)
be76576d is described below

commit be76576d3e63925525ba0ba49aebf9678ecffda4
Author: Peter Bacsko <[email protected]>
AuthorDate: Fri Oct 25 15:42:24 2024 -0500

    [YUNIKORN-2931] Create foreign pod e2e tests (#932)
    
    Closes: #932
    
    Signed-off-by: Craig Condit <[email protected]>
---
 test/e2e/foreign_pod/foreign_pod_suite_test.go | 89 ++++++++++++++++++++++++++
 test/e2e/foreign_pod/foreign_pod_test.go       | 78 ++++++++++++++++++++++
 2 files changed, 167 insertions(+)

diff --git a/test/e2e/foreign_pod/foreign_pod_suite_test.go 
b/test/e2e/foreign_pod/foreign_pod_suite_test.go
new file mode 100644
index 00000000..e5a87cae
--- /dev/null
+++ b/test/e2e/foreign_pod/foreign_pod_suite_test.go
@@ -0,0 +1,89 @@
+/*
+ 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 foreign_pod
+
+import (
+       "path/filepath"
+       "runtime"
+       "testing"
+
+       "github.com/onsi/ginkgo/v2"
+       "github.com/onsi/ginkgo/v2/reporters"
+       "github.com/onsi/gomega"
+       v1 "k8s.io/api/core/v1"
+
+       "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"
+)
+
+func init() {
+       configmanager.YuniKornTestConfig.ParseFlags()
+}
+
+func TestForeignPodHandling(t *testing.T) {
+       ginkgo.ReportAfterSuite("TestForeignPodHandling", func(report 
ginkgo.Report) {
+               err := common.CreateJUnitReportDir()
+               Ω(err).NotTo(gomega.HaveOccurred())
+               err = reporters.GenerateJUnitReportWithConfig(
+                       report,
+                       filepath.Join(configmanager.YuniKornTestConfig.LogDir, 
"TEST-foreign_pod_junit.xml"),
+                       reporters.JunitReportConfig{OmitSpecLabels: true},
+               )
+               Ω(err).NotTo(HaveOccurred())
+       })
+       gomega.RegisterFailHandler(ginkgo.Fail)
+       ginkgo.RunSpecs(t, "TestForeignPodHandling", 
ginkgo.Label("TestForeignPodHandling"))
+}
+
+var suiteName string
+var oldConfigMap = new(v1.ConfigMap)
+var kClient = k8s.KubeCtl{} //nolint
+
+var _ = BeforeSuite(func() {
+       _, filename, _, _ := runtime.Caller(0)
+       suiteName = common.GetSuiteName(filename)
+       yunikorn.EnsureYuniKornConfigsPresent()
+       yunikorn.UpdateConfigMapWrapper(oldConfigMap, "fifo")
+})
+
+var _ = AfterSuite(func() {
+       yunikorn.RestoreConfigMapWrapper(oldConfigMap)
+})
+
+// Declarations for Ginkgo DSL
+var Describe = ginkgo.Describe
+
+var It = ginkgo.It
+var PIt = ginkgo.PIt
+var By = ginkgo.By
+var BeforeSuite = ginkgo.BeforeSuite
+var AfterSuite = ginkgo.AfterSuite
+var BeforeEach = ginkgo.BeforeEach
+var AfterEach = ginkgo.AfterEach
+var DescribeTable = ginkgo.Describe
+var Entry = ginkgo.Entry
+
+// Declarations for Gomega Matchers
+var Equal = gomega.Equal
+var BeNumerically = gomega.BeNumerically
+var Ω = gomega.Expect
+var BeNil = gomega.BeNil
+var HaveOccurred = gomega.HaveOccurred
diff --git a/test/e2e/foreign_pod/foreign_pod_test.go 
b/test/e2e/foreign_pod/foreign_pod_test.go
new file mode 100644
index 00000000..932afbfd
--- /dev/null
+++ b/test/e2e/foreign_pod/foreign_pod_test.go
@@ -0,0 +1,78 @@
+/*
+ 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 foreign_pod
+
+import (
+       "fmt"
+
+       "github.com/onsi/ginkgo/v2"
+       "github.com/onsi/gomega"
+
+       tests "github.com/apache/yunikorn-k8shim/test/e2e"
+       "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s"
+       "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn"
+)
+
+const kubeSystem = "kube-system"
+
+var _ = Describe("", func() {
+       It("Verify foreign pod tracking", func() {
+               By("Retrieving foreign pods from kube-system")
+               kClient = k8s.KubeCtl{}
+               Ω(kClient.SetClient()).To(BeNil())
+               podList, err := kClient.GetPods(kubeSystem)
+               Ω(err).NotTo(gomega.HaveOccurred())
+
+               kubeUIDs := make(map[string]bool)
+               kubeNodes := make(map[string]string)
+               for _, pod := range podList.Items {
+                       kubeUIDs[string(pod.UID)] = true
+                       kubeNodes[string(pod.UID)] = pod.Spec.NodeName
+                       fmt.Fprintf(ginkgo.GinkgoWriter, "pod: %s, uid: %s, 
node: %s\n", pod.Name, pod.UID, pod.Spec.NodeName)
+               }
+
+               // retrieve foreign pod info
+               By("Retrieving foreign allocations")
+               var restClient yunikorn.RClient
+               nodes, err := restClient.GetNodes("default")
+               Ω(err).NotTo(gomega.HaveOccurred())
+               foreignAllocs := make(map[string]bool)
+               foreignNodes := make(map[string]string)
+               for _, n := range *nodes {
+                       fmt.Fprintf(ginkgo.GinkgoWriter, "Checking node %s\n", 
n.NodeID)
+                       if len(n.ForeignAllocations) > 0 {
+                               for _, falloc := range n.ForeignAllocations {
+                                       fmt.Fprintf(ginkgo.GinkgoWriter, "Found 
allocation %s on node %s\n", falloc.AllocationKey, falloc.NodeID)
+                                       foreignAllocs[falloc.AllocationKey] = 
true
+                                       foreignNodes[falloc.AllocationKey] = 
falloc.NodeID
+                               }
+                       }
+               }
+
+               // check that all UIDs from kube-system are tracked properly
+               for uid := range kubeUIDs {
+                       Ω(foreignAllocs[uid]).To(Equal(true), "pod %s from 
kube-system is not tracked in Yunikorn", uid)
+                       Ω(foreignNodes[uid]).To(Equal(kubeNodes[uid]), "pod %s 
is tracked under incorrect node", uid)
+               }
+       })
+
+       ginkgo.AfterEach(func() {
+               tests.DumpClusterInfoIfSpecFailed(suiteName, 
[]string{kubeSystem})
+       })
+})


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to