/*
Copyright 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.
*/

// Code generated by applyconfiguration-gen. DO NOT EDIT.

package v1

import (
	apisv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// GatewaySpecApplyConfiguration represents a declarative configuration of the GatewaySpec type for use
// with apply.
//
// GatewaySpec defines the desired state of Gateway.
//
// Not all possible combinations of options specified in the Spec are
// valid. Some invalid configurations can be caught synchronously via CRD
// validation, but there are many cases that will require asynchronous
// signaling via the GatewayStatus block.
type GatewaySpecApplyConfiguration struct {
	// GatewayClassName used for this Gateway. This is the name of a
	// GatewayClass resource.
	GatewayClassName *apisv1.ObjectName `json:"gatewayClassName,omitempty"`
	// Listeners associated with this Gateway. Listeners define
	// logical endpoints that are bound on this Gateway's addresses.
	// At least one Listener MUST be specified.
	//
	// ## Distinct Listeners
	//
	// Each Listener in a set of Listeners (for example, in a single Gateway)
	// MUST be _distinct_, in that a traffic flow MUST be able to be assigned to
	// exactly one listener. (This section uses "set of Listeners" rather than
	// "Listeners in a single Gateway" because implementations MAY merge configuration
	// from multiple Gateways onto a single data plane, and these rules _also_
	// apply in that case).
	//
	// Practically, this means that each listener in a set MUST have a unique
	// combination of Port, Protocol, and, if supported by the protocol, Hostname.
	//
	// Some combinations of port, protocol, and TLS settings are considered
	// Core support and MUST be supported by implementations based on the objects
	// they support:
	//
	// # HTTPRoute
	//
	// 1. HTTPRoute, Port: 80, Protocol: HTTP
	// 2. HTTPRoute, Port: 443, Protocol: HTTPS, TLS Mode: Terminate, TLS keypair provided
	//
	// # TLSRoute
	//
	// 1. TLSRoute, Port: 443, Protocol: TLS, TLS Mode: Passthrough
	//
	// "Distinct" Listeners have the following property:
	//
	// **The implementation can match inbound requests to a single distinct
	// Listener**.
	//
	// When multiple Listeners share values for fields (for
	// example, two Listeners with the same Port value), the implementation
	// can match requests to only one of the Listeners using other
	// Listener fields.
	//
	// When multiple listeners have the same value for the Protocol field, then
	// each of the Listeners with matching Protocol values MUST have different
	// values for other fields.
	//
	// The set of fields that MUST be different for a Listener differs per protocol.
	// The following rules define the rules for what fields MUST be considered for
	// Listeners to be distinct with each protocol currently defined in the
	// Gateway API spec.
	//
	// The set of listeners that all share a protocol value MUST have _different_
	// values for _at least one_ of these fields to be distinct:
	//
	// * **HTTP, HTTPS, TLS**: Port, Hostname
	// * **TCP, UDP**: Port
	//
	// One **very** important rule to call out involves what happens when an
	// implementation:
	//
	// * Supports TCP protocol Listeners, as well as HTTP, HTTPS, or TLS protocol
	// Listeners, and
	// * sees HTTP, HTTPS, or TLS protocols with the same `port` as one with TCP
	// Protocol.
	//
	// In this case all the Listeners that share a port with the
	// TCP Listener are not distinct and so MUST NOT be accepted.
	//
	// If an implementation does not support TCP Protocol Listeners, then the
	// previous rule does not apply, and the TCP Listeners SHOULD NOT be
	// accepted.
	//
	// Note that the `tls` field is not used for determining if a listener is distinct, because
	// Listeners that _only_ differ on TLS config will still conflict in all cases.
	//
	// ### Listeners that are distinct only by Hostname
	//
	// When the Listeners are distinct based only on Hostname, inbound request
	// hostnames MUST match from the most specific to least specific Hostname
	// values to choose the correct Listener and its associated set of Routes.
	//
	// Exact matches MUST be processed before wildcard matches, and wildcard
	// matches MUST be processed before fallback (empty Hostname value)
	// matches. For example, `"foo.example.com"` takes precedence over
	// `"*.example.com"`, and `"*.example.com"` takes precedence over `""`.
	//
	// Additionally, if there are multiple wildcard entries, more specific
	// wildcard entries must be processed before less specific wildcard entries.
	// For example, `"*.foo.example.com"` takes precedence over `"*.example.com"`.
	//
	// The precise definition here is that the higher the number of dots in the
	// hostname to the right of the wildcard character, the higher the precedence.
	//
	// The wildcard character will match any number of characters _and dots_ to
	// the left, however, so `"*.example.com"` will match both
	// `"foo.bar.example.com"` _and_ `"bar.example.com"`.
	//
	// ## Handling indistinct Listeners
	//
	// If a set of Listeners contains Listeners that are not distinct, then those
	// Listeners are _Conflicted_, and the implementation MUST set the "Conflicted"
	// condition in the Listener Status to "True".
	//
	// The words "indistinct" and "conflicted" are considered equivalent for the
	// purpose of this documentation.
	//
	// Implementations MAY choose to accept a Gateway with some Conflicted
	// Listeners only if they only accept the partial Listener set that contains
	// no Conflicted Listeners.
	//
	// Specifically, an implementation MAY accept a partial Listener set subject to
	// the following rules:
	//
	// * The implementation MUST NOT pick one conflicting Listener as the winner.
	// ALL indistinct Listeners must not be accepted for processing.
	// * At least one distinct Listener MUST be present, or else the Gateway effectively
	// contains _no_ Listeners, and must be rejected from processing as a whole.
	//
	// The implementation MUST set a "ListenersNotValid" condition on the
	// Gateway Status when the Gateway contains Conflicted Listeners whether or
	// not they accept the Gateway. That Condition SHOULD clearly
	// indicate in the Message which Listeners are conflicted, and which are
	// Accepted. Additionally, the Listener status for those listeners SHOULD
	// indicate which Listeners are conflicted and not Accepted.
	//
	// ## General Listener behavior
	//
	// Note that, for all distinct Listeners, requests SHOULD match at most one Listener.
	// For example, if Listeners are defined for "foo.example.com" and "*.example.com", a
	// request to "foo.example.com" SHOULD only be routed using routes attached
	// to the "foo.example.com" Listener (and not the "*.example.com" Listener).
	//
	// This concept is known as "Listener Isolation", and it is an Extended feature
	// of Gateway API. Implementations that do not support Listener Isolation MUST
	// clearly document this, and MUST NOT claim support for the
	// `GatewayHTTPListenerIsolation` feature.
	//
	// Implementations that _do_ support Listener Isolation SHOULD claim support
	// for the Extended `GatewayHTTPListenerIsolation` feature and pass the associated
	// conformance tests.
	//
	// ## Compatible Listeners
	//
	// A Gateway's Listeners are considered _compatible_ if:
	//
	// 1. They are distinct.
	// 2. The implementation can serve them in compliance with the Addresses
	// requirement that all Listeners are available on all assigned
	// addresses.
	//
	// Compatible combinations in Extended support are expected to vary across
	// implementations. A combination that is compatible for one implementation
	// may not be compatible for another.
	//
	// For example, an implementation that cannot serve both TCP and UDP listeners
	// on the same address, or cannot mix HTTPS and generic TLS listens on the same port
	// would not consider those cases compatible, even though they are distinct.
	//
	// Implementations MAY merge separate Gateways onto a single set of
	// Addresses if all Listeners across all Gateways are compatible.
	//
	// In a future release the MinItems=1 requirement MAY be dropped.
	//
	// Support: Core
	Listeners []ListenerApplyConfiguration `json:"listeners,omitempty"`
	// 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 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.
	// This could be the IP address or hostname of an external load balancer or
	// other networking infrastructure, or some other address that traffic will
	// be sent to.
	//
	// If no Addresses are specified, the implementation MAY schedule the
	// Gateway in an implementation-specific manner, assigning an appropriate
	// set of Addresses.
	//
	// The implementation MUST bind all Listeners to every GatewayAddress that
	// it assigns to the Gateway and add a corresponding entry in
	// GatewayStatus.Addresses.
	//
	// Support: Extended
	//
	// <gateway:validateIPAddress>
	Addresses []GatewaySpecAddressApplyConfiguration `json:"addresses,omitempty"`
	// Infrastructure defines infrastructure level attributes about this Gateway instance.
	//
	// Support: Extended
	Infrastructure *GatewayInfrastructureApplyConfiguration `json:"infrastructure,omitempty"`
	// AllowedListeners defines which ListenerSets can be attached to this Gateway.
	// The default value is to allow no ListenerSets.
	AllowedListeners *AllowedListenersApplyConfiguration `json:"allowedListeners,omitempty"`
	// TLS specifies frontend and backend tls configuration for entire gateway.
	//
	// Support: Extended
	TLS *GatewayTLSConfigApplyConfiguration `json:"tls,omitempty"`
	// DefaultScope, when set, configures the Gateway as a default Gateway,
	// meaning it will dynamically and implicitly have Routes (e.g. HTTPRoute)
	// attached to it, according to the scope configured here.
	//
	// If unset (the default) or set to None, the Gateway will not act as a
	// default Gateway; if set, the Gateway will claim any Route with a
	// matching scope set in its UseDefaultGateway field, subject to the usual
	// rules about which routes the Gateway can attach to.
	//
	// Think carefully before using this functionality! While the normal rules
	// about which Route can apply are still enforced, it is simply easier for
	// the wrong Route to be accidentally attached to this Gateway in this
	// configuration. If the Gateway operator is not also the operator in
	// control of the scope (e.g. namespace) with tight controls and checks on
	// what kind of workloads and Routes get added in that scope, we strongly
	// recommend not using this just because it seems convenient, and instead
	// stick to direct Route attachment.
	//
	// <gateway:experimental>
	DefaultScope *apisv1.GatewayDefaultScope `json:"defaultScope,omitempty"`
}

// GatewaySpecApplyConfiguration constructs a declarative configuration of the GatewaySpec type for use with
// apply.
func GatewaySpec() *GatewaySpecApplyConfiguration {
	return &GatewaySpecApplyConfiguration{}
}

// WithGatewayClassName sets the GatewayClassName field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the GatewayClassName field is set to the value of the last call.
func (b *GatewaySpecApplyConfiguration) WithGatewayClassName(value apisv1.ObjectName) *GatewaySpecApplyConfiguration {
	b.GatewayClassName = &value
	return b
}

// WithListeners adds the given value to the Listeners field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Listeners field.
func (b *GatewaySpecApplyConfiguration) WithListeners(values ...*ListenerApplyConfiguration) *GatewaySpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithListeners")
		}
		b.Listeners = append(b.Listeners, *values[i])
	}
	return b
}

