-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathipam_test.go
More file actions
97 lines (84 loc) · 2.37 KB
/
ipam_test.go
File metadata and controls
97 lines (84 loc) · 2.37 KB
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
package windows_test
import (
"context"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/extensions/table"
"github.com/weaveworks/eksctl/pkg/windows"
"k8s.io/client-go/kubernetes/fake"
)
type ipamEntry struct {
existingConfigMapData map[string]string
expectedConfigMapData map[string]string
}
var _ = DescribeTable("Windows IPAM", func(e ipamEntry) {
var clientset *fake.Clientset
if e.existingConfigMapData != nil {
clientset = fake.NewSimpleClientset(&v1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "amazon-vpc-cni",
Namespace: "kube-system",
},
Data: e.existingConfigMapData,
})
} else {
clientset = fake.NewSimpleClientset()
}
ipam := &windows.IPAM{
Clientset: clientset,
}
ctx := context.Background()
err := ipam.Enable(ctx)
Expect(err).NotTo(HaveOccurred())
cm, err := clientset.CoreV1().ConfigMaps("kube-system").Get(ctx, "amazon-vpc-cni", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(cm.Data).To(Equal(e.expectedConfigMapData))
},
Entry("VPC CNI ConfigMap is missing", ipamEntry{
expectedConfigMapData: map[string]string{
"enable-windows-ipam": "true",
},
}),
Entry("VPC CNI ConfigMap has data", ipamEntry{
existingConfigMapData: map[string]string{
"VPC_CNI_1": "yes",
"VPC_CNI_2": "no",
"other": "true",
},
expectedConfigMapData: map[string]string{
"VPC_CNI_1": "yes",
"VPC_CNI_2": "no",
"other": "true",
"enable-windows-ipam": "true",
},
}),
Entry("VPC CNI ConfigMap has Windows IPAM already enabled", ipamEntry{
existingConfigMapData: map[string]string{
"VPC_CNI_1": "yes",
"VPC_CNI_2": "no",
"enable-windows-ipam": "true",
},
expectedConfigMapData: map[string]string{
"VPC_CNI_1": "yes",
"VPC_CNI_2": "no",
"enable-windows-ipam": "true",
},
}),
Entry("VPC CNI ConfigMap has Windows IPAM explicitly disabled", ipamEntry{
existingConfigMapData: map[string]string{
"VPC_CNI_1": "yes",
"VPC_CNI_2": "no",
"enable-windows-ipam": "false",
},
expectedConfigMapData: map[string]string{
"VPC_CNI_1": "yes",
"VPC_CNI_2": "no",
"enable-windows-ipam": "true",
},
}),
)