Skip to content

Commit 0c3a454

Browse files
authored
Merge pull request #1887 from Xunzhuo/gogp-timeout
feat: support configurable timeout for GatewayObservedGenerationBump
2 parents 004eb1b + 849e2ad commit 0c3a454

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

conformance/tests/gateway-modify-listeners.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
5353
require.NoErrorf(t, err, "error getting Gateway: %v", err)
5454

5555
// verify that the implementation is tracking the most recent resource changes
56-
kubernetes.GatewayMustHaveLatestConditions(t, original)
56+
kubernetes.GatewayMustHaveLatestConditions(t, s.TimeoutConfig, original)
5757

5858
all := v1beta1.NamespacesFromAll
5959

@@ -112,7 +112,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
112112
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)
113113

114114
// verify that the implementation continues to keep up to date with the resource changes we've been making
115-
kubernetes.GatewayMustHaveLatestConditions(t, updated)
115+
kubernetes.GatewayMustHaveLatestConditions(t, s.TimeoutConfig, updated)
116116

117117
require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update")
118118
})
@@ -129,7 +129,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
129129
require.NoErrorf(t, err, "error getting Gateway: %v", err)
130130

131131
// verify that the implementation is tracking the most recent resource changes
132-
kubernetes.GatewayMustHaveLatestConditions(t, original)
132+
kubernetes.GatewayMustHaveLatestConditions(t, s.TimeoutConfig, original)
133133

134134
mutate := original.DeepCopy()
135135
require.Equalf(t, 2, len(mutate.Spec.Listeners), "the gateway must have 2 listeners")
@@ -171,7 +171,7 @@ var GatewayModifyListeners = suite.ConformanceTest{
171171
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)
172172

173173
// verify that the implementation continues to keep up to date with the resource changes we've been making
174-
kubernetes.GatewayMustHaveLatestConditions(t, updated)
174+
kubernetes.GatewayMustHaveLatestConditions(t, s.TimeoutConfig, updated)
175175

176176
require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update")
177177
})

conformance/tests/gateway-observed-generation-bump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var GatewayObservedGenerationBump = suite.ConformanceTest{
5454
require.NoErrorf(t, err, "error getting Gateway: %v", err)
5555

5656
// Sanity check
57-
kubernetes.GatewayMustHaveLatestConditions(t, original)
57+
kubernetes.GatewayMustHaveLatestConditions(t, s.TimeoutConfig, original)
5858

5959
all := v1beta1.NamespacesFromAll
6060

@@ -81,7 +81,7 @@ var GatewayObservedGenerationBump = suite.ConformanceTest{
8181
require.NoErrorf(t, err, "error getting Gateway: %v", err)
8282

8383
// Sanity check
84-
kubernetes.GatewayMustHaveLatestConditions(t, updated)
84+
kubernetes.GatewayMustHaveLatestConditions(t, s.TimeoutConfig, updated)
8585

8686
require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update")
8787
})

conformance/utils/config/timeout.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ type TimeoutConfig struct {
7474
// Max value for conformant implementation: None
7575
RequestTimeout time.Duration
7676

77+
// LatestObservedGenerationSet represents the maximum time for an ObservedGeneration to bump.
78+
// Max value for conformant implementation: None
79+
LatestObservedGenerationSet time.Duration
80+
7781
// RequiredConsecutiveSuccesses is the number of requests that must succeed in a row
7882
// to consider a response "consistent" before making additional assertions on the response body.
7983
// If this number is not reached within MaxTimeToConsistency, the test will fail.
@@ -96,6 +100,7 @@ func DefaultTimeoutConfig() TimeoutConfig {
96100
MaxTimeToConsistency: 30 * time.Second,
97101
NamespacesMustBeReady: 300 * time.Second,
98102
RequestTimeout: 10 * time.Second,
103+
LatestObservedGenerationSet: 60 * time.Second,
99104
RequiredConsecutiveSuccesses: 3,
100105
}
101106
}
@@ -141,4 +146,7 @@ func SetupTimeoutConfig(timeoutConfig *TimeoutConfig) {
141146
if timeoutConfig.RequestTimeout == 0 {
142147
timeoutConfig.RequestTimeout = defaultTimeoutConfig.RequestTimeout
143148
}
149+
if timeoutConfig.LatestObservedGenerationSet == 0 {
150+
timeoutConfig.LatestObservedGenerationSet = defaultTimeoutConfig.LatestObservedGenerationSet
151+
}
144152
}

conformance/utils/kubernetes/helpers.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,21 @@ func gwcMustBeAccepted(t *testing.T, c client.Client, timeoutConfig config.Timeo
108108
return controllerName
109109
}
110110

111-
// GatewayMustHaveLatestConditions will fail the test if there are
112-
// conditions that were not updated
113-
func GatewayMustHaveLatestConditions(t *testing.T, gw *v1beta1.Gateway) {
111+
// GatewayMustHaveLatestConditions waits until the specified Gateway has
112+
// the latest conditions to set.
113+
func GatewayMustHaveLatestConditions(t *testing.T, timeoutConfig config.TimeoutConfig, gw *v1beta1.Gateway) {
114114
t.Helper()
115115

116-
if err := ConditionsHaveLatestObservedGeneration(gw, gw.Status.Conditions); err != nil {
117-
t.Fatalf("Gateway %v", err)
118-
}
116+
waitErr := wait.PollImmediate(1*time.Second, timeoutConfig.LatestObservedGenerationSet, func() (bool, error) {
117+
if err := ConditionsHaveLatestObservedGeneration(gw, gw.Status.Conditions); err != nil {
118+
t.Logf("Gateway %s/%s latest conditions not set yet: %v", gw.Namespace, gw.Name, err)
119+
return false, nil
120+
}
121+
122+
return true, nil
123+
})
124+
125+
require.NoErrorf(t, waitErr, "error waiting for %s Gateway to have Latest ObservedGeneration to be set: %v", gw.Name, waitErr)
119126
}
120127

121128
// GatewayClassMustHaveLatestConditions will fail the test if there are

0 commit comments

Comments
 (0)