-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathdeviceplugins_suite_test.go
141 lines (117 loc) · 5.06 KB
/
deviceplugins_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2020-2022 Intel Corporation. All Rights Reserved.
//
// Licensed 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 e2e_test
import (
"context"
"flag"
"os"
"testing"
"time"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/dlb"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/dsa"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/fpga"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/fpgaadmissionwebhook"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/gpu"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/iaa"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/operator"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/qat"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/sgx"
_ "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/sgxadmissionwebhook"
"github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/utils"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/component-base/logs"
"k8s.io/component-base/version"
"k8s.io/klog/v2"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/config"
e2edebug "k8s.io/kubernetes/test/e2e/framework/debug"
e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
)
func init() {
ginkgo.SynchronizedBeforeSuite(setupFirstNode, func(data []byte) {})
}
func setupFirstNode(ctx context.Context) []byte {
c, err := framework.LoadClientset()
if err != nil {
framework.Failf("Error loading client: %v", err)
}
// Delete any namespaces except those created by the system. This ensures no
// lingering resources are left over from a previous test run.
if framework.TestContext.CleanStart {
deleted, err2 := framework.DeleteNamespaces(ctx, c, nil, /* deleteFilter */
[]string{
metav1.NamespaceSystem,
metav1.NamespaceDefault,
metav1.NamespacePublic,
v1.NamespaceNodeLease,
"cert-manager",
})
if err2 != nil {
framework.Failf("Error deleting orphaned namespaces: %v", err2)
}
framework.Logf("Waiting for deletion of the following namespaces: %v", deleted)
if err2 = framework.WaitForNamespacesDeleted(ctx, c, deleted, e2epod.DefaultPodDeletionTimeout); err2 != nil {
framework.Failf("Failed to delete orphaned namespaces %v: %v", deleted, err2)
}
}
timeouts := framework.NewTimeoutContext()
framework.ExpectNoError(e2enode.WaitForAllNodesSchedulable(ctx, c, timeouts.NodeSchedulable))
// Ensure all pods are running and ready before starting tests (otherwise,
// cluster infrastructure pods that are being pulled or started can block
// test pods from running, and tests that ensure all pods are running and
// ready will fail).
if err = e2epod.WaitForPodsRunningReady(ctx, c, metav1.NamespaceSystem, framework.TestContext.MinStartupPods,
timeouts.SystemPodsStartup); err != nil {
e2edebug.DumpAllNamespaceInfo(ctx, c, metav1.NamespaceSystem)
e2ekubectl.LogFailedContainers(ctx, c, metav1.NamespaceSystem, framework.Logf)
framework.Failf("Error waiting for all pods to be running and ready: %v", err)
}
// Log the version of the server and this client.
framework.Logf("e2e test version: %s", version.Get().GitVersion)
serverVersion, err := c.DiscoveryClient.ServerVersion()
if err != nil {
framework.Logf("Unexpected server error retrieving version: %v", err)
}
if serverVersion != nil {
framework.Logf("kube-apiserver version: %s", serverVersion.GitVersion)
}
utils.Kubectl("node-feature-discovery", "apply", "-k", "deployments/nfd/kustomization.yaml")
utils.Kubectl("node-feature-discovery", "apply", "-k", "deployments/nfd/overlays/node-feature-rules/kustomization.yaml")
if err = e2epod.WaitForPodsRunningReady(ctx, c, "node-feature-discovery", 2,
300*time.Second); err != nil {
framework.Failf("unable to wait for NFD pods to be running and ready: %v", err)
}
return []byte{}
}
func TestDevicePlugins(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "E2E Device Plugins Suite")
}
func TestMain(m *testing.M) {
klog.SetOutput(ginkgo.GinkgoWriter)
logs.InitLogs()
config.CopyFlags(config.Flags, flag.CommandLine)
framework.RegisterCommonFlags(flag.CommandLine)
framework.RegisterClusterFlags(flag.CommandLine)
flag.Parse()
// Register framework flags, then handle flags.
framework.AfterReadingAllFlags(&framework.TestContext)
// Now run the test suite.
os.Exit(m.Run())
}