Skip to content

Commit

Permalink
Moved getLocalSubnet() from node/sdn_controller.go to node/subnets.go
Browse files Browse the repository at this point in the history
- subnets.go handles subnet related operations and it seems logical to keep
  getLocalSubnet() in this file.
  • Loading branch information
Ravi Sankar Penta committed Dec 13, 2017
1 parent ac0793c commit 2603e1f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
38 changes: 0 additions & 38 deletions pkg/network/node/sdn_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,13 @@ import (
"github.com/openshift/origin/pkg/network/common"
"github.com/openshift/origin/pkg/util/netutils"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilwait "k8s.io/apimachinery/pkg/util/wait"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/sysctl"

"github.com/vishvananda/netlink"
)

func (plugin *OsdnNode) getLocalSubnet() (string, error) {
var subnet *networkapi.HostSubnet
// If the HostSubnet doesn't already exist, it will be created by the SDN master in
// response to the kubelet registering itself with the master (which should be
// happening in another goroutine in parallel with this). Sometimes this takes
// unexpectedly long though, so give it plenty of time before returning an error
// (since that will cause the node process to exit).
backoff := utilwait.Backoff{
// ~2 mins total
Duration: time.Second,
Factor: 1.5,
Steps: 11,
}
err := utilwait.ExponentialBackoff(backoff, func() (bool, error) {
var err error
subnet, err = plugin.networkClient.Network().HostSubnets().Get(plugin.hostName, metav1.GetOptions{})
if err == nil {
return true, nil
} else if kapierrors.IsNotFound(err) {
glog.Warningf("Could not find an allocated subnet for node: %s, Waiting...", plugin.hostName)
return false, nil
} else {
return false, err
}
})
if err != nil {
return "", fmt.Errorf("failed to get subnet for this host: %s, error: %v", plugin.hostName, err)
}

if err = plugin.networkInfo.ValidateNodeIP(subnet.HostIP); err != nil {
return "", fmt.Errorf("failed to validate own HostSubnet: %v", err)
}

return subnet.Subnet, nil
}

func (plugin *OsdnNode) alreadySetUp(localSubnetGatewayCIDR string, clusterNetworkCIDR []string) bool {
var found bool

Expand Down
47 changes: 44 additions & 3 deletions pkg/network/node/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
package node

import (
"fmt"
"time"

"github.com/golang/glog"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilwait "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/cache"

Expand All @@ -19,14 +24,50 @@ func (node *OsdnNode) SubnetStartNode() error {

type hostSubnetMap map[string]*networkapi.HostSubnet

func (plugin *OsdnNode) updateVXLANMulticastRules(subnets hostSubnetMap) {
func (node *OsdnNode) getLocalSubnet() (string, error) {
var subnet *networkapi.HostSubnet
// If the HostSubnet doesn't already exist, it will be created by the SDN master in
// response to the kubelet registering itself with the master (which should be
// happening in another goroutine in parallel with this). Sometimes this takes
// unexpectedly long though, so give it plenty of time before returning an error
// (since that will cause the node process to exit).
backoff := utilwait.Backoff{
// ~2 mins total
Duration: time.Second,
Factor: 1.5,
Steps: 11,
}
err := utilwait.ExponentialBackoff(backoff, func() (bool, error) {
var err error
subnet, err = node.networkClient.Network().HostSubnets().Get(node.hostName, metav1.GetOptions{})
if err == nil {
return true, nil
} else if kapierrors.IsNotFound(err) {
glog.Warningf("Could not find an allocated subnet for node: %s, Waiting...", node.hostName)
return false, nil
} else {
return false, err
}
})
if err != nil {
return "", fmt.Errorf("failed to get subnet for this host: %s, error: %v", node.hostName, err)
}

if err = node.networkInfo.ValidateNodeIP(subnet.HostIP); err != nil {
return "", fmt.Errorf("failed to validate own HostSubnet: %v", err)
}

return subnet.Subnet, nil
}

func (node *OsdnNode) updateVXLANMulticastRules(subnets hostSubnetMap) {
remoteIPs := make([]string, 0, len(subnets))
for _, subnet := range subnets {
if subnet.HostIP != plugin.localIP {
if subnet.HostIP != node.localIP {
remoteIPs = append(remoteIPs, subnet.HostIP)
}
}
if err := plugin.oc.UpdateVXLANMulticastFlows(remoteIPs); err != nil {
if err := node.oc.UpdateVXLANMulticastFlows(remoteIPs); err != nil {
glog.Errorf("Error updating OVS VXLAN multicast flows: %v", err)
}
}
Expand Down

0 comments on commit 2603e1f

Please sign in to comment.