Skip to content

Commit

Permalink
Retry default gw retrieval on error (#328)
Browse files Browse the repository at this point in the history
Sometimes it takes some time for DHCP to assign default gw, so
the default gw ping probe fails, here we add a 30 seconds timeout
with a 1 second interval.

Signed-off-by: Quique Llorente <[email protected]>
  • Loading branch information
qinqon authored and kubevirt-bot committed Jan 9, 2020
1 parent cd18d99 commit 2f82225
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/helper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (

const nmstateCommand = "nmstatectl"
const vlanFilteringCommand = "vlan-filtering"
const defaultGwRetrieveTimeout = 120
const defaultGwProbeTimeout = 120
const apiServerProbeTimeout = 120

Expand Down Expand Up @@ -223,23 +224,26 @@ func checkApiServerConnectivity(timeout time.Duration) error {
}

func defaultGw() (string, error) {
observedStateRaw, err := show()
if err != nil {
return "", fmt.Errorf("error running nmstatectl show: %v", err)
}
defaultGw := ""
return defaultGw, wait.PollImmediate(1*time.Second, defaultGwRetrieveTimeout, func() (bool, error) {
observedStateRaw, err := show()
if err != nil {
return false, fmt.Errorf("error running nmstatectl show: %v", err)
}

currentState, err := yaml.YAMLToJSON([]byte(observedStateRaw))
if err != nil {
return "", fmt.Errorf("Impossible to convert current state to JSON: %v", err)
}
currentState, err := yaml.YAMLToJSON([]byte(observedStateRaw))
if err != nil {
return false, fmt.Errorf("Impossible to convert current state to JSON: %v", err)
}

defaultGw := gjson.ParseBytes([]byte(currentState)).
Get("routes.running.#(destination==\"0.0.0.0/0\").next-hop-address").String()
if defaultGw == "" {
return "", fmt.Errorf("Impossible to retrieve default gw, state: %s", string(observedStateRaw))
}
defaultGw = gjson.ParseBytes([]byte(currentState)).
Get("routes.running.#(destination==\"0.0.0.0/0\").next-hop-address").String()
if defaultGw == "" {
return false, fmt.Errorf("Impossible to retrieve default gw, state: %s", string(observedStateRaw))
}

return defaultGw, nil
return true, nil
})
}

func ApplyDesiredState(desiredState nmstatev1alpha1.State) (string, error) {
Expand Down

0 comments on commit 2f82225

Please sign in to comment.