1
- package annotations
1
+ package annotations_test
2
2
3
3
import (
4
4
"encoding/json"
@@ -12,10 +12,16 @@ import (
12
12
corev1 "k8s.io/api/core/v1"
13
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
14
15
+ "github.com/k8snetworkplumbingwg/multus-dynamic-networks-controller/pkg/annotations"
15
16
nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
16
17
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/server/api"
17
18
)
18
19
20
+ type attachmentInfo struct {
21
+ ifaceName string
22
+ networkName string
23
+ }
24
+
19
25
var _ = Describe ("NetworkStatusFromResponse" , func () {
20
26
const (
21
27
ifaceName = "ens32"
@@ -28,9 +34,9 @@ var _ = Describe("NetworkStatusFromResponse", func() {
28
34
29
35
DescribeTable ("add dynamic interface to network status" , func (initialNetStatus []nadv1.NetworkStatus , resultIPs []string , expectedNetworkStatus []nadv1.NetworkStatus ) {
30
36
Expect (
31
- AddDynamicIfaceToStatus (
37
+ annotations . AddDynamicIfaceToStatus (
32
38
newPod (podName , namespace , initialNetStatus ... ),
33
- * NewAttachmentResult (
39
+ * annotations . NewAttachmentResult (
34
40
newNetworkSelectionElementWithIface (networkName , ifaceName , namespace ),
35
41
newResponse (ifaceToAdd , macAddr , resultIPs ... ),
36
42
),
@@ -39,7 +45,7 @@ var _ = Describe("NetworkStatusFromResponse", func() {
39
45
},
40
46
Entry ("initial empty pod" , []nadv1.NetworkStatus {}, nil , []nadv1.NetworkStatus {
41
47
{
42
- Name : NamespacedName (namespace , networkName ),
48
+ Name : annotations . NamespacedName (namespace , networkName ),
43
49
Interface : ifaceToAdd ,
44
50
Mac : macAddr ,
45
51
DNS : nadv1.DNS {
@@ -63,7 +69,7 @@ var _ = Describe("NetworkStatusFromResponse", func() {
63
69
Mac : "00:00:00:20:10:00" ,
64
70
},
65
71
{
66
- Name : NamespacedName (namespace , networkName ),
72
+ Name : annotations . NamespacedName (namespace , networkName ),
67
73
Interface : ifaceToAdd ,
68
74
Mac : macAddr ,
69
75
DNS : nadv1.DNS {
@@ -88,7 +94,7 @@ var _ = Describe("NetworkStatusFromResponse", func() {
88
94
Mac : "00:00:00:20:10:00" ,
89
95
},
90
96
{
91
- Name : NamespacedName (namespace , networkName ),
97
+ Name : annotations . NamespacedName (namespace , networkName ),
92
98
Interface : ifaceToAdd ,
93
99
Mac : macAddr ,
94
100
IPs : []string {"10.10.10.10" },
@@ -101,59 +107,112 @@ var _ = Describe("NetworkStatusFromResponse", func() {
101
107
}},
102
108
))
103
109
104
- DescribeTable ("remove an interface to the current network status" , func (initialNetStatus []nadv1.NetworkStatus , networkName string , ifaceToRemove string , expectedNetworkStatus []nadv1.NetworkStatus ) {
110
+ DescribeTable ("remove an interface to the current network status" , func (initialNetStatus []nadv1.NetworkStatus , expectedNetworkStatus []nadv1.NetworkStatus , ifacesToRemove ... attachmentInfo ) {
111
+ var netsToRemove []nadv1.NetworkSelectionElement
112
+ for _ , ifaceToRemove := range ifacesToRemove {
113
+ netsToRemove = append (
114
+ netsToRemove ,
115
+ * newNetworkSelectionElementWithIface (ifaceToRemove .networkName , ifaceToRemove .ifaceName , namespace ),
116
+ )
117
+ }
105
118
Expect (
106
- DeleteDynamicIfaceFromStatus (
107
- newPod (podName , namespace , initialNetStatus ... ),
108
- newNetworkSelectionElementWithIface (networkName , ifaceToRemove , namespace ),
109
- ),
119
+ annotations .DeleteDynamicIfaceFromStatus (newPod (podName , namespace , initialNetStatus ... ), netsToRemove ... ),
110
120
).To (Equal (expectedNetworkStatus ))
111
121
},
112
- Entry ("when there aren't any existing interfaces" , nil , "net1" , "iface1" , []nadv1.NetworkStatus {}),
113
- Entry ("when we remove all the currently existing interfaces" , []nadv1.NetworkStatus {
114
- {
115
- Name : NamespacedName (namespace , networkName ),
116
- Interface : "iface1" ,
117
- Mac : "00:00:00:20:10:00" ,
118
- }}, networkName , "iface1" , []nadv1.NetworkStatus {}),
122
+ Entry ("when there aren't any existing interfaces" , nil , []nadv1.NetworkStatus {}, attachmentInfo {
123
+ ifaceName : "iface1" ,
124
+ networkName : "net1" ,
125
+ }),
126
+ Entry (
127
+ "when we remove all the currently existing interfaces" ,
128
+ []nadv1.NetworkStatus {
129
+ {
130
+ Name : annotations .NamespacedName (namespace , networkName ),
131
+ Interface : "iface1" ,
132
+ Mac : "00:00:00:20:10:00" ,
133
+ }},
134
+ []nadv1.NetworkStatus {},
135
+ attachmentInfo {
136
+ ifaceName : "iface1" ,
137
+ networkName : networkName ,
138
+ },
139
+ ),
119
140
Entry ("when there is *not* a matching interface to remove" , []nadv1.NetworkStatus {
120
141
{
121
- Name : NamespacedName (namespace , networkName ),
142
+ Name : annotations . NamespacedName (namespace , networkName ),
122
143
Interface : "iface1" ,
123
144
Mac : "00:00:00:20:10:00" ,
124
145
}},
125
- "net2" ,
126
- "iface1" ,
127
146
[]nadv1.NetworkStatus {
128
147
{
129
- Name : NamespacedName (namespace , networkName ),
148
+ Name : annotations . NamespacedName (namespace , networkName ),
130
149
Interface : "iface1" ,
131
150
Mac : "00:00:00:20:10:00" ,
132
151
},
133
152
},
153
+ attachmentInfo {
154
+ ifaceName : "iface1" ,
155
+ networkName : "net2" ,
156
+ },
134
157
),
135
158
Entry ("when we remove one of the existing interfaces" , []nadv1.NetworkStatus {
136
159
{
137
- Name : NamespacedName (namespace , networkName ),
160
+ Name : annotations . NamespacedName (namespace , networkName ),
138
161
Interface : "iface1" ,
139
162
Mac : "00:00:00:20:10:00" ,
140
163
},
141
164
{
142
- Name : NamespacedName (namespace , "net2" ),
165
+ Name : annotations . NamespacedName (namespace , "net2" ),
143
166
Interface : "iface2" ,
144
167
Mac : "aa:bb:cc:20:10:00" ,
145
168
},
146
169
},
147
- "net2" ,
148
- "iface2" ,
149
170
[]nadv1.NetworkStatus {
150
171
{
151
- Name : NamespacedName (namespace , networkName ),
172
+ Name : annotations . NamespacedName (namespace , networkName ),
152
173
Interface : "iface1" ,
153
174
Mac : "00:00:00:20:10:00" ,
154
175
},
155
176
},
156
- ))
177
+ attachmentInfo {
178
+ ifaceName : "iface2" ,
179
+ networkName : "net2" ,
180
+ },
181
+ ),
182
+ Entry (
183
+ "when we remove multiple interfaces at once" ,
184
+ []nadv1.NetworkStatus {
185
+ {
186
+ Name : annotations .NamespacedName (namespace , networkName ),
187
+ Interface : "iface1" ,
188
+ Mac : "00:00:00:20:10:00" ,
189
+ },
190
+ {
191
+ Name : annotations .NamespacedName (namespace , "net2" ),
192
+ Interface : "iface2" ,
193
+ Mac : "aa:bb:cc:20:10:00" ,
194
+ },
195
+ {
196
+ Name : annotations .NamespacedName (namespace , "net3" ),
197
+ Interface : "iface3" ,
198
+ Mac : "aa:bb:cc:11:11:11" ,
199
+ },
200
+ },
201
+ []nadv1.NetworkStatus {
202
+ {
203
+ Name : annotations .NamespacedName (namespace , "net3" ),
204
+ Interface : "iface3" ,
205
+ Mac : "aa:bb:cc:11:11:11" ,
206
+ },
207
+ },
208
+ attachmentInfo {
209
+ ifaceName : "iface1" ,
210
+ networkName : networkName ,
211
+ },
212
+ attachmentInfo {
213
+ ifaceName : "iface2" ,
214
+ networkName : "net2" ,
215
+ }))
157
216
})
158
217
159
218
func newPod (podName string , namespace string , netStatus ... nadv1.NetworkStatus ) * corev1.Pod {
0 commit comments