The SDN initialization was being called from subnets.go for historical
reasons; have node.go call it directly instead. Also, don't bother
passing data to SetupSDN() that it could get from the OsdnNode
structure itself (another historical artifact).
| ... | ... |
@@ -46,6 +46,33 @@ func getPluginVersion(multitenant bool) []string {
|
| 46 | 46 |
return []string{"00", version}
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 |
+func (plugin *OsdnNode) getLocalSubnet() (string, error) {
|
|
| 50 |
+ // timeout: 30 secs |
|
| 51 |
+ retries := 60 |
|
| 52 |
+ retryInterval := 500 * time.Millisecond |
|
| 53 |
+ |
|
| 54 |
+ var err error |
|
| 55 |
+ var subnet *osapi.HostSubnet |
|
| 56 |
+ // Try every retryInterval and bail-out if it exceeds max retries |
|
| 57 |
+ for i := 0; i < retries; i++ {
|
|
| 58 |
+ subnet, err = plugin.osClient.HostSubnets().Get(plugin.hostName) |
|
| 59 |
+ if err == nil {
|
|
| 60 |
+ break |
|
| 61 |
+ } |
|
| 62 |
+ glog.Warningf("Could not find an allocated subnet for node: %s, Waiting...", plugin.hostName)
|
|
| 63 |
+ time.Sleep(retryInterval) |
|
| 64 |
+ } |
|
| 65 |
+ if err != nil {
|
|
| 66 |
+ return "", fmt.Errorf("Failed to get subnet for this host: %s, error: %v", plugin.hostName, err)
|
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+ if err = plugin.networkInfo.validateNodeIP(subnet.HostIP); err != nil {
|
|
| 70 |
+ return "", fmt.Errorf("Failed to validate own HostSubnet: %v", err)
|
|
| 71 |
+ } |
|
| 72 |
+ |
|
| 73 |
+ return subnet.Subnet, nil |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 49 | 76 |
func (plugin *OsdnNode) alreadySetUp(localSubnetGatewayCIDR, clusterNetworkCIDR string) bool {
|
| 50 | 77 |
var found bool |
| 51 | 78 |
|
| ... | ... |
@@ -144,7 +171,14 @@ func deleteLocalSubnetRoute(device, localSubnetCIDR string) {
|
| 144 | 144 |
glog.Errorf("Timed out looking for %s route for dev %s; if it appears later it will not be deleted.", localSubnetCIDR, device)
|
| 145 | 145 |
} |
| 146 | 146 |
|
| 147 |
-func (plugin *OsdnNode) SetupSDN(localSubnetCIDR, clusterNetworkCIDR, servicesNetworkCIDR string, mtu uint32) (bool, error) {
|
|
| 147 |
+func (plugin *OsdnNode) SetupSDN() (bool, error) {
|
|
| 148 |
+ localSubnetCIDR, err := plugin.getLocalSubnet() |
|
| 149 |
+ if err != nil {
|
|
| 150 |
+ return false, err |
|
| 151 |
+ } |
|
| 152 |
+ clusterNetworkCIDR := plugin.networkInfo.ClusterNetwork.String() |
|
| 153 |
+ serviceNetworkCIDR := plugin.networkInfo.ServiceNetwork.String() |
|
| 154 |
+ |
|
| 148 | 155 |
_, ipnet, err := net.ParseCIDR(localSubnetCIDR) |
| 149 | 156 |
localSubnetMaskLength, _ := ipnet.Mask.Size() |
| 150 | 157 |
localSubnetGateway := netutils.GenerateDefaultGateway(ipnet).String() |
| ... | ... |
@@ -158,7 +192,7 @@ func (plugin *OsdnNode) SetupSDN(localSubnetCIDR, clusterNetworkCIDR, servicesNe |
| 158 | 158 |
} |
| 159 | 159 |
glog.V(5).Infof("[SDN setup] full SDN setup required")
|
| 160 | 160 |
|
| 161 |
- mtuStr := fmt.Sprint(mtu) |
|
| 161 |
+ mtuStr := fmt.Sprint(plugin.mtu) |
|
| 162 | 162 |
|
| 163 | 163 |
exec := kexec.New() |
| 164 | 164 |
itx := ipcmd.NewTransaction(exec, LBR) |
| ... | ... |
@@ -266,7 +300,7 @@ func (plugin *OsdnNode) SetupSDN(localSubnetCIDR, clusterNetworkCIDR, servicesNe |
| 266 | 266 |
otx.AddFlow("table=2, priority=0, actions=drop")
|
| 267 | 267 |
|
| 268 | 268 |
// Table 3: from OpenShift container; service vs non-service |
| 269 |
- otx.AddFlow("table=3, priority=100, ip, nw_dst=%s, actions=goto_table:4", servicesNetworkCIDR)
|
|
| 269 |
+ otx.AddFlow("table=3, priority=100, ip, nw_dst=%s, actions=goto_table:4", serviceNetworkCIDR)
|
|
| 270 | 270 |
otx.AddFlow("table=3, priority=0, actions=goto_table:5")
|
| 271 | 271 |
|
| 272 | 272 |
// Table 4: from OpenShift container; service dispatch; filled in by AddServiceRules() |
| ... | ... |
@@ -313,7 +347,7 @@ func (plugin *OsdnNode) SetupSDN(localSubnetCIDR, clusterNetworkCIDR, servicesNe |
| 313 | 313 |
itx.SetLink("mtu", mtuStr)
|
| 314 | 314 |
itx.SetLink("up")
|
| 315 | 315 |
itx.AddRoute(clusterNetworkCIDR, "proto", "kernel", "scope", "link") |
| 316 |
- itx.AddRoute(servicesNetworkCIDR) |
|
| 316 |
+ itx.AddRoute(serviceNetworkCIDR) |
|
| 317 | 317 |
err = itx.EndTransaction() |
| 318 | 318 |
if err != nil {
|
| 319 | 319 |
return false, err |
| ... | ... |
@@ -30,7 +30,6 @@ type OsdnNode struct {
|
| 30 | 30 |
ovs *ovs.Interface |
| 31 | 31 |
networkInfo *NetworkInfo |
| 32 | 32 |
localIP string |
| 33 |
- localSubnet *osapi.HostSubnet |
|
| 34 | 33 |
hostName string |
| 35 | 34 |
podNetworkReady chan struct{}
|
| 36 | 35 |
vnids *nodeVNIDMap |
| ... | ... |
@@ -102,8 +101,12 @@ func (node *OsdnNode) Start() error {
|
| 102 | 102 |
return fmt.Errorf("Failed to set up iptables: %v", err)
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 |
- var networkChanged bool |
|
| 106 |
- networkChanged, err = node.SubnetStartNode(node.mtu) |
|
| 105 |
+ networkChanged, err := node.SetupSDN() |
|
| 106 |
+ if err != nil {
|
|
| 107 |
+ return err |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ err = node.SubnetStartNode() |
|
| 107 | 111 |
if err != nil {
|
| 108 | 112 |
return err |
| 109 | 113 |
} |
| ... | ... |
@@ -3,7 +3,6 @@ package plugin |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"net" |
| 6 |
- "time" |
|
| 7 | 6 |
|
| 8 | 7 |
log "github.com/golang/glog" |
| 9 | 8 |
|
| ... | ... |
@@ -197,48 +196,8 @@ func (master *OsdnMaster) watchNodes() {
|
| 197 | 197 |
}) |
| 198 | 198 |
} |
| 199 | 199 |
|
| 200 |
-func (node *OsdnNode) SubnetStartNode(mtu uint32) (bool, error) {
|
|
| 201 |
- err := node.initSelfSubnet() |
|
| 202 |
- if err != nil {
|
|
| 203 |
- return false, err |
|
| 204 |
- } |
|
| 205 |
- |
|
| 206 |
- networkChanged, err := node.SetupSDN(node.localSubnet.Subnet, node.networkInfo.ClusterNetwork.String(), node.networkInfo.ServiceNetwork.String(), mtu) |
|
| 207 |
- if err != nil {
|
|
| 208 |
- return false, err |
|
| 209 |
- } |
|
| 210 |
- |
|
| 200 |
+func (node *OsdnNode) SubnetStartNode() error {
|
|
| 211 | 201 |
go utilwait.Forever(node.watchSubnets, 0) |
| 212 |
- return networkChanged, nil |
|
| 213 |
-} |
|
| 214 |
- |
|
| 215 |
-func (node *OsdnNode) initSelfSubnet() error {
|
|
| 216 |
- // timeout: 30 secs |
|
| 217 |
- retries := 60 |
|
| 218 |
- retryInterval := 500 * time.Millisecond |
|
| 219 |
- |
|
| 220 |
- var err error |
|
| 221 |
- var subnet *osapi.HostSubnet |
|
| 222 |
- // Try every retryInterval and bail-out if it exceeds max retries |
|
| 223 |
- for i := 0; i < retries; i++ {
|
|
| 224 |
- // Get subnet for current node |
|
| 225 |
- subnet, err = node.osClient.HostSubnets().Get(node.hostName) |
|
| 226 |
- if err == nil {
|
|
| 227 |
- break |
|
| 228 |
- } |
|
| 229 |
- log.Warningf("Could not find an allocated subnet for node: %s, Waiting...", node.hostName)
|
|
| 230 |
- time.Sleep(retryInterval) |
|
| 231 |
- } |
|
| 232 |
- if err != nil {
|
|
| 233 |
- return fmt.Errorf("Failed to get subnet for this host: %s, error: %v", node.hostName, err)
|
|
| 234 |
- } |
|
| 235 |
- |
|
| 236 |
- if err = node.networkInfo.validateNodeIP(subnet.HostIP); err != nil {
|
|
| 237 |
- return fmt.Errorf("Failed to validate own HostSubnet: %v", err)
|
|
| 238 |
- } |
|
| 239 |
- |
|
| 240 |
- log.Infof("Found local HostSubnet %s", hostSubnetToString(subnet))
|
|
| 241 |
- node.localSubnet = subnet |
|
| 242 | 202 |
return nil |
| 243 | 203 |
} |
| 244 | 204 |
|