/
kuryr.go
62 lines (53 loc) · 2.25 KB
/
kuryr.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
package openstack
import (
"context"
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
configv1client "github.com/openshift/client-go/config/clientset/versioned"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
e2e "k8s.io/kubernetes/test/e2e/framework"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
)
var _ = g.Describe("[sig-installer][Suite:openshift/openstack][Kuryr] Kuryr", func() {
var clientSet *kubernetes.Clientset
var ctx context.Context
g.BeforeEach(func() {
ctx = context.Background()
g.By("preparing openshift dynamic client")
cfg, err := e2e.LoadConfig()
o.Expect(err).NotTo(o.HaveOccurred())
clientSet, err = e2e.LoadClientset()
o.Expect(err).NotTo(o.HaveOccurred())
c, err := configv1client.NewForConfig(cfg)
o.Expect(err).NotTo(o.HaveOccurred())
network, err := c.ConfigV1().Networks().Get(ctx, "cluster", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
if network.Status.NetworkType != "Kuryr" {
e2eskipper.Skipf("Test can only be run with Kuryr SDN")
}
})
g.It("should create a subnet for a namespace only when a pod without hostNetwork is created in the namespace", func() {
g.By("Creating a Namespace and pods")
{
ns := CreateNamespace(ctx, clientSet, "kuryr-hostnetwork", true)
defer DeleteNamespace(ctx, clientSet, ns)
g.By("Creating a Pod with hostNetwork=true")
command := []string{"/bin/sleep", "120"}
_, err := CreatePod(ctx, clientSet, ns.Name, "kuryr-hostnetwork", true, command)
o.Expect(err).NotTo(o.HaveOccurred())
subnetID, err := GetSubnetIDfromKuryrNetwork(ctx, clientSet, ns.Name)
if !apierrors.IsNotFound(err) {
e2e.Failf("Error has occured %v", err)
}
o.Expect(subnetID).To(o.BeEmpty(), "A subnet should not be created when a pod with Hostnetwork is created")
g.By("Creating a Pod with hostNetwork=false")
_, err = CreatePod(ctx, clientSet, ns.Name, "kuryr-nohostnetwork", false, command)
o.Expect(err).NotTo(o.HaveOccurred())
subnetID, err = GetSubnetIDfromKuryrNetwork(ctx, clientSet, ns.Name)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(subnetID).ToNot(o.BeEmpty(), "A subnet should be created when a non host network pod is created")
}
})
})