Skip to content

Commit

Permalink
[YUNIKORN-2931] Create foreign pod e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pbacsko committed Oct 24, 2024
1 parent 753e4f8 commit 8de95de
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/e2e/foreign_pod/foreign_pod_suite_test.go
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions test/e2e/foreign_pod/foreign_pod_test.go
Original file line number Diff line number Diff line change
@@ -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})
})
})

0 comments on commit 8de95de

Please sign in to comment.