-
Notifications
You must be signed in to change notification settings - Fork 429
Add IP rules, routes and interface configs to support bundle #7543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,17 @@ | |
| package support | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "net" | ||
| "path" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "antrea.io/antrea/pkg/agent/util/iptables" | ||
| "antrea.io/antrea/pkg/agent/util/sysctl" | ||
| "antrea.io/antrea/pkg/util/logdir" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| func (d *agentDumper) DumpLog(basedir string) error { | ||
|
|
@@ -44,6 +48,9 @@ func (d *agentDumper) DumpHostNetworkInfo(basedir string) error { | |
| if err := d.dumpIPToolInfo(basedir); err != nil { | ||
| return err | ||
| } | ||
| if err := d.dumpInterfaceConfigs(basedir); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -60,21 +67,61 @@ func (d *agentDumper) dumpIPTables(basedir string) error { | |
| } | ||
|
|
||
| func (d *agentDumper) dumpIPToolInfo(basedir string) error { | ||
| dump := func(name string) error { | ||
| output, err := d.executor.Command("ip", name).CombinedOutput() | ||
| dump := func(args ...string) error { | ||
| output, err := d.executor.Command("ip", args...).CombinedOutput() | ||
| if err != nil { | ||
| return fmt.Errorf("error when dumping %s: %w", name, err) | ||
| return fmt.Errorf("error when dumping %s: %w", strings.Join(args, " "), err) | ||
| } | ||
| return writeFile(d.fs, filepath.Join(basedir, name), name, output) | ||
| return writeFile(d.fs, filepath.Join(basedir, args[0]), args[0], output) | ||
| } | ||
| commands := [][]string{ | ||
| {"link"}, | ||
| {"address"}, | ||
| {"rule", "show"}, | ||
| {"route", "show", "table", "all"}, | ||
| } | ||
| for _, item := range []string{"route", "link", "address"} { | ||
| if err := dump(item); err != nil { | ||
| for _, cmd := range commands { | ||
| if err := dump(cmd...); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (d *agentDumper) dumpInterfaceConfigs(basedir string) error { | ||
| interfaces, err := net.Interfaces() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want to consider all interfaces. There can be a lot of them because there is one per local Pod.
I also think this should be best effort, if we fail to get the information (maybe because of a permission issue), let's log the error + write the error to the support bundle, but let's not fail the bundle operation.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be useful to fall back to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think this is a possible error scenario |
||
| if err != nil { | ||
| return fmt.Errorf("error getting network interfaces: %w", err) | ||
| } | ||
| hostGateway := d.aq.GetNodeConfig().GatewayConfig.Name | ||
| isRelevantIface := func(ifaceName string) bool { | ||
| return ifaceName == hostGateway || | ||
| ifaceName == "antrea-egress0" || | ||
| ifaceName == "antrea-ingress0" || | ||
| strings.HasPrefix(ifaceName, "antrea-ext.") | ||
| } | ||
|
|
||
| params := []string{"rp_filter", "arp_ignore", "arp_announce"} | ||
| var output bytes.Buffer | ||
| for _, iface := range interfaces { | ||
| if !isRelevantIface(iface.Name) { | ||
| continue | ||
| } | ||
| output.WriteString(iface.Name) | ||
| output.WriteString("\n") | ||
| for _, param := range params { | ||
| value, err := sysctl.GetSysctlNet(fmt.Sprintf("ipv4/conf/%s/%s", iface.Name, param)) | ||
| if err != nil { | ||
| klog.ErrorS(err, "Failed to get sysctl value", "interface", iface.Name, "param", param) | ||
| continue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should log the error here, even if we don't return it |
||
| } | ||
| output.WriteString(fmt.Sprintf("%s=%d\n", param, value)) | ||
| } | ||
| output.WriteString("\n") | ||
| } | ||
| return writeFile(d.fs, filepath.Join(basedir, "interface-config"), "interface-config", output.Bytes()) | ||
| } | ||
|
|
||
| func (d *agentDumper) DumpMemberlist(basedir string) error { | ||
| output, err := d.executor.Command("antctl", "-oyaml", "get", "memberlist").CombinedOutput() | ||
| if err != nil && !strings.Contains(string(output), "memberlist is not enabled") { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a unit test for this function? And ideally for
dumpIPToolInfoas well.