7
7
"github.com/golang/glog"
8
8
9
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
- "k8s.io/apimachinery/pkg/labels"
11
10
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
12
11
"k8s.io/apimachinery/pkg/util/sets"
13
12
"k8s.io/apimachinery/pkg/watch"
@@ -16,7 +15,6 @@ import (
16
15
"github.com/openshift/origin/pkg/network"
17
16
networkapi "github.com/openshift/origin/pkg/network/apis/network"
18
17
"github.com/openshift/origin/pkg/network/common"
19
- networkinformers "github.com/openshift/origin/pkg/network/generated/informers/internalversion/network/internalversion"
20
18
networkclient "github.com/openshift/origin/pkg/network/generated/internalclientset"
21
19
pnetid "github.com/openshift/origin/pkg/network/master/netid"
22
20
)
@@ -77,26 +75,17 @@ func (vmap *masterVNIDMap) isAdminNamespace(nsName string) bool {
77
75
return false
78
76
}
79
77
80
- func (vmap * masterVNIDMap ) populateVNIDs ( netNamespaceInformer networkinformers. NetNamespaceInformer ) error {
81
- netnsList , err := netNamespaceInformer . Lister (). List ( labels . Everything ())
82
- if err != nil {
83
- return err
78
+ func (vmap * masterVNIDMap ) markAllocatedNetID ( netid uint32 ) error {
79
+ // Skip GlobalVNID, not part of netID allocation range
80
+ if netid == network . GlobalVNID {
81
+ return nil
84
82
}
85
83
86
- for _ , netns := range netnsList {
87
- vmap .setVNID (netns .NetName , netns .NetID )
88
-
89
- // Skip GlobalVNID, not part of netID allocation range
90
- if netns .NetID == network .GlobalVNID {
91
- continue
92
- }
93
-
94
- switch err := vmap .netIDManager .Allocate (netns .NetID ); err {
95
- case nil : // Expected normal case
96
- case pnetid .ErrAllocated : // Expected when project networks are joined
97
- default :
98
- return fmt .Errorf ("unable to allocate netid %d: %v" , netns .NetID , err )
99
- }
84
+ switch err := vmap .netIDManager .Allocate (netid ); err {
85
+ case nil : // Expected normal case
86
+ case pnetid .ErrAllocated : // Expected when project networks are joined
87
+ default :
88
+ return fmt .Errorf ("unable to allocate netid %d: %v" , netid , err )
100
89
}
101
90
return nil
102
91
}
@@ -106,6 +95,12 @@ func (vmap *masterVNIDMap) allocateNetID(nsName string) (uint32, bool, error) {
106
95
exists := false
107
96
if netid , found := vmap .getVNID (nsName ); found {
108
97
exists = true
98
+
99
+ if err := vmap .markAllocatedNetID (netid ); err != nil {
100
+ return netid , exists , err
101
+ }
102
+ vmap .setVNID (nsName , netid )
103
+
109
104
return netid , exists , nil
110
105
}
111
106
@@ -279,11 +274,6 @@ func (vmap *masterVNIDMap) updateVNID(networkClient networkclient.Interface, ori
279
274
//--------------------- Master methods ----------------------
280
275
281
276
func (master * OsdnMaster ) VnidStartMaster () error {
282
- err := master .vnids .populateVNIDs (master .netNamespaceInformer )
283
- if err != nil {
284
- return err
285
- }
286
-
287
277
master .watchNamespaces ()
288
278
master .watchNetNamespaces ()
289
279
return nil
@@ -319,8 +309,7 @@ func (master *OsdnMaster) handleAddOrUpdateNetNamespace(obj, _ interface{}, even
319
309
netns := obj .(* networkapi.NetNamespace )
320
310
glog .V (5 ).Infof ("Watch %s event for NetNamespace %q" , eventType , netns .Name )
321
311
322
- err := master .vnids .updateVNID (master .networkClient , netns )
323
- if err != nil {
312
+ if err := master .vnids .updateVNID (master .networkClient , netns ); err != nil {
324
313
utilruntime .HandleError (fmt .Errorf ("Error updating netid: %v" , err ))
325
314
}
326
315
}
0 commit comments