@@ -39,9 +39,19 @@ type cniPodNetwork struct {
39
39
kc.NetworkConfig
40
40
}
41
41
42
+ func (c * cniPodNetwork ) ToProperty () cniPodNetworkProperty {
43
+ return cniPodNetworkProperty {
44
+ IfMAC : c .IfMAC ,
45
+ IsPrimary : c .IsPrimary ,
46
+ PodagentSkip : c .PodagentSkip ,
47
+ }
48
+ }
49
+
42
50
type cniPodNetworkProperty struct {
43
51
IfMAC string
44
52
IsPrimary bool
53
+ // PodagentSkip makes podagent skip configuring this network
54
+ PodagentSkip bool
45
55
}
46
56
47
57
type cniPodNetworks []cniPodNetwork
@@ -97,10 +107,8 @@ func getNetworkSet(networks string) (gset.GSet, error) {
97
107
netSetBuilder := gset .NewBuilder ()
98
108
err := json .Unmarshal ([]byte (networks ), & nets )
99
109
if err == nil {
100
- np := cniPodNetworkProperty {}
101
110
for _ , n := range nets {
102
- np .IfMAC = n .IfMAC
103
- np .IsPrimary = n .IsPrimary
111
+ np := n .ToProperty ()
104
112
netSetBuilder .Add (n .NetworkName , np )
105
113
}
106
114
}
@@ -158,6 +166,11 @@ func (c *Controller) addNetwork(podObj *apiv1.Pod, networkName string, np cniPod
158
166
if np .IsPrimary {
159
167
return nil
160
168
}
169
+ if np .PodagentSkip {
170
+ glog .V (3 ).Infof ("Skipping adding pod's %s network %s" , podObj .GetName (), networkName )
171
+ return nil
172
+ }
173
+
161
174
cniParams , err := c .getCNIParams (podObj , networkName , np )
162
175
if err != nil {
163
176
return err
@@ -172,6 +185,11 @@ func (c *Controller) delNetwork(podObj *apiv1.Pod, networkName string, np cniPod
172
185
if np .IsPrimary {
173
186
return nil
174
187
}
188
+ if np .PodagentSkip {
189
+ glog .V (3 ).Infof ("Skipping deleting pod's %s network %s" , podObj .GetName (), networkName )
190
+ return nil
191
+ }
192
+
175
193
cniParams , err := c .getCNIParams (podObj , networkName , np )
176
194
if err != nil {
177
195
return err
@@ -236,10 +254,8 @@ func (c *Controller) podUpdated(oldObj, newObj interface{}) {
236
254
glog .V (4 ).Infof ("Failed to unmarshall pod's %s old networks annotation, ignore: %s" , podName , err )
237
255
return
238
256
}
239
- np := cniPodNetworkProperty {}
240
257
for _ , n := range nets {
241
- np .IfMAC = n .IfMAC
242
- np .IsPrimary = n .IsPrimary
258
+ np := n .ToProperty ()
243
259
err := c .delNetwork (newPod , n .NetworkName , np )
244
260
if err != nil {
245
261
glog .Errorf ("Failed to delete network %s on pod %s" , n .NetworkName , podName )
@@ -260,10 +276,8 @@ func (c *Controller) addNetworks(pod *apiv1.Pod, networkAnnotation string) {
260
276
return
261
277
}
262
278
263
- np := cniPodNetworkProperty {}
264
279
for _ , n := range nets {
265
- np .IfMAC = n .IfMAC
266
- np .IsPrimary = n .IsPrimary
280
+ np := n .ToProperty ()
267
281
err := c .addNetwork (pod , n .NetworkName , np )
268
282
if err != nil {
269
283
glog .Errorf ("Failed to add network %s on pod %s" , n .NetworkName , podName )
0 commit comments