Skip to content

Commit

Permalink
Merge pull request #296 from dcbw/more-hostsubnet-logging
Browse files Browse the repository at this point in the history
Add more HostSubnet logging
  • Loading branch information
Ravi Sankar Penta committed Apr 22, 2016
2 parents 01c2431 + 42142b1 commit ba3087a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions plugins/osdn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type OsdnController struct {
// 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) error {

log.Infof("Starting with configured hostname '%s' (IP '%s')", hostname, selfIP)

if hostname == "" {
output, err := kexec.New().Command("uname", "-n").CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -280,3 +282,7 @@ func GetPodContainerID(pod *kapi.Pod) string {
}
return ""
}

func HostSubnetToString(subnet *osapi.HostSubnet) string {
return fmt.Sprintf("%s [host: '%s'] [ip: '%s'] [subnet: '%s']", subnet.Name, subnet.Host, subnet.HostIP, subnet.Subnet)
}
5 changes: 3 additions & 2 deletions plugins/osdn/ovs/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/openshift/openshift-sdn/pkg/ipcmd"
"github.com/openshift/openshift-sdn/pkg/netutils"
"github.com/openshift/openshift-sdn/pkg/ovs"
"github.com/openshift/openshift-sdn/plugins/osdn"
osapi "github.com/openshift/origin/pkg/sdn/api"

kapi "k8s.io/kubernetes/pkg/api"
Expand Down Expand Up @@ -333,7 +334,7 @@ func (plugin *ovsPlugin) GetName() string {
}

func (plugin *ovsPlugin) AddHostSubnetRules(subnet *osapi.HostSubnet) {
glog.V(5).Infof("AddHostSubnetRules for %v", subnet)
glog.Infof("AddHostSubnetRules for %s", osdn.HostSubnetToString(subnet))
otx := ovs.NewTransaction(BR)

otx.AddFlow("table=1, priority=100, tun_src=%s, actions=goto_table:5", subnet.HostIP)
Expand All @@ -347,7 +348,7 @@ func (plugin *ovsPlugin) AddHostSubnetRules(subnet *osapi.HostSubnet) {
}

func (plugin *ovsPlugin) DeleteHostSubnetRules(subnet *osapi.HostSubnet) {
glog.V(5).Infof("DeleteHostSubnetRules for %v", subnet)
glog.Infof("DeleteHostSubnetRules for %s", osdn.HostSubnetToString(subnet))

otx := ovs.NewTransaction(BR)
otx.DeleteFlows("table=1, tun_src=%s", subnet.HostIP)
Expand Down
5 changes: 2 additions & 3 deletions plugins/osdn/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,15 @@ func (registry *Registry) DeleteSubnet(nodeName string) error {
return registry.oClient.HostSubnets().Delete(nodeName)
}

func (registry *Registry) CreateSubnet(nodeName, nodeIP, subnetCIDR string) error {
func (registry *Registry) CreateSubnet(nodeName, nodeIP, subnetCIDR string) (*osapi.HostSubnet, error) {
hs := &osapi.HostSubnet{
TypeMeta: unversioned.TypeMeta{Kind: "HostSubnet"},
ObjectMeta: kapi.ObjectMeta{Name: nodeName},
Host: nodeName,
HostIP: nodeIP,
Subnet: subnetCIDR,
}
_, err := registry.oClient.HostSubnets().Create(hs)
return err
return registry.oClient.HostSubnets().Create(hs)
}

func (registry *Registry) WatchSubnets(receiver chan<- *HostSubnetEvent) error {
Expand Down
12 changes: 8 additions & 4 deletions plugins/osdn/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func (oc *OsdnController) SubnetStartMaster(clusterNetwork *net.IPNet, hostSubne
if err := oc.validateNode(sub.HostIP); err != nil {
// 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))
}
}

Expand All @@ -44,12 +46,12 @@ func (oc *OsdnController) addNode(nodeName string, nodeIP string) error {
if err != nil {
return fmt.Errorf("Error allocating network for node %s: %v", nodeName, err)
}
err = oc.Registry.CreateSubnet(nodeName, nodeIP, sn.String())
sub, err := oc.Registry.CreateSubnet(nodeName, nodeIP, sn.String())
if err != nil {
return fmt.Errorf("Error writing subnet %v to etcd for node %s: %v", sn, nodeName, err)
}

log.Infof("Created HostSubnet %v for node %s (%s)", sn, nodeName, nodeIP)
log.Infof("Created HostSubnet %s", HostSubnetToString(sub))
return nil
}

Expand All @@ -68,7 +70,7 @@ func (oc *OsdnController) deleteNode(nodeName string) error {
return fmt.Errorf("Error deleting subnet %v for node %q: %v", sub, nodeName, err)
}

log.Infof("Deleted HostSubnet %v for node %s", sub, nodeName)
log.Infof("Deleted HostSubnet %s", HostSubnetToString(sub))
return nil
}

Expand Down Expand Up @@ -118,6 +120,7 @@ func (oc *OsdnController) initSelfSubnet() error {
return fmt.Errorf("Failed to validate own HostSubnet: %v", err)
}

log.Infof("Found local HostSubnet %s", HostSubnetToString(subnet))
oc.localSubnet = subnet
return nil
}
Expand Down Expand Up @@ -155,11 +158,12 @@ func watchNodes(oc *OsdnController) {
continue
}
if nodeErr == nil {
err = oc.Registry.CreateSubnet(ev.Node.Name, nodeIP, sub.Subnet)
_, err := oc.Registry.CreateSubnet(ev.Node.Name, nodeIP, sub.Subnet)
if err != nil {
log.Errorf("Error creating subnet for node %s, ip %s: %v", ev.Node.Name, sub.HostIP, err)
continue
}
log.Infof("Updated HostSubnet %s to HostIP %s", HostSubnetToString(sub), nodeIP)
} else {
log.Errorf("Ignoring creating invalid node %s/%s: %v", ev.Node.Name, nodeIP, nodeErr)
}
Expand Down

0 comments on commit ba3087a

Please sign in to comment.