-
Notifications
You must be signed in to change notification settings - Fork 555
conformance: add test for optional address value #3689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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{ | ||
"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 namespace %s and Gateway %s to be ready for testing", gwNN.Namespace, gwNN.Name) | ||
mlavacca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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") | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-without-address-value | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
addresses: | ||
# This indicates an address type that will be substituted within the test suite | ||
# It's currently inputted via the `address-type` flag | ||
- type: "PLACEHOLDER_ADDRESS_TYPE" | ||
|
||
listeners: | ||
- name: http | ||
port: 8080 | ||
protocol: HTTP |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,7 +444,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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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 | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.