Skip to content

Commit 7ae834e

Browse files
committed
conformance: add test for optional address value
1 parent f6c481a commit 7ae834e

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

conformance/conformance.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func DefaultOptions(t *testing.T) suite.ConformanceOptions {
8888
ExemptFeatures: exemptFeatures,
8989
ManifestFS: []fs.FS{&Manifests},
9090
GatewayClassName: *flags.GatewayClassName,
91+
AddressType: *flags.AddressType,
9192
Implementation: implementation,
9293
Mode: *flags.Mode,
9394
NamespaceAnnotations: namespaceAnnotations,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package tests
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/stretchr/testify/require"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/types"
26+
27+
v1 "sigs.k8s.io/gateway-api/apis/v1"
28+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
29+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
30+
"sigs.k8s.io/gateway-api/pkg/features"
31+
)
32+
33+
func init() {
34+
ConformanceTests = append(ConformanceTests, GatewayOptionalAddressValue)
35+
}
36+
37+
var GatewayOptionalAddressValue = suite.ConformanceTest{
38+
ShortName: "GatewayOptionalAddressValue",
39+
Description: "Check Gateway Support for GatewayAddressEmpty feature",
40+
Features: []features.FeatureName{
41+
features.SupportGateway,
42+
features.SupportGatewayAddressEmpty,
43+
},
44+
Manifests: []string{
45+
"tests/gateway-optional-address-value.yaml",
46+
},
47+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
48+
ns := "gateway-conformance-infra"
49+
50+
kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, []string{ns})
51+
52+
gwNN := types.NamespacedName{
53+
Name: "gateway-without-address-value",
54+
Namespace: "gateway-conformance-infra",
55+
}
56+
ctx, cancel := context.WithTimeout(context.Background(), s.TimeoutConfig.DefaultTestTimeout)
57+
defer cancel()
58+
59+
t.Logf("waiting for namespace %s and Gateway %s to be ready for testing", gwNN.Namespace, gwNN.Name)
60+
kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN)
61+
62+
t.Logf("retrieving Gateway %s/%s", gwNN.Namespace, gwNN.Name)
63+
currentGW := &v1.Gateway{}
64+
err := s.Client.Get(ctx, gwNN, currentGW)
65+
require.NoError(t, err, "error getting Gateway: %v", err)
66+
t.Logf("verifying that the Gateway %s/%s is accepted without address value field", gwNN.Namespace, gwNN.Name)
67+
kubernetes.GatewayMustHaveCondition(t, s.Client, s.TimeoutConfig, gwNN, metav1.Condition{
68+
Type: string(v1.GatewayConditionAccepted),
69+
Status: metav1.ConditionTrue,
70+
})
71+
},
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: gateway.networking.k8s.io/v1
3+
kind: Gateway
4+
metadata:
5+
name: gateway-without-address-value
6+
namespace: gateway-conformance-infra
7+
spec:
8+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
9+
addresses:
10+
# This indicates an address type that will be substituted within the test suite
11+
# It's currently inputted via the `address-type` flag
12+
- type: "PLACEHOLDER_ADDRESS_TYPE"
13+
14+
listeners:
15+
- name: http
16+
port: 8080
17+
protocol: HTTP

conformance/utils/flags/flags.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ var (
4949
ConformanceProfiles = flag.String("conformance-profiles", "", "Comma-separated list of the conformance profiles to run")
5050
ReportOutput = flag.String("report-output", "", "The file where to write the conformance report")
5151
SkipProvisionalTests = flag.Bool("skip-provisional-tests", false, "Whether to skip provisional tests")
52+
AddressType = flag.String("address-type", "IPAddress", "Type of address in the gateway spec")
5253
)

conformance/utils/kubernetes/apply.go

+10
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ func (a Applier) prepareGateway(t *testing.T, uObj *unstructured.Unstructured) {
139139
err = unstructured.SetNestedSlice(uObj.Object, primOverlayAddrs, "spec", "addresses")
140140
require.NoError(t, err, "could not overlay static addresses on Gateway %s/%s", ns, name)
141141
}
142+
143+
// This is being done in order to support the injection of implementation-specific address types
144+
// into the test suite
145+
if len(gwspec.Addresses) > 0 && *gwspec.Addresses[0].Type == "PLACEHOLDER_ADDRESS_TYPE" {
146+
addrs := map[string]interface{}{
147+
"type": a.AddressType,
148+
}
149+
err = unstructured.SetNestedSlice(uObj.Object, []interface{}{addrs}, "spec", "addresses")
150+
require.NoError(t, err, "could not overlay address type on Gateway %s/%s", ns, name)
151+
}
142152
}
143153

144154
// prepareGatewayClass adjust the spec.controllerName on the resource

0 commit comments

Comments
 (0)