Skip to content

Commit 37c85d2

Browse files
committed
Add timeout to k8sClient Create
1 parent 801d2f3 commit 37c85d2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

tests/cel/clientsettingspolicy_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1111

1212
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
13+
"github.com/nginx/nginx-gateway-fabric/v2/tests/framework"
1314
)
1415

1516
func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
@@ -147,8 +148,10 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
147148
},
148149
Spec: policySpec,
149150
}
150-
151-
err := k8sClient.Create(context.Background(), clientSettingsPolicy)
151+
timeoutConfig := framework.DefaultTimeoutConfig()
152+
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.KubernetesClientTimeout)
153+
err := k8sClient.Create(ctx, clientSettingsPolicy)
154+
defer cancel()
152155

153156
// Clean up after test
154157
defer func() {

tests/framework/timeout.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type TimeoutConfig struct {
3535

3636
// TestForTrafficTimeout represents the maximum time for NGF to test for passing or failing traffic.
3737
TestForTrafficTimeout time.Duration
38+
39+
// KubernetesClientTimeout represents the maximum time for Kubernetes client operations.
40+
KubernetesClientTimeout time.Duration
3841
}
3942

4043
// DefaultTimeoutConfig populates a TimeoutConfig with the default values.
@@ -51,5 +54,6 @@ func DefaultTimeoutConfig() TimeoutConfig {
5154
GetLeaderLeaseTimeout: 60 * time.Second,
5255
GetStatusTimeout: 60 * time.Second,
5356
TestForTrafficTimeout: 60 * time.Second,
57+
KubernetesClientTimeout: 10 * time.Second,
5458
}
5559
}

0 commit comments

Comments
 (0)