From baf7e52c5b20d8dc191c4df9b014bda3d0764dc0 Mon Sep 17 00:00:00 2001
From: Tobias Klauser <tobias@cilium.io>
Date: Tue, 12 Sep 2023 10:35:22 +0200
Subject: [PATCH] connectivity: convert conn-disrupt-dispatch-interval to
 duration

It's more commonplace to use DurationVar to specify duration CLI flags
and gives users more flexibility.

Example usage:

    $ cilium connectivity test --conn-disrupt-dispatch-interval 20ms

Fixes: 67b8025b4d43 ("connectivity: Expose test-conn-disrupt dispatch period")

Signed-off-by: Tobias Klauser <tobias@cilium.io>
---
 connectivity/check/check.go      | 2 +-
 connectivity/check/deployment.go | 2 +-
 internal/cli/cmd/connectivity.go | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/connectivity/check/check.go b/connectivity/check/check.go
index 1c214c9769..ac80724d11 100644
--- a/connectivity/check/check.go
+++ b/connectivity/check/check.go
@@ -68,7 +68,7 @@ type Parameters struct {
 	ConnDisruptTestSetup          bool
 	ConnDisruptTestRestartsPath   string
 	ConnDisruptTestXfrmErrorsPath string
-	ConnDisruptDispatchInterval   uint
+	ConnDisruptDispatchInterval   time.Duration
 	FlushCT                       bool
 	SecondaryNetworkIface         string
 
diff --git a/connectivity/check/deployment.go b/connectivity/check/deployment.go
index b8daa697cd..21ea072660 100644
--- a/connectivity/check/deployment.go
+++ b/connectivity/check/deployment.go
@@ -672,7 +672,7 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
 				Port:     8000,
 				Command: []string{
 					"tcd-client",
-					"--dispatch-interval", strconv.Itoa(int(ct.params.ConnDisruptDispatchInterval)),
+					"--dispatch-interval", strconv.Itoa(int(ct.params.ConnDisruptDispatchInterval.Milliseconds())),
 					fmt.Sprintf("test-conn-disrupt.%s.svc.cluster.local.:8000", ct.params.TestNamespace),
 				},
 				ReadinessProbe: readinessProbe,
diff --git a/internal/cli/cmd/connectivity.go b/internal/cli/cmd/connectivity.go
index c3788385f1..9eba5bff23 100644
--- a/internal/cli/cmd/connectivity.go
+++ b/internal/cli/cmd/connectivity.go
@@ -178,7 +178,7 @@ func newCmdConnectivityTest(hooks Hooks) *cobra.Command {
 	cmd.Flags().BoolVar(&params.ConnDisruptTestSetup, "conn-disrupt-test-setup", false, "Set up conn disrupt test dependencies")
 	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().UintVar(&params.ConnDisruptDispatchInterval, "conn-disrupt-dispatch-interval (ms)", 10, "TCP packet dispatch interval in ms")
+	cmd.Flags().DurationVar(&params.ConnDisruptDispatchInterval, "conn-disrupt-dispatch-interval", 10*time.Millisecond, "TCP packet dispatch interval")
 	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)")