@@ -42,6 +42,7 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetwork *net.IPNet, hostSubne
42
42
}
43
43
44
44
go utilwait .Forever (master .watchNodes , 0 )
45
+ go utilwait .Forever (master .watchSubnets , 0 )
45
46
return nil
46
47
}
47
48
@@ -240,6 +241,47 @@ func (node *OsdnNode) initSelfSubnet() error {
240
241
return nil
241
242
}
242
243
244
+ // Only run on the master
245
+ // Watch for all hostsubnet events and if one is found with the right annotation, use the IPAM to dole a real subnet
246
+ func (master * OsdnMaster ) watchSubnets () {
247
+ eventQueue := master .registry .RunEventQueue (HostSubnets )
248
+
249
+ for {
250
+ eventType , obj , err := eventQueue .Pop ()
251
+ if err != nil {
252
+ utilruntime .HandleError (fmt .Errorf ("EventQueue failed for subnets: %v" , err ))
253
+ return
254
+ }
255
+ hs := obj .(* osapi.HostSubnet )
256
+ name := hs .ObjectMeta .Name
257
+ hostIP := hs .HostIP
258
+
259
+ log .V (5 ).Infof ("Watch %s event for HostSubnet %q" , strings .Title (string (eventType )), name )
260
+ switch eventType {
261
+ case watch .Added , watch .Modified :
262
+ if _ , ok := hs .Annotations [AssignHostSubnetAnnotation ]; ok {
263
+ // Delete the annotated hostsubnet and create a new one with an assigned subnet
264
+ // We do not update (instead of delete+create) because the watchSubnets on the nodes
265
+ // will skip the event if it finds that the hostsubnet has the same host
266
+ // And we cannot fix the watchSubnets code for node because it will break migration if
267
+ // nodes are upgraded after the master
268
+ err = master .registry .DeleteSubnet (name )
269
+ if err != nil {
270
+ log .Errorf ("Error in deleting annotated subnet from master, name: %s, ip %s: %v" , name , hostIP , err )
271
+ continue
272
+ }
273
+ err = master .addNode (name , hostIP )
274
+ if err != nil {
275
+ log .Errorf ("Error creating subnet for node %s, ip %s: %v" , name , hostIP , err )
276
+ continue
277
+ }
278
+ }
279
+ case watch .Deleted :
280
+ // ignore all deleted hostsubnets
281
+ }
282
+ }
283
+ }
284
+
243
285
// Only run on the nodes
244
286
func (node * OsdnNode ) watchSubnets () {
245
287
subnets := make (map [string ]* osapi.HostSubnet )
0 commit comments