Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions conformance/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func DefaultOptions(t *testing.T) suite.ConformanceOptions {
ExemptFeatures: exemptFeatures,
ManifestFS: []fs.FS{&Manifests},
GatewayClassName: *flags.GatewayClassName,
AddressType: *flags.AddressType,
Implementation: implementation,
Mode: *flags.Mode,
NamespaceAnnotations: namespaceAnnotations,
Expand Down
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{
"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)
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")
},
}
17 changes: 17 additions & 0 deletions conformance/tests/gateway-optional-address-value.yaml
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
1 change: 1 addition & 0 deletions conformance/utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ var (
ConformanceProfiles = flag.String("conformance-profiles", "", "Comma-separated list of the conformance profiles to run")
ReportOutput = flag.String("report-output", "", "The file where to write the conformance report")
SkipProvisionalTests = flag.Bool("skip-provisional-tests", false, "Whether to skip provisional tests")
AddressType = flag.String("address-type", "IPAddress", "Type of address in the gateway spec")
)
19 changes: 19 additions & 0 deletions conformance/utils/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ func (a Applier) prepareGateway(t *testing.T, uObj *unstructured.Unstructured) {
err = unstructured.SetNestedSlice(uObj.Object, primOverlayAddrs, "spec", "addresses")
require.NoError(t, err, "could not overlay static addresses on Gateway %s/%s", ns, name)
}

// This is being done in order to support the injection of implementation-specific address types
// into the test suite
var addresses []interface{}
for _, add := range gwspec.Addresses {
if *add.Type == "PLACEHOLDER_ADDRESS_TYPE" {
addresses = append(addresses, map[string]interface{}{
"type": a.AddressType,
},
)
} else {
addresses = append(addresses, add)
}
}

if len(addresses) > 0 {
err = unstructured.SetNestedSlice(uObj.Object, addresses, "spec", "addresses")
require.NoError(t, err, "could not overlay address type on Gateway %s/%s", ns, name)
}
}

// prepareGatewayClass adjust the spec.controllerName on the resource
Expand Down
2 changes: 1 addition & 1 deletion conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor 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

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