Skip to content

Commit f860bc3

Browse files
Add hostmode to check interface and fix formatter
- Adds a hostmode check function to the check interface - Remove host-network redundant arguments - Work to debug iptables rule detection failure
1 parent 2c4a420 commit f860bc3

13 files changed

Lines changed: 55 additions & 45 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2727
curl \
2828
iperf3 \
2929
iproute2 \
30+
iptables \
3031
netcat-openbsd \
3132
tcpdump \
3233
procps \

cmd/netdebug/commands/run.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func runTests(cmd *cobra.Command, args []string) error {
146146

147147
if overlay {
148148
fmt.Println("\n--- Overlay Network Tests ---")
149-
overlayChecks := filterOutCheck(checksWithoutBandwidth, "ports")
149+
overlayChecks := filterHostNetworkOnlyChecks(checksWithoutBandwidth)
150150
events, err := runStandardTests(ctx, coord, overlayTargets, overlayPods, overlayChecks, timeout, debug, types.NetworkTypeOverlay)
151151
if err != nil {
152152
fmt.Printf("Warning: overlay network tests failed: %v\n", err)
@@ -284,12 +284,14 @@ func runBandwidthTests(ctx context.Context, coord *coordinator.Coordinator, targ
284284
return allEvents, nil
285285
}
286286

287-
func filterOutCheck(checks []string, checkToRemove string) []string {
287+
func filterHostNetworkOnlyChecks(checks []string) []string {
288288
var filtered []string
289-
for _, check := range checks {
290-
if check != checkToRemove {
291-
filtered = append(filtered, check)
289+
for _, name := range checks {
290+
check := checkspkg.DefaultRegistry.Get(name)
291+
if check != nil && check.HostNetworkOnly() {
292+
continue
292293
}
294+
filtered = append(filtered, name)
293295
}
294296
return filtered
295297
}

internal/manifests/daemonset-host.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ spec:
5353
fieldRef:
5454
fieldPath: status.hostIP
5555
securityContext:
56+
runAsUser: 0
5657
privileged: true
5758
capabilities:
5859
add:

pkg/agent/runner.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func RunTests(ctx context.Context, config *types.Config, self *SelfInfo) error {
2626
wg.Add(1)
2727
go func(checkName string) {
2828
defer wg.Done()
29-
if isLocalOnlyCheck(checkName) {
29+
check := checks.DefaultRegistry.Get(checkName)
30+
if check != nil && check.IsLocal() {
3031
runSingleCheck(ctx, checkName, "localhost", self.NodeName, config, self)
3132
} else {
3233
runCheckAgainstAllTargets(ctx, checkName, targets, config, self)
@@ -63,15 +64,6 @@ func filterTargets(targets []types.TargetNode, selfNodeName string) []types.Targ
6364
return filtered
6465
}
6566

66-
func isLocalOnlyCheck(checkName string) bool {
67-
switch checkName {
68-
case "hostconfig", "conntrack", "iptables":
69-
return true
70-
default:
71-
return false
72-
}
73-
}
74-
7567
func runCheckAgainstAllTargets(ctx context.Context, checkName string, targets []types.TargetNode, config *types.Config, self *SelfInfo) {
7668
for _, target := range targets {
7769
if checkName == "ports" {

pkg/checks/bandwidth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (c *BandwidthCheck) IsLocal() bool {
101101
return false
102102
}
103103

104+
func (c *BandwidthCheck) HostNetworkOnly() bool {
105+
return false
106+
}
107+
104108
func (c *BandwidthCheck) AlwaysShow() bool {
105109
return true
106110
}

pkg/checks/check.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ type Check interface {
2626
// These checks won't display a Target column in table output.
2727
IsLocal() bool
2828

29+
// HostNetworkOnly returns true if this check requires the host network namespace
30+
// and should only run on hostNetwork pods. Checks that inspect host-level networking
31+
// (iptables, conntrack, ports, etc.) should return true.
32+
HostNetworkOnly() bool
33+
2934
// AlwaysShow returns true if this check should always be displayed in output,
3035
// even when passing. This is useful for checks like bandwidth where the
3136
// result value is always interesting regardless of pass/fail status.

pkg/checks/conntrack.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ func (c *ConntrackCheck) IsLocal() bool {
122122
return true
123123
}
124124

125+
func (c *ConntrackCheck) HostNetworkOnly() bool {
126+
return true
127+
}
128+
125129
func (c *ConntrackCheck) AlwaysShow() bool {
126130
return false
127131
}

pkg/checks/dns.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func (c *DNSCheck) IsLocal() bool {
8181
return false
8282
}
8383

84+
func (c *DNSCheck) HostNetworkOnly() bool {
85+
return false
86+
}
87+
8488
func (c *DNSCheck) AlwaysShow() bool {
8589
return false
8690
}

pkg/checks/hostconfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func (c *HostConfigCheck) IsLocal() bool {
146146
return true
147147
}
148148

149+
func (c *HostConfigCheck) HostNetworkOnly() bool {
150+
return true
151+
}
152+
149153
func (c *HostConfigCheck) AlwaysShow() bool {
150154
return true
151155
}

pkg/checks/iptables.go

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ func (c *IptablesCheck) Run(ctx context.Context, target string) (*types.TestResu
4141
details.LegacyRuleCount, details.NftableRuleCount))
4242
}
4343

44-
backend, err := c.detectActiveBackend(ctx)
45-
if err == nil && backend != "" {
46-
issues = append(issues, fmt.Sprintf("detected active backend: %s", backend))
47-
}
48-
4944
if len(issues) > 0 && details.DuplicateRules > 0 {
5045
result.Status = types.StatusFail
5146
result.Error = "iptables configuration conflict detected"
@@ -80,24 +75,11 @@ func (c *IptablesCheck) countIptablesRules(ctx context.Context, binary string) (
8075
return count, nil
8176
}
8277

83-
func (c *IptablesCheck) detectActiveBackend(ctx context.Context) (string, error) {
84-
cmd := exec.CommandContext(ctx, "iptables", "--version")
85-
output, err := cmd.CombinedOutput()
86-
if err != nil {
87-
return "", err
88-
}
89-
90-
versionStr := strings.ToLower(string(output))
91-
if strings.Contains(versionStr, "nf_tables") {
92-
return "nftables", nil
93-
} else if strings.Contains(versionStr, "legacy") {
94-
return "legacy", nil
95-
}
96-
97-
return "unknown", nil
78+
func (c *IptablesCheck) IsLocal() bool {
79+
return true
9880
}
9981

100-
func (c *IptablesCheck) IsLocal() bool {
82+
func (c *IptablesCheck) HostNetworkOnly() bool {
10183
return true
10284
}
10385

@@ -125,18 +107,17 @@ func (c *IptablesCheck) FormatSummary(details interface{}, debug bool) string {
125107
return ""
126108
}
127109

128-
// Get issues if present
129-
issuesRaw, hasIssues := iptablesMap["issues"]
130-
if hasIssues {
131-
if issues, ok := issuesRaw.([]interface{}); ok && len(issues) > 0 {
132-
return fmt.Sprintf("%d issues", len(issues))
133-
}
134-
}
135-
136110
legacyCount, _ := iptablesMap["legacy_rule_count"].(float64)
137111
nftCount, _ := iptablesMap["nftable_rule_count"].(float64)
138112

139113
summary := fmt.Sprintf("%.0f legacy, %.0f nftables rules", legacyCount, nftCount)
114+
115+
if issuesRaw, ok := iptablesMap["issues"]; ok {
116+
if issues, ok := issuesRaw.([]interface{}); ok && len(issues) > 0 {
117+
summary += fmt.Sprintf(" | %d issues", len(issues))
118+
}
119+
}
120+
140121
if debug {
141122
return summary
142123
}

0 commit comments

Comments
 (0)