// Called by plug factory functions to initialize the generic plugin instance func (oc *OvsController) BaseInit(registry *Registry, flowController FlowController, pluginHooks PluginHooks, hostname string, selfIP string) error { if hostname == "" { output, err := kexec.New().Command("uname", "-n").CombinedOutput() if err != nil { return err } hostname = strings.TrimSpace(string(output)) } if selfIP == "" { var err error selfIP, err = netutils.GetNodeIP(hostname) if err != nil { return err } } log.Infof("Self IP: %s.", selfIP) oc.pluginHooks = pluginHooks oc.Registry = registry oc.flowController = flowController oc.localIP = selfIP oc.hostName = hostname oc.VNIDMap = make(map[string]uint) oc.sig = make(chan struct{}) oc.podNetworkReady = make(chan struct{}) oc.adminNamespaces = make([]string, 0) oc.services = make(map[string]api.Service) return nil }
func GetNodeIP(node *kapi.Node) (string, error) { if len(node.Status.Addresses) > 0 { return node.Status.Addresses[0].Address, nil } else { return netutils.GetNodeIP(node.Name) } }
func (registry *Registry) WatchNodes(receiver chan<- *NodeEvent) error { eventQueue := registry.runEventQueue("Nodes") nodeAddressMap := map[types.UID]string{} for { eventType, obj, err := eventQueue.Pop() if err != nil { return err } node := obj.(*kapi.Node) nodeIP := "" if len(node.Status.Addresses) > 0 { nodeIP = node.Status.Addresses[0].Address } else { nodeIP, err = netutils.GetNodeIP(node.ObjectMeta.Name) if err != nil { return err } } switch eventType { case watch.Added, watch.Modified: oldNodeIP, ok := nodeAddressMap[node.ObjectMeta.UID] if ok && (oldNodeIP == nodeIP) { continue } receiver <- &NodeEvent{Type: Added, Node: node} nodeAddressMap[node.ObjectMeta.UID] = nodeIP case watch.Deleted: receiver <- &NodeEvent{Type: Deleted, Node: node} delete(nodeAddressMap, node.ObjectMeta.UID) } } }
func (registry *Registry) WatchNodes(receiver chan<- *osdnapi.NodeEvent, ready chan<- bool, start <-chan string, stop <-chan bool) error { eventQueue, startVersion := registry.createAndRunEventQueue("Node", ready, start) nodeAddressMap, err := registry.getNodeAddressMap() if err != nil { return err } checkCondition := true for { eventType, obj, err := getEvent(eventQueue, startVersion, &checkCondition) if err != nil { return err } node := obj.(*kapi.Node) nodeIP := "" if len(node.Status.Addresses) > 0 { nodeIP = node.Status.Addresses[0].Address } else { nodeIP, err = netutils.GetNodeIP(node.ObjectMeta.Name) if err != nil { return err } } switch eventType { case watch.Added: receiver <- &osdnapi.NodeEvent{Type: osdnapi.Added, Node: osdnapi.Node{Name: node.ObjectMeta.Name, IP: nodeIP}} nodeAddressMap[node.ObjectMeta.UID] = nodeIP case watch.Modified: oldNodeIP, ok := nodeAddressMap[node.ObjectMeta.UID] if ok && oldNodeIP != nodeIP { // Node Added event will handle update subnet if there is ip mismatch receiver <- &osdnapi.NodeEvent{Type: osdnapi.Added, Node: osdnapi.Node{Name: node.ObjectMeta.Name, IP: nodeIP}} nodeAddressMap[node.ObjectMeta.UID] = nodeIP } case watch.Deleted: receiver <- &osdnapi.NodeEvent{Type: osdnapi.Deleted, Node: osdnapi.Node{Name: node.ObjectMeta.Name}} delete(nodeAddressMap, node.ObjectMeta.UID) } } }
// Called by plug factory functions to initialize the generic plugin instance func (oc *OsdnController) BaseInit(registry *Registry, pluginHooks PluginHooks, multitenant bool, hostname string, selfIP string, iptablesSyncPeriod time.Duration) error { log.Infof("Starting with configured hostname %q (IP %q), iptables sync period %q", hostname, selfIP, iptablesSyncPeriod.String()) if hostname == "" { output, err := kexec.New().Command("uname", "-n").CombinedOutput() if err != nil { return err } hostname = strings.TrimSpace(string(output)) } 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 err } selfIP = defaultIP.String() } } if multitenant { log.Infof("Initializing multi-tenant plugin for %s (%s)", hostname, selfIP) } else { log.Infof("Initializing single-tenant plugin for %s (%s)", hostname, selfIP) } oc.pluginHooks = pluginHooks oc.Registry = registry oc.localIP = selfIP oc.HostName = hostname oc.vnidMap = make(map[string]uint) oc.podNetworkReady = make(chan struct{}) oc.adminNamespaces = make([]string, 0) oc.iptablesSyncPeriod = iptablesSyncPeriod return nil }
func (registry *Registry) GetNodes() ([]osdnapi.Node, string, error) { knodes, err := registry.kClient.Nodes().List(kapi.ListOptions{}) if err != nil { return nil, "", err } nodes := make([]osdnapi.Node, 0, len(knodes.Items)) for _, node := range knodes.Items { var nodeIP string if len(node.Status.Addresses) > 0 { nodeIP = node.Status.Addresses[0].Address } else { nodeIP, err = netutils.GetNodeIP(node.ObjectMeta.Name) if err != nil { return nil, "", err } } nodes = append(nodes, osdnapi.Node{Name: node.ObjectMeta.Name, IP: nodeIP}) } return nodes, knodes.ListMeta.ResourceVersion, nil }
// 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 }
// Called by plug factory functions to initialize the generic plugin instance func (oc *OvsController) BaseInit(registry *Registry, flowController FlowController, pluginHooks PluginHooks, hostname string, selfIP string) error { if hostname == "" { output, err := kexec.New().Command("uname", "-n").CombinedOutput() if err != nil { return err } hostname = strings.TrimSpace(string(output)) } 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 err } selfIP = defaultIP.String() } } log.Infof("Self IP: %s.", selfIP) oc.pluginHooks = pluginHooks oc.Registry = registry oc.flowController = flowController oc.localIP = selfIP oc.hostName = hostname oc.VNIDMap = make(map[string]uint) oc.sig = make(chan struct{}) oc.podNetworkReady = make(chan struct{}) oc.adminNamespaces = make([]string, 0) oc.services = make(map[string]api.Service) return nil }