Skip to content

Commit

Permalink
connectivity: Add flag --expected-drop-reasons
Browse files Browse the repository at this point in the history
This new flag can be used to customize the set of expected reasons for
packet drops, for the new test that ensure we don't have any unexpected
packet drops.

Signed-off-by: Paul Chaignon <[email protected]>
  • Loading branch information
pchaigno committed Dec 6, 2023
1 parent 24d56a5 commit c314595
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
7 changes: 5 additions & 2 deletions connectivity/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ type Parameters struct {
ConnDisruptTestRestartsPath string
ConnDisruptTestXfrmErrorsPath string
ConnDisruptDispatchInterval time.Duration
FlushCT bool
SecondaryNetworkIface string

ExpectedDropReasons []string

FlushCT bool
SecondaryNetworkIface string

K8sVersion string
HelmChartDirectory string
Expand Down
2 changes: 1 addition & 1 deletion connectivity/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func Run(ctx context.Context, ct *check.ConnectivityTest, addExtraTests func(*ch
}
}

ct.NewTest("no-unexpected-packet-drops").WithScenarios(tests.NoUnexpectedPacketDrops())
ct.NewTest("no-unexpected-packet-drops").WithScenarios(tests.NoUnexpectedPacketDrops(ct.Params().ExpectedDropReasons))

// Run all tests without any policies in place.
noPoliciesScenarios := []check.Scenario{
Expand Down
19 changes: 15 additions & 4 deletions connectivity/tests/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tests

import (
"context"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -76,21 +77,31 @@ func (n *noErrorsInLogs) Run(ctx context.Context, t *check.Test) {

// NoUnexpectedPacketDrops checks whether there were no drops due to expected
// packet drops.
func NoUnexpectedPacketDrops() check.Scenario {
return &noUnexpectedPacketDrops{}
func NoUnexpectedPacketDrops(expectedDrops []string) check.Scenario {
return &noUnexpectedPacketDrops{expectedDrops}
}

type noUnexpectedPacketDrops struct{}
type noUnexpectedPacketDrops struct{

Check failure on line 84 in connectivity/tests/errors.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofmt`-ed with `-s` (gofmt)
expectedDrops []string
}

func (n *noUnexpectedPacketDrops) Name() string {
return "no-unexpected-packet-drops"
}

func (n *noUnexpectedPacketDrops) Run(ctx context.Context, t *check.Test) {
ct := t.Context()

filter := ""
if len(n.expectedDrops) > 0 {
filter = fmt.Sprintf("%q", n.expectedDrops[0])
for _, reason := range n.expectedDrops[1:] {
filter = fmt.Sprintf("%s, %q", filter, reason)
}
}
cmd := []string{
"/bin/sh", "-c",
"cilium metrics list -o json | jq '.[] | select((.name == \"cilium_drop_count_total\") and (.labels.reason | IN(\"Policy denied\", \"Policy denied by denylist\", \"Unsupported L3 protocol\") | not))'",
fmt.Sprintf("cilium metrics list -o json | jq '.[] | select((.name == \"cilium_drop_count_total\") and (.labels.reason | IN(%s) | not))'", filter),
}

for _, pod := range ct.CiliumPods() {
Expand Down
6 changes: 6 additions & 0 deletions defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@ var (
"authentication.mutual.spire.install.agent.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator=NotIn",
"authentication.mutual.spire.install.agent.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].values[0]=true",
}

ExpectedDropReasons = []string{
"Policy denied",
"Policy denied by denylist",
"Unsupported L3 protocol",
}
)
3 changes: 3 additions & 0 deletions internal/cli/cmd/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func newCmdConnectivityTest(hooks Hooks) *cobra.Command {
cmd.Flags().StringVar(&params.ConnDisruptTestRestartsPath, "conn-disrupt-test-restarts-path", "/tmp/cilium-conn-disrupt-restarts", "Conn disrupt test temporary result file (used internally)")
cmd.Flags().StringVar(&params.ConnDisruptTestXfrmErrorsPath, "conn-disrupt-test-xfrm-errors-path", "/tmp/cilium-conn-disrupt-xfrm-errors", "Conn disrupt test temporary result file (used internally)")
cmd.Flags().DurationVar(&params.ConnDisruptDispatchInterval, "conn-disrupt-dispatch-interval", 10*time.Millisecond, "TCP packet dispatch interval")

cmd.Flags().StringSliceVar(&params.ExpectedDropReasons, "expected-drop-reasons", defaults.ExpectedDropReasons, fmt.Sprintf("List of expected drop reasons"))

Check failure on line 194 in internal/cli/cmd/connectivity.go

View workflow job for this annotation

GitHub Actions / build

S1039: unnecessary use of fmt.Sprintf (gosimple)

cmd.Flags().BoolVar(&params.FlushCT, "flush-ct", false, "Flush conntrack of Cilium on each node")
cmd.Flags().MarkHidden("flush-ct")
cmd.Flags().StringVar(&params.SecondaryNetworkIface, "secondary-network-iface", "", "Secondary network iface name (e.g., to test NodePort BPF on multiple networks)")
Expand Down

0 comments on commit c314595

Please sign in to comment.