Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

Commit

Permalink
Unexport names that don't need to be exported.
Browse files Browse the repository at this point in the history
Also, move getNodeIP() from common.go to subnets.go since it's only
used from there.
  • Loading branch information
danwinship committed Jun 21, 2016
1 parent 3395f29 commit e398de3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
14 changes: 2 additions & 12 deletions plugins/osdn/common.go
Expand Up @@ -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://<containerID>
if parts := strings.Split(pod.Status.ContainerStatuses[0].ContainerID, "://"); len(parts) > 1 {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions plugins/osdn/controller.go
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions plugins/osdn/master.go
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/osdn/node.go
Expand Up @@ -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(),
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/osdn/node_iptables.go
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion plugins/osdn/proxy.go
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/osdn/registry.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 14 additions & 6 deletions plugins/osdn/subnets.go
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}

Expand All @@ -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{}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/osdn/vnids.go
Expand Up @@ -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
}
Expand Down

0 comments on commit e398de3

Please sign in to comment.