5
5
6
6
"github.com/golang/glog"
7
7
kapi "k8s.io/kubernetes/pkg/api"
8
+ "k8s.io/kubernetes/pkg/types"
8
9
"k8s.io/kubernetes/pkg/util/sets"
9
10
"k8s.io/kubernetes/pkg/watch"
10
11
@@ -17,6 +18,10 @@ type F5Plugin struct {
17
18
// F5Client is the object that represents the F5 BIG-IP host, holds state,
18
19
// and provides an interface to manipulate F5 BIG-IP.
19
20
F5Client * f5LTM
21
+
22
+ // VtepMap is a map of node ids and their ip addresses
23
+ // helps to sync events at router start vs node status update events
24
+ VtepMap map [types.UID ]string
20
25
}
21
26
22
27
// F5PluginConfig holds configuration for the f5 plugin.
@@ -84,7 +89,7 @@ func NewF5Plugin(cfg F5PluginConfig) (*F5Plugin, error) {
84
89
if err != nil {
85
90
return nil , err
86
91
}
87
- return & F5Plugin {f5 }, f5 .Initialize ()
92
+ return & F5Plugin {f5 , map [types. UID ] string {} }, f5 .Initialize ()
88
93
}
89
94
90
95
// ensurePoolExists checks whether the named pool already exists in F5 BIG-IP
@@ -496,19 +501,27 @@ func (p *F5Plugin) HandleNode(eventType watch.EventType, node *kapi.Node) error
496
501
// The F5 appliance, if hooked to use the VxLAN encapsulation
497
502
// should have its FDB updated depending on nodes arriving and leaving the cluster
498
503
switch eventType {
499
- case watch .Added :
504
+ case watch .Added , watch . Modified :
500
505
// New VTEP created, add the record to the vxlan fdb
501
506
ip , err := getNodeIP (node )
502
507
if err != nil {
503
508
// just log the error
504
509
glog .Warningf ("Error in obtaining IP address of newly added node %s - %v" , node .Name , err )
505
510
return nil
506
511
}
512
+
513
+ // check and find if the node has already been processed
514
+ // if yes, then break, or just add the new vtep
515
+ uid := node .ObjectMeta .UID
516
+ if oldNodeIP , ok := p .VtepMap [uid ]; ok && (oldNodeIP == ip ) {
517
+ break
518
+ }
507
519
err = p .F5Client .AddVtep (ip )
508
520
if err != nil {
509
521
glog .Errorf ("Error in adding node '%s' to F5s FDB - %v" , ip , err )
510
522
return err
511
523
}
524
+ p .VtepMap [uid ] = ip
512
525
case watch .Deleted :
513
526
// VTEP deleted, delete the record from vxlan fdb
514
527
ip , err := getNodeIP (node )
@@ -522,8 +535,8 @@ func (p *F5Plugin) HandleNode(eventType watch.EventType, node *kapi.Node) error
522
535
glog .Errorf ("Error in removing node '%s' from F5s FDB - %v" , ip , err )
523
536
return err
524
537
}
525
- case watch . Modified :
526
- // ignore the modified event. Change in IP address of the node is not supported.
538
+ uid := node . ObjectMeta . UID
539
+ delete ( p . VtepMap , uid )
527
540
}
528
541
return nil
529
542
}
0 commit comments