Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions conformance/tests/gateway-optional-address-value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"context"
"testing"

"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/types"

v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayOptionalAddressValue)
}

var GatewayOptionalAddressValue = suite.ConformanceTest{
ShortName: "GatewayOptionalAddressValue",
Description: "Check Gateway Support for GatewayAddressEmpty feature",
Features: []features.FeatureName{
features.SupportGateway,
features.SupportGatewayAddressEmpty,
},
Provisional: true,
Manifests: []string{
Comment thread
EyalPazz marked this conversation as resolved.
"tests/gateway-optional-address-value.yaml",
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
ns := "gateway-conformance-infra"

kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, []string{ns})

gwNN := types.NamespacedName{
Name: "gateway-without-address-value",
Namespace: "gateway-conformance-infra",
}
ctx, cancel := context.WithTimeout(context.Background(), s.TimeoutConfig.DefaultTestTimeout)
defer cancel()

t.Logf("waiting for Gateway %s to be ready for testing", gwNN.Name)
kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN)

t.Logf("retrieving Gateway %s/%s", gwNN.Namespace, gwNN.Name)
currentGW := &v1.Gateway{}
err := s.Client.Get(ctx, gwNN, currentGW)
require.NoError(t, err, "error getting Gateway: %v", err)
t.Logf("verifying that the Gateway %s/%s is accepted", gwNN.Namespace, gwNN.Name)
_, err = kubernetes.WaitForGatewayAddress(t, s.Client, s.TimeoutConfig, kubernetes.NewGatewayRef(gwNN, "http"))
require.NoError(t, err, "timed out waiting for Gateway address to be assigned")
},
}
13 changes: 13 additions & 0 deletions conformance/tests/gateway-optional-address-value.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-without-address-value
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
addresses:
- type: "IPAddress"
listeners:
- name: http
port: 8080
protocol: HTTP
2 changes: 1 addition & 1 deletion conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
}
port = strconv.FormatInt(int64(listener.Port), 10)
for _, address := range gw.Status.Addresses {
if address.Type != nil && (*address.Type == gatewayv1.IPAddressType || *address.Type == v1alpha2.HostnameAddressType) {
if address.Type != nil {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlavacca regarding this line, do you think it's an OK change? i didn't really understand why it was like at first place

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it's ok to remove the other condition, as we have only three possibilities:

  • IPAddress
  • HostnameAddress
  • domain-prefixed named address (which replaced NamedAddress)

Since the last one is implementation-specific and will never be tested, we can safely simplify this if condition as you proposed.

Nice catch!

ipAddr = address.Value
return true, nil
}
Expand Down