// WithAddresses adds the given value to the Addresses field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Addresses field.
func (b *GatewaySpecApplyConfiguration) WithAddresses(values ...*GatewaySpecAddressApplyConfiguration) *GatewaySpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithAddresses")
		}
		b.Addresses = append(b.Addresses, *values[i])
	}
	return b
}

// WithInfrastructure sets the Infrastructure field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Infrastructure field is set to the value of the last call.
func (b *GatewaySpecApplyConfiguration) WithInfrastructure(value *GatewayInfrastructureApplyConfiguration) *GatewaySpecApplyConfiguration {
	b.Infrastructure = value
	return b
}

// WithAllowedListeners sets the AllowedListeners field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the AllowedListeners field is set to the value of the last call.
func (b *GatewaySpecApplyConfiguration) WithAllowedListeners(value *AllowedListenersApplyConfiguration) *GatewaySpecApplyConfiguration {
	b.AllowedListeners = value
	return b
}

// WithTLS sets the TLS field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the TLS field is set to the value of the last call.
func (b *GatewaySpecApplyConfiguration) WithTLS(value *GatewayTLSConfigApplyConfiguration) *GatewaySpecApplyConfiguration {
	b.TLS = value
	return b
}

// WithDefaultScope sets the DefaultScope field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the DefaultScope field is set to the value of the last call.
func (b *GatewaySpecApplyConfiguration) WithDefaultScope(value apisv1.GatewayDefaultScope) *GatewaySpecApplyConfiguration {
	b.DefaultScope = &value
	return b
}
