|
| 1 | +# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md |
| 2 | + |
| 3 | + |
| 4 | +from typing import Any |
| 5 | +from ocp_resources.resource import NamespacedResource |
| 6 | +from ocp_resources.exceptions import MissingRequiredArgumentError |
| 7 | + |
| 8 | + |
| 9 | +class Gateway(NamespacedResource): |
| 10 | + """ |
| 11 | + Gateway represents an instance of a service-traffic handling infrastructure |
| 12 | + by binding Listeners to a set of IP addresses. |
| 13 | + """ |
| 14 | + |
| 15 | + api_group: str = NamespacedResource.ApiGroup.GATEWAY_NETWORKING_K8S_IO |
| 16 | + |
| 17 | + def __init__( |
| 18 | + self, |
| 19 | + addresses: list[Any] | None = None, |
| 20 | + gateway_class_name: str | None = None, |
| 21 | + infrastructure: dict[str, Any] | None = None, |
| 22 | + listeners: list[Any] | None = None, |
| 23 | + **kwargs: Any, |
| 24 | + ) -> None: |
| 25 | + r""" |
| 26 | + Args: |
| 27 | + addresses (list[Any]): Addresses requested for this Gateway. This is optional and behavior |
| 28 | + can depend on the implementation. If a value is set in the spec |
| 29 | + and the requested address is invalid or unavailable, the |
| 30 | + implementation MUST indicate this in the associated entry in |
| 31 | + GatewayStatus.Addresses. The Addresses field represents a request |
| 32 | + for the address(es) on the "outside of the Gateway", that traffic |
| 33 | + bound for this Gateway will use. This could be the IP address or |
| 34 | + hostname of an external load balancer or other networking |
| 35 | + infrastructure, or some other address that traffic will be sent |
| 36 | + to. If no Addresses are specified, the implementation MAY |
| 37 | + schedule the Gateway in an implementation-specific manner, |
| 38 | + assigning an appropriate set of Addresses. The implementation |
| 39 | + MUST bind all Listeners to every GatewayAddress that it assigns to |
| 40 | + the Gateway and add a corresponding entry in |
| 41 | + GatewayStatus.Addresses. Support: Extended |
| 42 | +
|
| 43 | + gateway_class_name (str): GatewayClassName used for this Gateway. This is the name of a |
| 44 | + GatewayClass resource. |
| 45 | +
|
| 46 | + infrastructure (dict[str, Any]): Infrastructure defines infrastructure level attributes about this |
| 47 | + Gateway instance. Support: Extended |
| 48 | +
|
| 49 | + listeners (list[Any]): Listeners associated with this Gateway. Listeners define logical |
| 50 | + endpoints that are bound on this Gateway's addresses. At least one |
| 51 | + Listener MUST be specified. ## Distinct Listeners Each Listener |
| 52 | + in a set of Listeners (for example, in a single Gateway) MUST be |
| 53 | + _distinct_, in that a traffic flow MUST be able to be assigned to |
| 54 | + exactly one listener. (This section uses "set of Listeners" rather |
| 55 | + than "Listeners in a single Gateway" because implementations MAY |
| 56 | + merge configuration from multiple Gateways onto a single data |
| 57 | + plane, and these rules _also_ apply in that case). Practically, |
| 58 | + this means that each listener in a set MUST have a unique |
| 59 | + combination of Port, Protocol, and, if supported by the protocol, |
| 60 | + Hostname. Some combinations of port, protocol, and TLS settings |
| 61 | + are considered Core support and MUST be supported by |
| 62 | + implementations based on the objects they support: HTTPRoute 1. |
| 63 | + HTTPRoute, Port: 80, Protocol: HTTP 2. HTTPRoute, Port: 443, |
| 64 | + Protocol: HTTPS, TLS Mode: Terminate, TLS keypair provided |
| 65 | + TLSRoute 1. TLSRoute, Port: 443, Protocol: TLS, TLS Mode: |
| 66 | + Passthrough "Distinct" Listeners have the following property: |
| 67 | + **The implementation can match inbound requests to a single |
| 68 | + distinct Listener**. When multiple Listeners share values for |
| 69 | + fields (for example, two Listeners with the same Port value), the |
| 70 | + implementation can match requests to only one of the Listeners |
| 71 | + using other Listener fields. When multiple listeners have the |
| 72 | + same value for the Protocol field, then each of the Listeners with |
| 73 | + matching Protocol values MUST have different values for other |
| 74 | + fields. The set of fields that MUST be different for a Listener |
| 75 | + differs per protocol. The following rules define the rules for |
| 76 | + what fields MUST be considered for Listeners to be distinct with |
| 77 | + each protocol currently defined in the Gateway API spec. The set |
| 78 | + of listeners that all share a protocol value MUST have _different_ |
| 79 | + values for _at least one_ of these fields to be distinct: * |
| 80 | + **HTTP, HTTPS, TLS**: Port, Hostname * **TCP, UDP**: Port One |
| 81 | + **very** important rule to call out involves what happens when an |
| 82 | + implementation: * Supports TCP protocol Listeners, as well as |
| 83 | + HTTP, HTTPS, or TLS protocol Listeners, and * sees HTTP, HTTPS, |
| 84 | + or TLS protocols with the same `port` as one with TCP Protocol. |
| 85 | + In this case all the Listeners that share a port with the TCP |
| 86 | + Listener are not distinct and so MUST NOT be accepted. If an |
| 87 | + implementation does not support TCP Protocol Listeners, then the |
| 88 | + previous rule does not apply, and the TCP Listeners SHOULD NOT be |
| 89 | + accepted. Note that the `tls` field is not used for determining |
| 90 | + if a listener is distinct, because Listeners that _only_ differ on |
| 91 | + TLS config will still conflict in all cases. ### Listeners that |
| 92 | + are distinct only by Hostname When the Listeners are distinct |
| 93 | + based only on Hostname, inbound request hostnames MUST match from |
| 94 | + the most specific to least specific Hostname values to choose the |
| 95 | + correct Listener and its associated set of Routes. Exact matches |
| 96 | + MUST be processed before wildcard matches, and wildcard matches |
| 97 | + MUST be processed before fallback (empty Hostname value) matches. |
| 98 | + For example, `"foo.example.com"` takes precedence over |
| 99 | + `"*.example.com"`, and `"*.example.com"` takes precedence over |
| 100 | + `""`. Additionally, if there are multiple wildcard entries, more |
| 101 | + specific wildcard entries must be processed before less specific |
| 102 | + wildcard entries. For example, `"*.foo.example.com"` takes |
| 103 | + precedence over `"*.example.com"`. The precise definition here is |
| 104 | + that the higher the number of dots in the hostname to the right of |
| 105 | + the wildcard character, the higher the precedence. The wildcard |
| 106 | + character will match any number of characters _and dots_ to the |
| 107 | + left, however, so `"*.example.com"` will match both |
| 108 | + `"foo.bar.example.com"` _and_ `"bar.example.com"`. ## Handling |
| 109 | + indistinct Listeners If a set of Listeners contains Listeners |
| 110 | + that are not distinct, then those Listeners are _Conflicted_, and |
| 111 | + the implementation MUST set the "Conflicted" condition in the |
| 112 | + Listener Status to "True". The words "indistinct" and |
| 113 | + "conflicted" are considered equivalent for the purpose of this |
| 114 | + documentation. Implementations MAY choose to accept a Gateway |
| 115 | + with some Conflicted Listeners only if they only accept the |
| 116 | + partial Listener set that contains no Conflicted Listeners. |
| 117 | + Specifically, an implementation MAY accept a partial Listener set |
| 118 | + subject to the following rules: * The implementation MUST NOT |
| 119 | + pick one conflicting Listener as the winner. ALL indistinct |
| 120 | + Listeners must not be accepted for processing. * At least one |
| 121 | + distinct Listener MUST be present, or else the Gateway effectively |
| 122 | + contains _no_ Listeners, and must be rejected from processing as a |
| 123 | + whole. The implementation MUST set a "ListenersNotValid" |
| 124 | + condition on the Gateway Status when the Gateway contains |
| 125 | + Conflicted Listeners whether or not they accept the Gateway. That |
| 126 | + Condition SHOULD clearly indicate in the Message which Listeners |
| 127 | + are conflicted, and which are Accepted. Additionally, the Listener |
| 128 | + status for those listeners SHOULD indicate which Listeners are |
| 129 | + conflicted and not Accepted. ## General Listener behavior Note |
| 130 | + that, for all distinct Listeners, requests SHOULD match at most |
| 131 | + one Listener. For example, if Listeners are defined for |
| 132 | + "foo.example.com" and "*.example.com", a request to |
| 133 | + "foo.example.com" SHOULD only be routed using routes attached to |
| 134 | + the "foo.example.com" Listener (and not the "*.example.com" |
| 135 | + Listener). This concept is known as "Listener Isolation", and it |
| 136 | + is an Extended feature of Gateway API. Implementations that do not |
| 137 | + support Listener Isolation MUST clearly document this, and MUST |
| 138 | + NOT claim support for the `GatewayHTTPListenerIsolation` feature. |
| 139 | + Implementations that _do_ support Listener Isolation SHOULD claim |
| 140 | + support for the Extended `GatewayHTTPListenerIsolation` feature |
| 141 | + and pass the associated conformance tests. ## Compatible |
| 142 | + Listeners A Gateway's Listeners are considered _compatible_ if: |
| 143 | + 1. They are distinct. 2. The implementation can serve them in |
| 144 | + compliance with the Addresses requirement that all Listeners |
| 145 | + are available on all assigned addresses. Compatible |
| 146 | + combinations in Extended support are expected to vary across |
| 147 | + implementations. A combination that is compatible for one |
| 148 | + implementation may not be compatible for another. For example, an |
| 149 | + implementation that cannot serve both TCP and UDP listeners on the |
| 150 | + same address, or cannot mix HTTPS and generic TLS listens on the |
| 151 | + same port would not consider those cases compatible, even though |
| 152 | + they are distinct. Implementations MAY merge separate Gateways |
| 153 | + onto a single set of Addresses if all Listeners across all |
| 154 | + Gateways are compatible. In a future release the MinItems=1 |
| 155 | + requirement MAY be dropped. Support: Core |
| 156 | +
|
| 157 | + """ |
| 158 | + super().__init__(**kwargs) |
| 159 | + |
| 160 | + self.addresses = addresses |
| 161 | + self.gateway_class_name = gateway_class_name |
| 162 | + self.infrastructure = infrastructure |
| 163 | + self.listeners = listeners |
| 164 | + |
| 165 | + def to_dict(self) -> None: |
| 166 | + super().to_dict() |
| 167 | + |
| 168 | + if not self.kind_dict and not self.yaml_file: |
| 169 | + if self.gateway_class_name is None: |
| 170 | + raise MissingRequiredArgumentError(argument="self.gateway_class_name") |
| 171 | + |
| 172 | + if self.listeners is None: |
| 173 | + raise MissingRequiredArgumentError(argument="self.listeners") |
| 174 | + |
| 175 | + self.res["spec"] = {} |
| 176 | + _spec = self.res["spec"] |
| 177 | + |
| 178 | + _spec["gatewayClassName"] = self.gateway_class_name |
| 179 | + _spec["listeners"] = self.listeners |
| 180 | + |
| 181 | + if self.addresses is not None: |
| 182 | + _spec["addresses"] = self.addresses |
| 183 | + |
| 184 | + if self.infrastructure is not None: |
| 185 | + _spec["infrastructure"] = self.infrastructure |
| 186 | + |
| 187 | + # End of generated code |
0 commit comments