Skip to content

Commit

Permalink
connectivity test: introduce connectivity test suite timeout flag
Browse files Browse the repository at this point in the history
Currently, the connectivity test suite command doesn't have a timeout.
Its context only gets cancelled due to interrupt of SIGTERM signal.

For most connectivity test scenarios and actions, this isn't a problem
as they have individual fine-grained timeouts (e.g. request timeout).

But there are test scenarios (e.g. `health ` - `Cilium Health Probe`)
that might run infinitely on failiure (e.g. if a Cilium Agent Pod no
longer is available).

Therefore, this commit introduces a new flag `--timeout` that provides
the possibility to configure an overall timeout for the connectivity
test suite. It defaults to `0` - meaning no timeout by default (current
behaviour).

Signed-off-by: Marco Hofstetter <[email protected]>
  • Loading branch information
mhofstetter committed Dec 4, 2023
1 parent 14592cb commit aad0c99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions connectivity/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type Parameters struct {

ExternalTargetCANamespace string
ExternalTargetCAName string

Timeout time.Duration
}

type podCIDRs struct {
Expand Down
7 changes: 6 additions & 1 deletion defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

package defaults

import "time"
import (
"time"
)

const (
// renovate: datasource=github-releases depName=cilium/cilium
Expand Down Expand Up @@ -135,6 +137,9 @@ const (
// ClustermeshMaxConnectedClusters is the default number of the maximum
// number of clusters that should be allowed to connect to the Clustermesh.
ClustermeshMaxConnectedClusters = 255

// Default timeout for Connectivity Test Suite (disabled by default)
ConnectivityTestSuiteTimeout = 0 * time.Minute
)

var (
Expand Down
13 changes: 11 additions & 2 deletions internal/cli/cmd/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var params = check.Parameters{
Writer: os.Stdout,
},
}

var tests []string

func newCmdConnectivityTest(hooks Hooks) *cobra.Command {
Expand Down Expand Up @@ -76,11 +77,17 @@ func newCmdConnectivityTest(hooks Hooks) *cobra.Command {
return err
}

ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM)

if params.Timeout > 0 {
timeoutCtx, cancelFunc := context.WithTimeoutCause(ctx, params.Timeout, fmt.Errorf("connectivity test suite timeout (%s) reached", params.Timeout))
defer cancelFunc()
ctx = timeoutCtx
}

go func() {
<-ctx.Done()
cc.Log("Interrupt received, cancelling tests...")
cc.Logf("Cancellation request (%s) received, cancelling tests...", context.Cause(ctx))
}()

done := make(chan struct{})
Expand Down Expand Up @@ -187,6 +194,8 @@ func newCmdConnectivityTest(hooks Hooks) *cobra.Command {
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)")

cmd.Flags().DurationVar(&params.Timeout, "timeout", defaults.ConnectivityTestSuiteTimeout, "Maximum time to allow the connectivity test suite to take")

hooks.AddConnectivityTestFlags(cmd.Flags())

return cmd
Expand Down

0 comments on commit aad0c99

Please sign in to comment.