Skip to content

Commit

Permalink
Add proper error message to alreadySetup
Browse files Browse the repository at this point in the history
The healtFn and alreadySetup functions were returning a boolean
and they should return an error with information in case of
failures.

Fixes: bz#1504011
  • Loading branch information
imcsk8 committed Jan 3, 2018
1 parent dc73150 commit ca87845
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions pkg/network/node/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func waitForOVS(network, addr string) error {
// from the OVS server and then checks healthFn, and one that periodically checks
// healthFn. If healthFn returns false in either of these two cases while the OVS
// server is responsive the node process will terminate.
func runOVSHealthCheck(network, addr string, healthFn func() bool) {
func runOVSHealthCheck(network, addr string, healthFn func() error) {
// this loop holds an open socket connection to OVS until it times out, then
// checks for health
go utilwait.Until(func() {
Expand All @@ -67,8 +67,8 @@ func runOVSHealthCheck(network, addr string, healthFn func() bool) {
glog.V(2).Infof("SDN healthcheck unable to ping OVS server: %v", err)
return false, nil
}
if !healthFn() {
return false, fmt.Errorf("OVS health check failed")
if err := healthFn(); err != nil {
return false, fmt.Errorf("OVS health check failed, %v", err)
}
return true, nil
})
Expand All @@ -92,7 +92,7 @@ func runOVSHealthCheck(network, addr string, healthFn func() bool) {
glog.V(2).Infof("SDN healthcheck unable to ping OVS server: %v", err)
return
}
if !healthFn() {
if err := healthFn(); err != nil {
glog.Fatalf("SDN healthcheck detected unhealthy OVS server, restarting: %v", err)
}
glog.V(4).Infof("SDN healthcheck succeeded")
Expand Down
23 changes: 12 additions & 11 deletions pkg/network/node/sdn_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package node

import (
"errors"
"fmt"
"net"
"time"
Expand All @@ -20,17 +21,17 @@ import (
"github.com/vishvananda/netlink"
)

func (plugin *OsdnNode) alreadySetUp(localSubnetGatewayCIDR string, clusterNetworkCIDR []string) bool {
func (plugin *OsdnNode) alreadySetUp(localSubnetGatewayCIDR string, clusterNetworkCIDR []string) error {
var found bool

l, err := netlink.LinkByName(Tun0)
if err != nil {
return false
return err
}

addrs, err := netlink.AddrList(l, netlink.FAMILY_V4)
if err != nil {
return false
return err
}
found = false
for _, addr := range addrs {
Expand All @@ -40,12 +41,12 @@ func (plugin *OsdnNode) alreadySetUp(localSubnetGatewayCIDR string, clusterNetwo
}
}
if !found {
return false
return errors.New("Local subnet gateway CIDR not found")
}

routes, err := netlink.RouteList(l, netlink.FAMILY_V4)
if err != nil {
return false
return err
}
for _, clusterCIDR := range clusterNetworkCIDR {
found = false
Expand All @@ -56,15 +57,15 @@ func (plugin *OsdnNode) alreadySetUp(localSubnetGatewayCIDR string, clusterNetwo
}
}
if !found {
return false
return errors.New("Cluster CIDR not found")
}
}

if !plugin.oc.AlreadySetUp() {
return false
return errors.New("Plugin is not setup")
}

return true
return nil
}

func deleteLocalSubnetRoute(device, localSubnetCIDR string) {
Expand Down Expand Up @@ -133,8 +134,8 @@ func (plugin *OsdnNode) SetupSDN() (bool, error) {
}

var changed bool
if plugin.alreadySetUp(gwCIDR, clusterNetworkCIDRs) {
glog.V(5).Infof("[SDN setup] no SDN setup required")
if err := plugin.alreadySetUp(gwCIDR, clusterNetworkCIDRs); err == nil {
glog.V(5).Infof("[SDN setup] no SDN setup required: %v", err)
} else {
glog.Infof("[SDN setup] full SDN setup required")
if err := plugin.setup(clusterNetworkCIDRs, localSubnetCIDR, localSubnetGateway, gwCIDR); err != nil {
Expand All @@ -145,7 +146,7 @@ func (plugin *OsdnNode) SetupSDN() (bool, error) {

// TODO: make it possible to safely reestablish node configuration after restart
// If OVS goes down and fails the health check, restart the entire process
healthFn := func() bool { return plugin.alreadySetUp(gwCIDR, clusterNetworkCIDRs) }
healthFn := func() error { return plugin.alreadySetUp(gwCIDR, clusterNetworkCIDRs) }
runOVSHealthCheck(ovsDialDefaultNetwork, ovsDialDefaultAddress, healthFn)

return changed, nil
Expand Down

0 comments on commit ca87845

Please sign in to comment.