This repository has been archived by the owner on Jul 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfde8dd
commit 3395f29
Showing
6 changed files
with
184 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package osdn | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
log "github.com/golang/glog" | ||
|
||
"github.com/openshift/openshift-sdn/pkg/netutils" | ||
"github.com/openshift/openshift-sdn/plugins/osdn/api" | ||
|
||
osclient "github.com/openshift/origin/pkg/client" | ||
osapi "github.com/openshift/origin/pkg/sdn/api" | ||
|
||
kapi "k8s.io/kubernetes/pkg/api" | ||
kclient "k8s.io/kubernetes/pkg/client/unversioned" | ||
kubeletTypes "k8s.io/kubernetes/pkg/kubelet/container" | ||
kexec "k8s.io/kubernetes/pkg/util/exec" | ||
kubeutilnet "k8s.io/kubernetes/pkg/util/net" | ||
) | ||
|
||
type OsdnNode struct { | ||
multitenant bool | ||
registry *Registry | ||
localIP string | ||
localSubnet *osapi.HostSubnet | ||
hostName string | ||
podNetworkReady chan struct{} | ||
vnids vnidMap | ||
iptablesSyncPeriod time.Duration | ||
mtu uint | ||
} | ||
|
||
// Called by higher layers to create the plugin SDN node instance | ||
func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclient.Client, hostname string, selfIP string, iptablesSyncPeriod time.Duration, mtu uint) (api.OsdnNodePlugin, error) { | ||
if !IsOpenShiftNetworkPlugin(pluginName) { | ||
return nil, nil | ||
} | ||
|
||
log.Infof("Initializing SDN node of type %q with configured hostname %q (IP %q), iptables sync period %q", pluginName, hostname, selfIP, iptablesSyncPeriod.String()) | ||
if hostname == "" { | ||
output, err := kexec.New().Command("uname", "-n").CombinedOutput() | ||
if err != nil { | ||
return nil, err | ||
} | ||
hostname = strings.TrimSpace(string(output)) | ||
log.Infof("Resolved hostname to %q", hostname) | ||
} | ||
if selfIP == "" { | ||
var err error | ||
selfIP, err = netutils.GetNodeIP(hostname) | ||
if err != nil { | ||
log.V(5).Infof("Failed to determine node address from hostname %s; using default interface (%v)", hostname, err) | ||
defaultIP, err := kubeutilnet.ChooseHostInterface() | ||
if err != nil { | ||
return nil, err | ||
} | ||
selfIP = defaultIP.String() | ||
log.Infof("Resolved IP address to %q", selfIP) | ||
} | ||
} | ||
|
||
plugin := &OsdnNode{ | ||
multitenant: IsOpenShiftMultitenantNetworkPlugin(pluginName), | ||
registry: NewRegistry(osClient, kClient), | ||
localIP: selfIP, | ||
hostName: hostname, | ||
vnids: newVnidMap(), | ||
podNetworkReady: make(chan struct{}), | ||
iptablesSyncPeriod: iptablesSyncPeriod, | ||
mtu: mtu, | ||
} | ||
return plugin, nil | ||
} | ||
|
||
func (node *OsdnNode) Start() error { | ||
ni, err := node.registry.GetNetworkInfo() | ||
if err != nil { | ||
return fmt.Errorf("Failed to get network information: %v", err) | ||
} | ||
|
||
nodeIPTables := NewNodeIPTables(ni.ClusterNetwork.String(), node.iptablesSyncPeriod) | ||
if err := nodeIPTables.Setup(); err != nil { | ||
return fmt.Errorf("Failed to set up iptables: %v", err) | ||
} | ||
|
||
networkChanged, err := node.SubnetStartNode(node.mtu) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if node.multitenant { | ||
if err := node.VnidStartNode(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if networkChanged { | ||
pods, err := node.GetLocalPods(kapi.NamespaceAll) | ||
if err != nil { | ||
return err | ||
} | ||
for _, p := range pods { | ||
containerID := GetPodContainerID(&p) | ||
err = node.UpdatePod(p.Namespace, p.Name, kubeletTypes.DockerID(containerID)) | ||
if err != nil { | ||
log.Warningf("Could not update pod %q (%s): %s", p.Name, containerID, err) | ||
} | ||
} | ||
} | ||
|
||
node.markPodNetworkReady() | ||
|
||
return nil | ||
} | ||
|
||
func (node *OsdnNode) GetLocalPods(namespace string) ([]kapi.Pod, error) { | ||
return node.registry.GetRunningPods(node.hostName, namespace) | ||
} | ||
|
||
func (node *OsdnNode) markPodNetworkReady() { | ||
close(node.podNetworkReady) | ||
} | ||
|
||
func (node *OsdnNode) WaitForPodNetworkReady() error { | ||
logInterval := 10 * time.Second | ||
numIntervals := 12 // timeout: 2 mins | ||
|
||
for i := 0; i < numIntervals; i++ { | ||
select { | ||
// Wait for StartNode() to finish SDN setup | ||
case <-node.podNetworkReady: | ||
return nil | ||
case <-time.After(logInterval): | ||
log.Infof("Waiting for SDN pod network to be ready...") | ||
} | ||
} | ||
return fmt.Errorf("SDN pod network is not ready(timeout: 2 mins)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.