Skip to content

Commit

Permalink
feat: flag injection & change GatewayAddress -> GatewaySpecAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalPazz committed Feb 27, 2025
1 parent f87161b commit 1487843
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 93 deletions.
4 changes: 2 additions & 2 deletions apis/v1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ type GatewaySpec struct {
// +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 )"
Addresses []GatewayAddress `json:"addresses,omitempty"`
Addresses []GatewaySpecAddress `json:"addresses,omitempty"`

// Infrastructure defines infrastructure level attributes about this Gateway instance.
//
Expand Down Expand Up @@ -719,7 +719,7 @@ type RouteGroupKind struct {
// GatewayAddress 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"
type GatewayAddress struct {
type GatewaySpecAddress struct {
// Type of the address.
//
// +optional
Expand Down
1 change: 0 additions & 1 deletion apis/v1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ type LabelValue string
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^Hostname|IPAddress|NamedAddress|[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$`
type AddressType string

// HeaderName is the name of a header or query parameter.
Expand Down
42 changes: 21 additions & 21 deletions apis/v1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion apis/v1beta1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type RouteGroupKind = v1.RouteGroupKind

// GatewayAddress describes an address that can be bound to a Gateway.
// +k8s:deepcopy-gen=false
type GatewayAddress = v1.GatewayAddress
type GatewaySpecAddress = v1.GatewaySpecAddress

// GatewayStatus defines the observed state of Gateway.
// +k8s:deepcopy-gen=false
Expand Down
4 changes: 2 additions & 2 deletions applyconfiguration/apis/v1/gatewayspec.go

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

52 changes: 52 additions & 0 deletions applyconfiguration/apis/v1/gatewayspecaddress.go

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

22 changes: 11 additions & 11 deletions applyconfiguration/internal/internal.go

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

4 changes: 2 additions & 2 deletions applyconfiguration/utils.go

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

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

4 changes: 0 additions & 4 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.

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
1 change: 0 additions & 1 deletion conformance/tests/gateway-optional-address-value.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ var GatewayOptionalAddressValue = suite.ConformanceTest{
Type: string(v1.GatewayConditionAccepted),
Status: metav1.ConditionTrue,
})

},
}
3 changes: 2 additions & 1 deletion conformance/tests/gateway-optional-address-value.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
addresses:
# How should we inject a valid type here?
- type: "VALID_ADDRESS_TYPE_PLACEHOLDER"
- type: "PLACEHOLDER_ADDRESS_TYPE"

listeners:
- name: http
port: 8080
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/gateway-static-addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func extractStatusAddresses(addresses []v1.GatewayStatusAddress) []string {
// Private Helper Functions
// -----------------------------------------------------------------------------

func filterAddr(addrs []v1.GatewayAddress, filter v1.GatewayAddress) (newAddrs []v1.GatewayAddress) {
func filterAddr(addrs []v1.GatewaySpecAddress, filter v1.GatewaySpecAddress) (newAddrs []v1.GatewaySpecAddress) {
for _, addr := range addrs {
if addr.Value != filter.Value {
newAddrs = append(newAddrs, addr)
Expand Down
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")
)
22 changes: 18 additions & 4 deletions conformance/utils/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type Applier struct {
// GatewayClass will be used as the spec.gatewayClassName when applying Gateway resources
GatewayClass string

// AddressType is a type that is expected to be supported AND usable
// for Gateways in the underlying implementation
AddressType string

// ControllerName will be used as the spec.controllerName when applying GatewayClass resources
ControllerName string

Expand All @@ -57,11 +61,11 @@ type Applier struct {

// UsableNetworkAddresses is a list of addresses that are expected to be
// supported AND usable for Gateways in the underlying implementation.
UsableNetworkAddresses []v1beta1.GatewayAddress
UsableNetworkAddresses []v1beta1.GatewaySpecAddress

// UnusableNetworkAddresses is a list of addresses that are expected to be
// supported, but not usable for Gateways in the underlying implementation.
UnusableNetworkAddresses []v1beta1.GatewayAddress
UnusableNetworkAddresses []v1beta1.GatewaySpecAddress
}

// prepareGateway adjusts the gatewayClassName.
Expand Down Expand Up @@ -104,7 +108,7 @@ func (a Applier) prepareGateway(t *testing.T, uObj *unstructured.Unstructured) {
// Note: I would really love to find a better way to do this kind of
// thing in the future.
var overlayUsable, overlayUnusable bool
var specialAddrs []v1beta1.GatewayAddress
var specialAddrs []v1beta1.GatewaySpecAddress
for _, addr := range gwspec.Addresses {
switch addr.Value {
case "PLACEHOLDER_USABLE_ADDRS":
Expand Down Expand Up @@ -135,6 +139,16 @@ 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
if len(gwspec.Addresses) > 0 && *gwspec.Addresses[0].Type == "PLACEHOLDER_ADDRESS_TYPE" {
addrs := map[string]interface{}{
"type": a.AddressType,
}
err = unstructured.SetNestedSlice(uObj.Object, []interface{}{addrs}, "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 Expand Up @@ -353,7 +367,7 @@ func getContentsFromPathOrURL(manifestFS []fs.FS, location string, timeoutConfig
// convertGatewayAddrsToPrimitives converts a slice of Gateway addresses
// to a slice of primitive types and then returns them as a []interface{} so that
// they can be applied back to an unstructured Gateway.
func convertGatewayAddrsToPrimitives(gwaddrs []v1beta1.GatewayAddress) (raw []interface{}) {
func convertGatewayAddrsToPrimitives(gwaddrs []v1beta1.GatewaySpecAddress) (raw []interface{}) {
for _, addr := range gwaddrs {
addrType := string(v1beta1.IPAddressType)
if addr.Type != nil {
Expand Down
Loading

0 comments on commit 1487843

Please sign in to comment.