Skip to content

Commit fdde6ba

Browse files
authored
Automate Graceful Recovery NFR (#1832)
Problem: We want to automate the Graceful Recovery NFR. Solution: Extend existing automation to cover the following test cases in the Graceful Recovery NFR: "restart nginx-gateway container" and "restart NGINX container". Testing: Test correctly matches results of manual run of graceful-recovery NFR test.
1 parent 98ec514 commit fdde6ba

11 files changed

+567
-15
lines changed

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GINKGO_FLAGS=
1414
NGF_VERSION=
1515
CI=false
1616
TELEMETRY_ENDPOINT=
17-
TELEMETRY_ENDPOINT_INSECURE=
17+
TELEMETRY_ENDPOINT_INSECURE=false
1818

1919
ifneq ($(GINKGO_LABEL),)
2020
override GINKGO_FLAGS += --label-filter "$(GINKGO_LABEL)"

tests/framework/request.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package framework
33
import (
44
"bytes"
55
"context"
6+
"crypto/tls"
67
"fmt"
78
"net"
89
"net/http"
@@ -34,7 +35,18 @@ func Get(url, address string, timeout time.Duration) (int, string, error) {
3435
return 0, "", err
3536
}
3637

37-
resp, err := http.DefaultClient.Do(req)
38+
var resp *http.Response
39+
if strings.HasPrefix(url, "https") {
40+
customTransport := http.DefaultTransport.(*http.Transport).Clone()
41+
// similar to how in our examples with https requests we run our curl command
42+
// we turn off verification of the certificate, we do the same here
43+
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} //nolint:gosec // for https test traffic
44+
client := &http.Client{Transport: customTransport}
45+
resp, err = client.Do(req)
46+
} else {
47+
resp, err = http.DefaultClient.Do(req)
48+
}
49+
3850
if err != nil {
3951
return 0, "", err
4052
}

tests/framework/resourcemanager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ func (rm *ResourceManager) ApplyFromFiles(files []string, namespace string) erro
124124
}
125125

126126
// Delete deletes Kubernetes resources defined as Go objects.
127-
func (rm *ResourceManager) Delete(resources []client.Object) error {
127+
func (rm *ResourceManager) Delete(resources []client.Object, opts ...client.DeleteOption) error {
128128
for _, resource := range resources {
129129
ctx, cancel := context.WithTimeout(context.Background(), rm.TimeoutConfig.DeleteTimeout)
130130
defer cancel()
131131

132-
if err := rm.K8sClient.Delete(ctx, resource); err != nil && !apierrors.IsNotFound(err) {
132+
if err := rm.K8sClient.Delete(ctx, resource, opts...); err != nil && !apierrors.IsNotFound(err) {
133133
return fmt.Errorf("error deleting resource: %w", err)
134134
}
135135
}
@@ -159,7 +159,7 @@ func (rm *ResourceManager) readAndHandleObjects(
159159
files []string,
160160
) error {
161161
for _, file := range files {
162-
data, err := rm.getFileContents(file)
162+
data, err := rm.GetFileContents(file)
163163
if err != nil {
164164
return err
165165
}
@@ -187,9 +187,9 @@ func (rm *ResourceManager) readAndHandleObjects(
187187
return nil
188188
}
189189

190-
// getFileContents takes a string that can either be a local file
190+
// GetFileContents takes a string that can either be a local file
191191
// path or an https:// URL to YAML manifests and provides the contents.
192-
func (rm *ResourceManager) getFileContents(file string) (*bytes.Buffer, error) {
192+
func (rm *ResourceManager) GetFileContents(file string) (*bytes.Buffer, error) {
193193
if strings.HasPrefix(file, "http://") {
194194
return nil, fmt.Errorf("data can't be retrieved from %s: http is not supported, use https", file)
195195
} else if strings.HasPrefix(file, "https://") {
@@ -314,7 +314,7 @@ func (rm *ResourceManager) waitForRoutesToBeReady(ctx context.Context, namespace
314314

315315
var numParents, readyCount int
316316
for _, route := range routeList.Items {
317-
numParents += len(route.Status.Parents)
317+
numParents += len(route.Spec.ParentRefs)
318318
for _, parent := range route.Status.Parents {
319319
for _, cond := range parent.Conditions {
320320
if cond.Type == string(v1.RouteConditionAccepted) && cond.Status == metav1.ConditionTrue {

tests/framework/timeout.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@ type TimeoutConfig struct {
1717

1818
// RequestTimeout represents the maximum time for making an HTTP Request with the roundtripper.
1919
RequestTimeout time.Duration
20+
21+
// ContainerRestartTimeout represents the maximum time for a Kubernetes Container to restart.
22+
ContainerRestartTimeout time.Duration
23+
24+
// GetLeaderLeaseTimeout represents the maximum time for NGF to retrieve the leader lease.
25+
GetLeaderLeaseTimeout time.Duration
2026
}
2127

2228
// DefaultTimeoutConfig populates a TimeoutConfig with the default values.
2329
func DefaultTimeoutConfig() TimeoutConfig {
2430
return TimeoutConfig{
25-
CreateTimeout: 60 * time.Second,
26-
DeleteTimeout: 10 * time.Second,
27-
GetTimeout: 10 * time.Second,
28-
ManifestFetchTimeout: 10 * time.Second,
29-
RequestTimeout: 10 * time.Second,
31+
CreateTimeout: 60 * time.Second,
32+
DeleteTimeout: 10 * time.Second,
33+
GetTimeout: 10 * time.Second,
34+
ManifestFetchTimeout: 10 * time.Second,
35+
RequestTimeout: 10 * time.Second,
36+
ContainerRestartTimeout: 10 * time.Second,
37+
GetLeaderLeaseTimeout: 60 * time.Second,
3038
}
3139
}

0 commit comments

Comments
 (0)