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
8 changes: 4 additions & 4 deletions apis/v1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ type GatewaySpec struct {
// Addresses requested for this Gateway. This is optional and behavior can
// depend on the implementation. If a value is set in the spec and the
// requested address is invalid or unavailable, the implementation MUST
// indicate this in the associated entry in GatewayStatus.Addresses.
// indicate this in an associated entry in GatewayStatus.Conditions.
//
// The Addresses field represents a request for the address(es) on the
// "outside of the Gateway", that traffic bound for this Gateway will use.
Expand All @@ -268,8 +268,8 @@ type GatewaySpec struct {
// +listType=atomic
// <gateway:validateIPAddress>
// +kubebuilder:validation:MaxItems=16
// +kubebuilder:validation:XValidation:message="IPAddress values must be unique",rule="self.all(a1, a1.type == 'IPAddress' ? self.exists_one(a2, a2.type == a1.type && a2.value == a1.value) : true )"
// +kubebuilder:validation:XValidation:message="Hostname values must be unique",rule="self.all(a1, a1.type == 'Hostname' ? self.exists_one(a2, a2.type == a1.type && a2.value == a1.value) : true )"
// +kubebuilder:validation:XValidation:message="IPAddress values must be unique",rule="self.all(a1, a1.type == 'IPAddress' && has(a1.value) ? self.exists_one(a2, a2.type == a1.type && has(a2.value) && a2.value == a1.value) : true )"
// +kubebuilder:validation:XValidation:message="Hostname values must be unique",rule="self.all(a1, a1.type == 'Hostname' && has(a1.value) ? self.exists_one(a2, a2.type == a1.type && has(a2.value) && a2.value == a1.value) : true )"
Addresses []GatewaySpecAddress `json:"addresses,omitempty"`

// Infrastructure defines infrastructure level attributes about this Gateway instance.
Expand Down Expand Up @@ -884,7 +884,7 @@ type RouteGroupKind struct {

// GatewaySpecAddress describes an address that can be bound to a Gateway.
//
// +kubebuilder:validation:XValidation:message="Hostname value must only contain valid characters (matching ^(\\*\\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$)",rule="self.type == 'Hostname' ? self.value.matches(r\"\"\"^(\\*\\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$\"\"\"): true"
// +kubebuilder:validation:XValidation:message="Hostname value must be empty or contain only valid characters (matching ^(\\*\\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$)",rule="self.type == 'Hostname' ? (!has(self.value) || self.value.matches(r\"\"\"^(\\*\\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$\"\"\")): true"
type GatewaySpecAddress struct {
// Type of the address.
//
Expand Down
36 changes: 20 additions & 16 deletions config/crd/experimental/gateway.networking.k8s.io_gateways.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions config/crd/standard/gateway.networking.k8s.io_gateways.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions conformance/tests/gateway-static-addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ var GatewayStaticAddresses = suite.ConformanceTest{
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, finalExpectedListenerState)
require.Len(t, currentGW.Spec.Addresses, 1, "expected only 1 address left specified on Gateway")
statusAddresses := extractStatusAddresses(currentGW.Status.Addresses)
require.NotContains(t, statusAddresses, unusableAddress.Value, "should contain the unusable address")
require.NotContains(t, statusAddresses, invalidAddress.Value, "should contain the invalid address")
require.NotContains(t, statusAddresses, unusableAddress.Value, "should not contain the unusable address")
require.NotContains(t, statusAddresses, invalidAddress.Value, "should not contain the invalid address")
require.Contains(t, statusAddresses, usableAddress.Value, "should contain the usable address")
for _, addr := range currentGW.Status.Addresses {
if usableAddress.Value != addr.Value {
Expand Down
2 changes: 1 addition & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions pkg/test/cel/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,54 @@ func TestValidateGateway(t *testing.T) {
},
wantErrors: []string{"IPAddress values must be unique", "Hostname values must be unique"},
},
{
desc: "optional ip address or hostname values",
mutate: func(gw *gatewayv1.Gateway) {
gw.Spec.Addresses = []gatewayv1.GatewaySpecAddress{
{
Type: ptrTo(gatewayv1.IPAddressType),
},
{
Type: ptrTo(gatewayv1.HostnameAddressType),
},
}
},
},
{
desc: "multiple optional ip address or hostname values alongside defined values",
mutate: func(gw *gatewayv1.Gateway) {
gw.Spec.Addresses = []gatewayv1.GatewaySpecAddress{
{
Type: ptrTo(gatewayv1.HostnameAddressType),
},
{
Type: ptrTo(gatewayv1.IPAddressType),
},
{
Type: ptrTo(gatewayv1.IPAddressType),
Value: "1.2.3.4",
},
{
Type: ptrTo(gatewayv1.HostnameAddressType),
Value: "foo.bar",
},
{
Type: ptrTo(gatewayv1.IPAddressType),
},
{
Type: ptrTo(gatewayv1.HostnameAddressType),
},
{
Type: ptrTo(gatewayv1.IPAddressType),
Value: "2.3.4.5",
},
{
Type: ptrTo(gatewayv1.HostnameAddressType),
Value: "bar.bar",
},
}
},
},
}

for _, tc := range testCases {
Expand Down