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 May 17, 2016
1 parent de8f272 commit a41ffea
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
13 changes: 2 additions & 11 deletions plugins/osdn/common.go
Expand Up @@ -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"
Expand All @@ -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://<containerID>
if parts := strings.Split(pod.Status.ContainerStatuses[0].ContainerID, "://"); len(parts) > 1 {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions plugins/osdn/controller.go
Expand Up @@ -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)
Expand All @@ -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)
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
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
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/osdn/node.go
Expand Up @@ -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(),
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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"}},
Expand Down
2 changes: 1 addition & 1 deletion plugins/osdn/proxy.go
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/osdn/registry.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 14 additions & 6 deletions plugins/osdn/subnets.go
Expand Up @@ -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))
}
}

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

0 comments on commit a41ffea

Please sign in to comment.