diff --git a/plugins/osdn/common.go b/plugins/osdn/common.go index d184ae4..3f98305 100644 --- a/plugins/osdn/common.go +++ b/plugins/osdn/common.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/openshift/openshift-sdn/pkg/netutils" "github.com/openshift/openshift-sdn/plugins/osdn/api" osapi "github.com/openshift/origin/pkg/sdn/api" @@ -30,15 +29,7 @@ func isMultitenantPlugin(pluginType string) bool { } } -func GetNodeIP(node *kapi.Node) (string, error) { - if len(node.Status.Addresses) > 0 && node.Status.Addresses[0].Address != "" { - return node.Status.Addresses[0].Address, nil - } else { - return netutils.GetNodeIP(node.Name) - } -} - -func GetPodContainerID(pod *kapi.Pod) string { +func getPodContainerID(pod *kapi.Pod) string { if len(pod.Status.ContainerStatuses) > 0 { // Extract only container ID, pod.Status.ContainerStatuses[0].ContainerID is of the format: docker:// if parts := strings.Split(pod.Status.ContainerStatuses[0].ContainerID, "://"); len(parts) > 1 { @@ -48,6 +39,6 @@ func GetPodContainerID(pod *kapi.Pod) string { return "" } -func HostSubnetToString(subnet *osapi.HostSubnet) string { +func hostSubnetToString(subnet *osapi.HostSubnet) string { return fmt.Sprintf("%s [host: '%s'] [ip: '%s'] [subnet: '%s']", subnet.Name, subnet.Host, subnet.HostIP, subnet.Subnet) } diff --git a/plugins/osdn/controller.go b/plugins/osdn/controller.go index dad9bbb..917de72 100644 --- a/plugins/osdn/controller.go +++ b/plugins/osdn/controller.go @@ -325,7 +325,7 @@ func (plugin *OsdnNode) SetupSDN(localSubnetCIDR, clusterNetworkCIDR, servicesNe } func (plugin *OsdnNode) AddHostSubnetRules(subnet *osapi.HostSubnet) error { - glog.Infof("AddHostSubnetRules for %s", HostSubnetToString(subnet)) + glog.Infof("AddHostSubnetRules for %s", hostSubnetToString(subnet)) otx := ovs.NewTransaction(BR) otx.AddFlow("table=1, priority=100, tun_src=%s, actions=goto_table:5", subnet.HostIP) @@ -340,7 +340,7 @@ func (plugin *OsdnNode) AddHostSubnetRules(subnet *osapi.HostSubnet) error { } func (plugin *OsdnNode) DeleteHostSubnetRules(subnet *osapi.HostSubnet) error { - glog.Infof("DeleteHostSubnetRules for %s", HostSubnetToString(subnet)) + glog.Infof("DeleteHostSubnetRules for %s", hostSubnetToString(subnet)) otx := ovs.NewTransaction(BR) otx.DeleteFlows("table=1, tun_src=%s", subnet.HostIP) diff --git a/plugins/osdn/master.go b/plugins/osdn/master.go index cc49d57..a739324 100644 --- a/plugins/osdn/master.go +++ b/plugins/osdn/master.go @@ -30,13 +30,13 @@ func StartMaster(networkConfig osconfigapi.MasterNetworkConfig, osClient *osclie log.Infof("Initializing SDN master of type %q", networkConfig.NetworkPluginName) master := &OsdnMaster{ - registry: NewRegistry(osClient, kClient), + registry: newRegistry(osClient, kClient), vnids: newVnidMap(), adminNamespaces: make([]string, 0), } // Validate command-line/config parameters - clusterNetwork, hostBitsPerSubnet, serviceNetwork, err := ValidateClusterNetwork(networkConfig.ClusterNetworkCIDR, int(networkConfig.HostSubnetLength), networkConfig.ServiceNetworkCIDR) + clusterNetwork, hostBitsPerSubnet, serviceNetwork, err := validateClusterNetwork(networkConfig.ClusterNetworkCIDR, int(networkConfig.HostSubnetLength), networkConfig.ServiceNetworkCIDR) if err != nil { return err } diff --git a/plugins/osdn/node.go b/plugins/osdn/node.go index 6d4ff42..5dfccc5 100644 --- a/plugins/osdn/node.go +++ b/plugins/osdn/node.go @@ -66,7 +66,7 @@ func NewNodePlugin(pluginType string, osClient *osclient.Client, kClient *kclien plugin := &OsdnNode{ multitenant: isMultitenantPlugin(pluginType), - registry: NewRegistry(osClient, kClient), + registry: newRegistry(osClient, kClient), localIP: selfIP, hostName: hostname, vnids: newVnidMap(), @@ -85,12 +85,12 @@ func (node *OsdnNode) Start() error { } ipt := iptables.New(kexec.New(), utildbus.New(), iptables.ProtocolIpv4) - if err := SetupIptables(ipt, clusterNetwork.String()); err != nil { + if err := setupIptables(ipt, clusterNetwork.String()); err != nil { return fmt.Errorf("Failed to set up iptables: %v", err) } ipt.AddReloadFunc(func() { - err := SetupIptables(ipt, clusterNetwork.String()) + err := setupIptables(ipt, clusterNetwork.String()) if err != nil { log.Errorf("Error reloading iptables: %v\n", err) } @@ -113,7 +113,7 @@ func (node *OsdnNode) Start() error { return err } for _, p := range pods { - containerID := GetPodContainerID(&p) + 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) @@ -156,7 +156,7 @@ type FirewallRule struct { args []string } -func SetupIptables(ipt iptables.Interface, clusterNetworkCIDR string) error { +func setupIptables(ipt iptables.Interface, clusterNetworkCIDR string) error { rules := []FirewallRule{ {"nat", "POSTROUTING", []string{"-s", clusterNetworkCIDR, "!", "-d", clusterNetworkCIDR, "-j", "MASQUERADE"}}, {"filter", "INPUT", []string{"-p", "udp", "-m", "multiport", "--dports", "4789", "-m", "comment", "--comment", "001 vxlan incoming", "-j", "ACCEPT"}}, diff --git a/plugins/osdn/proxy.go b/plugins/osdn/proxy.go index 10253ac..00cb324 100644 --- a/plugins/osdn/proxy.go +++ b/plugins/osdn/proxy.go @@ -31,7 +31,7 @@ type ovsProxyPlugin struct { func NewProxyPlugin(pluginType string, osClient *osclient.Client, kClient *kclient.Client) (api.FilteringEndpointsConfigHandler, error) { if isMultitenantPlugin(pluginType) { return &ovsProxyPlugin{ - registry: NewRegistry(osClient, kClient), + registry: newRegistry(osClient, kClient), podsByIP: make(map[string]*kapi.Pod), }, nil } diff --git a/plugins/osdn/registry.go b/plugins/osdn/registry.go index 4e0b72d..f2058c6 100644 --- a/plugins/osdn/registry.go +++ b/plugins/osdn/registry.go @@ -39,7 +39,7 @@ const ( Pods ResourceName = "Pods" ) -func NewRegistry(osClient *osclient.Client, kClient *kclient.Client) *Registry { +func newRegistry(osClient *osclient.Client, kClient *kclient.Client) *Registry { return &Registry{ oClient: osClient, kClient: kClient, @@ -146,7 +146,7 @@ func (registry *Registry) CreateClusterNetwork(clusterNetwork *net.IPNet, subnet return err } -func ValidateClusterNetwork(network string, hostSubnetLength int, serviceNetwork string) (*net.IPNet, int, *net.IPNet, error) { +func validateClusterNetwork(network string, hostSubnetLength int, serviceNetwork string) (*net.IPNet, int, *net.IPNet, error) { _, cn, err := net.ParseCIDR(network) if err != nil { return nil, -1, nil, fmt.Errorf("Failed to parse ClusterNetwork CIDR %s: %v", network, err) @@ -174,7 +174,7 @@ func (registry *Registry) cacheClusterNetwork() error { return err } - registry.clusterNetwork, registry.hostSubnetLength, registry.serviceNetwork, err = ValidateClusterNetwork(cn.Network, cn.HostSubnetLength, cn.ServiceNetwork) + registry.clusterNetwork, registry.hostSubnetLength, registry.serviceNetwork, err = validateClusterNetwork(cn.Network, cn.HostSubnetLength, cn.ServiceNetwork) return err } diff --git a/plugins/osdn/subnets.go b/plugins/osdn/subnets.go index 3b5aadd..fede8b6 100644 --- a/plugins/osdn/subnets.go +++ b/plugins/osdn/subnets.go @@ -30,7 +30,7 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetwork *net.IPNet, hostSubne // Don't error out; just warn so the error can be corrected with 'oc' log.Errorf("Failed to validate HostSubnet %s: %v", err) } else { - log.Infof("Found existing HostSubnet %s", HostSubnetToString(&sub)) + log.Infof("Found existing HostSubnet %s", hostSubnetToString(&sub)) } } @@ -92,9 +92,9 @@ func (master *OsdnMaster) addNode(nodeName string, nodeIP string) error { } if subnetAllocated { - log.Infof("Created HostSubnet %s", HostSubnetToString(sub)) + log.Infof("Created HostSubnet %s", hostSubnetToString(sub)) } else { - log.Infof("Updated HostSubnet %s", HostSubnetToString(sub)) + log.Infof("Updated HostSubnet %s", hostSubnetToString(sub)) } return nil } @@ -114,10 +114,18 @@ func (master *OsdnMaster) deleteNode(nodeName string) error { return fmt.Errorf("Error deleting subnet %v for node %q: %v", sub, nodeName, err) } - log.Infof("Deleted HostSubnet %s", HostSubnetToString(sub)) + log.Infof("Deleted HostSubnet %s", hostSubnetToString(sub)) return nil } +func getNodeIP(node *kapi.Node) (string, error) { + if len(node.Status.Addresses) > 0 && node.Status.Addresses[0].Address != "" { + return node.Status.Addresses[0].Address, nil + } else { + return netutils.GetNodeIP(node.Name) + } +} + func (master *OsdnMaster) watchNodes() { eventQueue := master.registry.RunEventQueue(Nodes) nodeAddressMap := map[types.UID]string{} @@ -132,7 +140,7 @@ func (master *OsdnMaster) watchNodes() { name := node.ObjectMeta.Name uid := node.ObjectMeta.UID - nodeIP, err := GetNodeIP(node) + nodeIP, err := getNodeIP(node) if err != nil { log.Errorf("Failed to get node IP for %s, skipping event: %v, node: %v", name, eventType, node) continue @@ -207,7 +215,7 @@ func (node *OsdnNode) initSelfSubnet() error { return fmt.Errorf("Failed to validate own HostSubnet: %v", err) } - log.Infof("Found local HostSubnet %s", HostSubnetToString(subnet)) + log.Infof("Found local HostSubnet %s", hostSubnetToString(subnet)) node.localSubnet = subnet return nil } diff --git a/plugins/osdn/vnids.go b/plugins/osdn/vnids.go index 96adb88..0ed0cf6 100644 --- a/plugins/osdn/vnids.go +++ b/plugins/osdn/vnids.go @@ -174,7 +174,7 @@ func (node *OsdnNode) updatePodNetwork(namespace string, netID uint) error { return err } for _, pod := range pods { - err := node.UpdatePod(pod.Namespace, pod.Name, kubetypes.DockerID(GetPodContainerID(&pod))) + err := node.UpdatePod(pod.Namespace, pod.Name, kubetypes.DockerID(getPodContainerID(&pod))) if err != nil { return err }