Skip to content

Commit d008cde

Browse files
authored
conformance: add test for optional address value (#3689)
* conformance: add test for optional address value * fix: small resolutions after CR * fix: CR Resolution 2 * fix: only overlay addresses if needed * fix: conflict resolvement mistake * fix: CR comments
1 parent 110bcaf commit d008cde

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
"k8s.io/apimachinery/pkg/types"
25+
26+
v1 "sigs.k8s.io/gateway-api/apis/v1"
27+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
28+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
29+
"sigs.k8s.io/gateway-api/pkg/features"
30+
)
31+
32+
func init() {
33+
ConformanceTests = append(ConformanceTests, GatewayOptionalAddressValue)
34+
}
35+
36+
var GatewayOptionalAddressValue = suite.ConformanceTest{
37+
ShortName: "GatewayOptionalAddressValue",
38+
Description: "Check Gateway Support for GatewayAddressEmpty feature",
39+
Features: []features.FeatureName{
40+
features.SupportGateway,
41+
features.SupportGatewayAddressEmpty,
42+
},
43+
Provisional: true,
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 Gateway %s to be ready for testing", 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", gwNN.Namespace, gwNN.Name)
67+
_, err = kubernetes.WaitForGatewayAddress(t, s.Client, s.TimeoutConfig, kubernetes.NewGatewayRef(gwNN, "http"))
68+
require.NoError(t, err, "timed out waiting for Gateway address to be assigned")
69+
},
70+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway-without-address-value
5+
namespace: gateway-conformance-infra
6+
spec:
7+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
8+
addresses:
9+
- type: "IPAddress"
10+
listeners:
11+
- name: http
12+
port: 8080
13+
protocol: HTTP

conformance/utils/kubernetes/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
446446
}
447447
port = strconv.FormatInt(int64(listener.Port), 10)
448448
for _, address := range gw.Status.Addresses {
449-
if address.Type != nil && (*address.Type == gatewayv1.IPAddressType || *address.Type == v1alpha2.HostnameAddressType) {
449+
if address.Type != nil {
450450
ipAddr = address.Value
451451
return true, nil
452452
}

0 commit comments

Comments
 (0)