Skip to content

Commit

Permalink
Move network type check to inside the network code
Browse files Browse the repository at this point in the history
Prevents races when the all-in-one is used with multi-tenant SDN
  • Loading branch information
smarterclayton committed Oct 10, 2017
1 parent b5f117a commit b0073eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
3 changes: 2 additions & 1 deletion pkg/cmd/server/kubernetes/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func (c *NetworkConfig) RunSDN() {
if c.SDNNode == nil {
return
}

if err := c.SDNNode.Start(); err != nil {
glog.Fatalf("error: SDN node startup failed: %v", err)
glog.Fatalf("SDN node startup failed: %v", err)
}
}

Expand Down
30 changes: 0 additions & 30 deletions pkg/cmd/server/kubernetes/network/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package network
import (
"fmt"
"net"
"strings"

"github.com/golang/glog"

miekgdns "github.com/miekg/dns"

kerrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kclientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/apis/componentconfig"
kclientsetexternal "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
Expand All @@ -19,7 +16,6 @@ import (
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/dns"
"github.com/openshift/origin/pkg/network"
networkapi "github.com/openshift/origin/pkg/network/apis/network"
networkclient "github.com/openshift/origin/pkg/network/generated/internalclientset"
)

Expand Down Expand Up @@ -66,10 +62,6 @@ func New(options configapi.NodeConfig, clusterDomain string, proxyConfig *compon
return nil, err
}

if err = validateNetworkPluginName(networkClient, options.NetworkConfig.NetworkPluginName); err != nil {
return nil, err
}

internalKubeInformers := kinternalinformers.NewSharedInformerFactory(internalKubeClient, proxyConfig.ConfigSyncPeriod.Duration)

var sdnNode network.NodeInterface
Expand Down Expand Up @@ -146,25 +138,3 @@ func New(options configapi.NodeConfig, clusterDomain string, proxyConfig *compon

return config, nil
}

func validateNetworkPluginName(networkClient networkclient.Interface, pluginName string) error {
if network.IsOpenShiftNetworkPlugin(pluginName) {
// Detect any plugin mismatches between node and master
clusterNetwork, err := networkClient.Network().ClusterNetworks().Get(networkapi.ClusterNetworkDefault, metav1.GetOptions{})
if kerrs.IsNotFound(err) {
return fmt.Errorf("master has not created a default cluster network, network plugin %q can not start", pluginName)
} else if err != nil {
return fmt.Errorf("cannot fetch %q cluster network: %v", networkapi.ClusterNetworkDefault, err)
}

if clusterNetwork.PluginName != strings.ToLower(pluginName) {
if len(clusterNetwork.PluginName) != 0 {
return fmt.Errorf("detected network plugin mismatch between OpenShift node(%q) and master(%q)", pluginName, clusterNetwork.PluginName)
} else {
// Do not return error in this case
glog.Warningf(`either there is network plugin mismatch between OpenShift node(%q) and master or OpenShift master is running an older version where we did not persist plugin name`, pluginName)
}
}
}
return nil
}
22 changes: 21 additions & 1 deletion pkg/network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/golang/glog"
"github.com/vishvananda/netlink"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -297,7 +298,11 @@ func (node *OsdnNode) killUpdateFailedPods(pods []kapi.Pod) error {
}

func (node *OsdnNode) Start() error {
log.V(2).Infof("Starting openshift-sdn network plugin")
glog.V(2).Infof("Starting openshift-sdn network plugin")

if err := validateNetworkPluginName(node.networkClient, node.policy.Name()); err != nil {
return fmt.Errorf("failed to validate network configuration: %v", err)
}

var err error
node.networkInfo, err = common.GetNetworkInfo(node.networkClient)
Expand Down Expand Up @@ -503,3 +508,18 @@ func (node *OsdnNode) handleDeleteService(obj interface{}) {
glog.V(5).Infof("Watch %s event for Service %q", watch.Deleted, serv.Name)
node.DeleteServiceRules(serv)
}

func validateNetworkPluginName(networkClient networkclient.Interface, pluginName string) error {
// Detect any plugin mismatches between node and master
clusterNetwork, err := networkClient.Network().ClusterNetworks().Get(networkapi.ClusterNetworkDefault, metav1.GetOptions{})
switch {
case errors.IsNotFound(err):
return fmt.Errorf("master has not created a default cluster network, network plugin %q can not start", pluginName)
case err != nil:
return fmt.Errorf("cannot fetch %q cluster network: %v", networkapi.ClusterNetworkDefault, err)
}
if clusterNetwork.PluginName != strings.ToLower(pluginName) {
return fmt.Errorf("detected network plugin mismatch between OpenShift node(%q) and master(%q)", pluginName, clusterNetwork.PluginName)
}
return nil
}

0 comments on commit b0073eb

Please sign in to comment.