Skip to content

Commit 16674f6

Browse files
Add flags for using FQDN for host, appending port for all requests, and timeout config
1 parent a83607f commit 16674f6

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

conformance/conformance.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package conformance
1818

1919
import (
20+
"encoding/json"
2021
"io/fs"
2122
"os"
2223
"testing"
@@ -81,6 +82,13 @@ func DefaultOptions(t *testing.T) suite.ConformanceOptions {
8182
*flags.ImplementationContact,
8283
)
8384

85+
timeoutConfig := conformanceconfig.DefaultTimeoutConfig()
86+
87+
if *flags.TimeoutConfig != "" {
88+
err := json.Unmarshal([]byte(*flags.TimeoutConfig), &timeoutConfig)
89+
require.NoError(t, err, "error initializing timeout config from the input")
90+
}
91+
8492
return suite.ConformanceOptions{
8593
AllowCRDsMismatch: *flags.AllowCRDsMismatch,
8694
CleanupBaseResources: *flags.CleanupBaseResources,
@@ -103,7 +111,7 @@ func DefaultOptions(t *testing.T) suite.ConformanceOptions {
103111
RunTest: *flags.RunTest,
104112
SkipTests: skipTests,
105113
SupportedFeatures: supportedFeatures,
106-
TimeoutConfig: conformanceconfig.DefaultTimeoutConfig(),
114+
TimeoutConfig: timeoutConfig,
107115
SkipProvisionalTests: *flags.SkipProvisionalTests,
108116
}
109117
}

conformance/mesh/manifests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ spec:
2828
- name: echo
2929
image: gcr.io/k8s-staging-gateway-api/echo-advanced:v20240412-v1.0.0-394-g40c666fd
3030
imagePullPolicy: IfNotPresent
31+
ports:
32+
- containerPort: 8080
33+
- containerPort: 8443
34+
- containerPort: 9090
35+
- containerPort: 7070
3136
args:
3237
- --tcp=9090
3338
- --port=8080
@@ -85,6 +90,11 @@ spec:
8590
- name: echo
8691
image: gcr.io/k8s-staging-gateway-api/echo-advanced:v20240412-v1.0.0-394-g40c666fd
8792
imagePullPolicy: IfNotPresent
93+
ports:
94+
- containerPort: 8080
95+
- containerPort: 8443
96+
- containerPort: 9090
97+
- containerPort: 7070
8898
args:
8999
- --tcp=9090
90100
- --port=8080

conformance/utils/echo/pod.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535

3636
"sigs.k8s.io/gateway-api/conformance/utils/config"
37+
"sigs.k8s.io/gateway-api/conformance/utils/flags"
3738
"sigs.k8s.io/gateway-api/conformance/utils/http"
3839
"sigs.k8s.io/gateway-api/conformance/utils/suite"
3940
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
@@ -104,7 +105,12 @@ func makeRequest(t *testing.T, exp *http.ExpectedResponse) []string {
104105
exp.Response.StatusCodes = []int{200}
105106
}
106107

108+
if *flags.UseFQDNHost {
109+
r.Host = fmt.Sprintf("%v.%v", strings.Split(r.Host, ".")[0], "gateway-conformance-mesh.svc.cluster.local")
110+
}
111+
107112
host := http.CalculateHost(t, r.Host, protocol)
113+
108114
args := []string{"client", fmt.Sprintf("%s://%s%s", protocol, host, r.Path)}
109115
if protocol != "grpc" && r.Method != "" {
110116
args = append(args, "--method="+r.Method)

conformance/utils/flags/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ var (
5050
ConformanceProfiles = flag.String("conformance-profiles", "", "Comma-separated list of the conformance profiles to run")
5151
ReportOutput = flag.String("report-output", "", "The file where to write the conformance report")
5252
SkipProvisionalTests = flag.Bool("skip-provisional-tests", false, "Whether to skip provisional tests")
53+
UseFQDNHost = flag.Bool("use-fqdn-host", false, "Use FQDN for hosts for all requests")
54+
AppendPortToHost = flag.Bool("append-port-to-host", false, "add port to the host for all ports including 80 and 443")
55+
TimeoutConfig = flag.String("timeout-config", "", "TimeoutConfig object in json format")
5356
)

conformance/utils/http/http.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"time"
2727

2828
"sigs.k8s.io/gateway-api/conformance/utils/config"
29+
"sigs.k8s.io/gateway-api/conformance/utils/flags"
2930
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
3031
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
3132
"sigs.k8s.io/gateway-api/conformance/utils/weight"
@@ -202,12 +203,23 @@ func CalculateHost(t *testing.T, gwAddr, scheme string) string {
202203
if !strings.Contains(err.Error(), "missing port in address") {
203204
tlog.Logf(t, "Failed to parse host %q: %v", gwAddr, err)
204205
}
206+
if *flags.AppendPortToHost {
207+
if port != "" {
208+
return gwAddr
209+
}
210+
if strings.ToLower(scheme) == "http" {
211+
return fmt.Sprintf("%v:%v", gwAddr, "80")
212+
}
213+
if strings.ToLower(scheme) == "https" {
214+
return fmt.Sprintf("%v:%v", gwAddr, "443")
215+
}
216+
}
205217
return gwAddr
206218
}
207-
if strings.ToLower(scheme) == "http" && port == "80" {
219+
if strings.ToLower(scheme) == "http" && port == "80" && !*flags.AppendPortToHost {
208220
return Ipv6SafeHost(host)
209221
}
210-
if strings.ToLower(scheme) == "https" && port == "443" {
222+
if strings.ToLower(scheme) == "https" && port == "443" && !*flags.AppendPortToHost {
211223
return Ipv6SafeHost(host)
212224
}
213225
return gwAddr

0 commit comments

Comments
 (0)