forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify the status of required routes and IP configuration of gateway …
…periodically Add checks to the routeClient. The required routes will be added back if they were deleted unexpectedly. Add IP configuration check of the gateway to the agent. An integration test is added to verify that the route will be added back correctly. Fixes antrea-io#627
- Loading branch information
Showing
8 changed files
with
246 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2021 Antrea Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
type Route struct { | ||
peerPodCIDR *net.IPNet | ||
peerPodGW net.IP | ||
} | ||
|
||
func getGatewayRoutes(data *TestData, isIPv6 bool) (routes []Route, err error) { | ||
antreaGWName, err := data.GetGatewayInterfaceName(antreaNamespace) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var cmd []string | ||
nodeName := nodeName(0) | ||
antreaPodName, err := data.getAntreaPodOnNode(nodeName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !isIPv6 { | ||
cmd = []string{"ip", "route", "list", "dev", antreaGWName} | ||
} else { | ||
cmd = []string{"ip", "-6", "route", "list", "dev", antreaGWName} | ||
} | ||
stdout, stderr, err := data.runCommandFromPod(antreaNamespace, antreaPodName, agentContainerName, cmd) | ||
if err != nil { | ||
return nil, fmt.Errorf("error when running ip command in Pod '%s': %v - stdout: %s - stderr: %s", antreaPodName, err, stdout, stderr) | ||
} | ||
|
||
re := regexp.MustCompile(`([^\s]+) via ([^\s]+)`) | ||
for _, line := range strings.Split(stdout, "\n") { | ||
var err error | ||
matches := re.FindStringSubmatch(line) | ||
if len(matches) == 0 { | ||
continue | ||
} | ||
route := Route{} | ||
if _, route.peerPodCIDR, err = net.ParseCIDR(matches[1]); err != nil { | ||
return nil, fmt.Errorf("%s is not a valid net CIDR", matches[1]) | ||
} | ||
if route.peerPodGW = net.ParseIP(matches[2]); route.peerPodGW == nil { | ||
return nil, fmt.Errorf("%s is not a valid IP", matches[2]) | ||
} | ||
routes = append(routes, route) | ||
} | ||
return routes, nil | ||
} | ||
|
||
func deleteGatewayRoute(route *Route, data *TestData, isIPv6 bool) error { | ||
var cmd []string | ||
nodeName := nodeName(0) | ||
antreaPodName, err := data.getAntreaPodOnNode(nodeName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !isIPv6 { | ||
cmd = []string{"ip", "route", "del", route.peerPodCIDR.String()} | ||
} else { | ||
cmd = []string{"ip", "-6", "route", "del", route.peerPodCIDR.String()} | ||
} | ||
_, _, err = data.runCommandFromPod(antreaNamespace, antreaPodName, agentContainerName, cmd) | ||
if err != nil { | ||
return fmt.Errorf("error when running ip command on Node '%s': %v", nodeName, err) | ||
} | ||
return nil | ||
} | ||
|
||
func addGatewayRoute(route *Route, data *TestData, isIPv6 bool) error { | ||
antreaGWName, err := data.GetGatewayInterfaceName(antreaNamespace) | ||
if err != nil { | ||
return err | ||
} | ||
var cmd []string | ||
nodeName := nodeName(0) | ||
antreaPodName, err := data.getAntreaPodOnNode(nodeName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !isIPv6 { | ||
cmd = []string{"ip", "route", "add", route.peerPodCIDR.String(), "via", route.peerPodGW.String(), "dev", antreaGWName, "onlink"} | ||
} else { | ||
cmd = []string{"ip", "-6", "route", "add", route.peerPodCIDR.String(), "via", route.peerPodGW.String(), "dev", antreaGWName, "onlink"} | ||
} | ||
_, _, err = data.runCommandFromPod(antreaNamespace, antreaPodName, agentContainerName, cmd) | ||
if err != nil { | ||
return fmt.Errorf("error when running ip command on Node '%s': %v", nodeName, err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.