Skip to content

Commit 5920c3c

Browse files
author
Ravi Sankar Penta
committed
Removed populating VNID map during SDN master startup
1 parent 291e20b commit 5920c3c

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

pkg/network/master/vnids.go

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/golang/glog"
88

99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
"k8s.io/apimachinery/pkg/labels"
1110
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1211
"k8s.io/apimachinery/pkg/util/sets"
1312
"k8s.io/apimachinery/pkg/watch"
@@ -16,7 +15,6 @@ import (
1615
"github.com/openshift/origin/pkg/network"
1716
networkapi "github.com/openshift/origin/pkg/network/apis/network"
1817
"github.com/openshift/origin/pkg/network/common"
19-
networkinformers "github.com/openshift/origin/pkg/network/generated/informers/internalversion/network/internalversion"
2018
networkclient "github.com/openshift/origin/pkg/network/generated/internalclientset"
2119
pnetid "github.com/openshift/origin/pkg/network/master/netid"
2220
)
@@ -77,26 +75,17 @@ func (vmap *masterVNIDMap) isAdminNamespace(nsName string) bool {
7775
return false
7876
}
7977

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
8482
}
8583

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)
10089
}
10190
return nil
10291
}
@@ -106,6 +95,12 @@ func (vmap *masterVNIDMap) allocateNetID(nsName string) (uint32, bool, error) {
10695
exists := false
10796
if netid, found := vmap.getVNID(nsName); found {
10897
exists = true
98+
99+
if err := vmap.markAllocatedNetID(netid); err != nil {
100+
return netid, exists, err
101+
}
102+
vmap.setVNID(nsName, netid)
103+
109104
return netid, exists, nil
110105
}
111106

@@ -279,11 +274,6 @@ func (vmap *masterVNIDMap) updateVNID(networkClient networkclient.Interface, ori
279274
//--------------------- Master methods ----------------------
280275

281276
func (master *OsdnMaster) VnidStartMaster() error {
282-
err := master.vnids.populateVNIDs(master.netNamespaceInformer)
283-
if err != nil {
284-
return err
285-
}
286-
287277
master.watchNamespaces()
288278
master.watchNetNamespaces()
289279
return nil
@@ -319,8 +309,7 @@ func (master *OsdnMaster) handleAddOrUpdateNetNamespace(obj, _ interface{}, even
319309
netns := obj.(*networkapi.NetNamespace)
320310
glog.V(5).Infof("Watch %s event for NetNamespace %q", eventType, netns.Name)
321311

322-
err := master.vnids.updateVNID(master.networkClient, netns)
323-
if err != nil {
312+
if err := master.vnids.updateVNID(master.networkClient, netns); err != nil {
324313
utilruntime.HandleError(fmt.Errorf("Error updating netid: %v", err))
325314
}
326315
}

0 commit comments

Comments
 (0)