From e398de3d2f61844cac42b7bc285a1d9a1e75eaf5 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 17 May 2016 08:43:45 -0400 Subject: [PATCH] Unexport names that don't need to be exported. Also, move getNodeIP() from common.go to subnets.go since it's only used from there. --- plugins/osdn/common.go | 14 ++------------ plugins/osdn/controller.go | 4 ++-- plugins/osdn/master.go | 4 ++-- plugins/osdn/node.go | 6 +++--- plugins/osdn/node_iptables.go | 2 +- plugins/osdn/proxy.go | 2 +- plugins/osdn/registry.go | 6 +++--- plugins/osdn/subnets.go | 20 ++++++++++++++------ plugins/osdn/vnids.go | 2 +- 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/plugins/osdn/common.go b/plugins/osdn/common.go index b21ee9f..0ae49b4 100644 --- a/plugins/osdn/common.go +++ b/plugins/osdn/common.go @@ -4,22 +4,12 @@ import ( "fmt" "strings" - "github.com/openshift/openshift-sdn/pkg/netutils" - osapi "github.com/openshift/origin/pkg/sdn/api" kapi "k8s.io/kubernetes/pkg/api" ) -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 { @@ -29,6 +19,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: %q, ip: %q, subnet: %q)", subnet.Name, subnet.Host, subnet.HostIP, subnet.Subnet) } diff --git a/plugins/osdn/controller.go b/plugins/osdn/controller.go index e27568c..16d35fd 100644 --- a/plugins/osdn/controller.go +++ b/plugins/osdn/controller.go @@ -328,7 +328,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) @@ -343,7 +343,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 3b7ecd4..15e8ed7 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 - ni, err := ValidateClusterNetwork(networkConfig.ClusterNetworkCIDR, int(networkConfig.HostSubnetLength), networkConfig.ServiceNetworkCIDR, networkConfig.NetworkPluginName) + ni, err := validateClusterNetwork(networkConfig.ClusterNetworkCIDR, int(networkConfig.HostSubnetLength), networkConfig.ServiceNetworkCIDR, networkConfig.NetworkPluginName) if err != nil { return err } diff --git a/plugins/osdn/node.go b/plugins/osdn/node.go index c60b14e..54cffe8 100644 --- a/plugins/osdn/node.go +++ b/plugins/osdn/node.go @@ -63,7 +63,7 @@ func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclien plugin := &OsdnNode{ multitenant: IsOpenShiftMultitenantNetworkPlugin(pluginName), - registry: NewRegistry(osClient, kClient), + registry: newRegistry(osClient, kClient), localIP: selfIP, hostName: hostname, vnids: newVnidMap(), @@ -80,7 +80,7 @@ func (node *OsdnNode) Start() error { return fmt.Errorf("Failed to get network information: %v", err) } - nodeIPTables := NewNodeIPTables(ni.ClusterNetwork.String(), node.iptablesSyncPeriod) + nodeIPTables := newNodeIPTables(ni.ClusterNetwork.String(), node.iptablesSyncPeriod) if err := nodeIPTables.Setup(); err != nil { return fmt.Errorf("Failed to set up iptables: %v", err) } @@ -102,7 +102,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) diff --git a/plugins/osdn/node_iptables.go b/plugins/osdn/node_iptables.go index 6d1479a..deb4c99 100644 --- a/plugins/osdn/node_iptables.go +++ b/plugins/osdn/node_iptables.go @@ -27,7 +27,7 @@ type NodeIPTables struct { mu sync.Mutex // Protects concurrent access to syncIPTableRules() } -func NewNodeIPTables(clusterNetworkCIDR string, syncPeriod time.Duration) *NodeIPTables { +func newNodeIPTables(clusterNetworkCIDR string, syncPeriod time.Duration) *NodeIPTables { return &NodeIPTables{ ipt: iptables.New(kexec.New(), utildbus.New(), iptables.ProtocolIpv4), clusterNetworkCIDR: clusterNetworkCIDR, diff --git a/plugins/osdn/proxy.go b/plugins/osdn/proxy.go index a4fa68d..812a46b 100644 --- a/plugins/osdn/proxy.go +++ b/plugins/osdn/proxy.go @@ -35,7 +35,7 @@ func NewProxyPlugin(pluginName string, osClient *osclient.Client, kClient *kclie } 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 df4f8b6..3e30986 100644 --- a/plugins/osdn/registry.go +++ b/plugins/osdn/registry.go @@ -46,7 +46,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, @@ -167,7 +167,7 @@ func (registry *Registry) CreateClusterNetwork(ni *NetworkInfo) error { return err } -func ValidateClusterNetwork(network string, hostSubnetLength int, serviceNetwork string, pluginName string) (*NetworkInfo, error) { +func validateClusterNetwork(network string, hostSubnetLength int, serviceNetwork string, pluginName string) (*NetworkInfo, error) { _, cn, err := net.ParseCIDR(network) if err != nil { return nil, fmt.Errorf("Failed to parse ClusterNetwork CIDR %s: %v", network, err) @@ -201,7 +201,7 @@ func (registry *Registry) GetNetworkInfo() (*NetworkInfo, error) { return nil, err } - registry.NetworkInfo, err = ValidateClusterNetwork(cn.Network, cn.HostSubnetLength, cn.ServiceNetwork, cn.PluginName) + registry.NetworkInfo, err = validateClusterNetwork(cn.Network, cn.HostSubnetLength, cn.ServiceNetwork, cn.PluginName) if err != nil { return nil, err } diff --git a/plugins/osdn/subnets.go b/plugins/osdn/subnets.go index b8d0e72..10e818c 100644 --- a/plugins/osdn/subnets.go +++ b/plugins/osdn/subnets.go @@ -31,7 +31,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)) } } @@ -62,7 +62,7 @@ func (master *OsdnMaster) addNode(nodeName string, nodeIP string) error { if err != nil { return fmt.Errorf("Error updating subnet %s for node %s: %v", sub.Subnet, nodeName, err) } - log.Infof("Updated HostSubnet %s", HostSubnetToString(sub)) + log.Infof("Updated HostSubnet %s", hostSubnetToString(sub)) return nil } } @@ -78,7 +78,7 @@ func (master *OsdnMaster) addNode(nodeName string, nodeIP string) error { master.subnetAllocator.ReleaseNetwork(sn) return fmt.Errorf("Error creating subnet %s for node %s: %v", sn.String(), nodeName, err) } - log.Infof("Created HostSubnet %s", HostSubnetToString(sub)) + log.Infof("Created HostSubnet %s", hostSubnetToString(sub)) return nil } @@ -97,10 +97,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{} @@ -115,7 +123,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 @@ -192,7 +200,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 b4c0a7a..3075dd3 100644 --- a/plugins/osdn/vnids.go +++ b/plugins/osdn/vnids.go @@ -283,7 +283,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 }