Skip to content

Commit f4a5702

Browse files
authored
Merge pull request #4 from RedHatQE/main
[pull] main from RedHatQE:main
2 parents 19881f1 + 1cb8bba commit f4a5702

File tree

11 files changed

+481
-83
lines changed

11 files changed

+481
-83
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ If a related issue doesn't exist, you can open a new issue using a relevant [iss
2020
To contribute code to the project:
2121

2222
- Fork the project and work on your forked repository
23-
- Before submitting a new pull request, make sure you have `pre-commit` installed
23+
- Before submitting a new pull request, make sure you have `prek` installed
2424

2525
```bash
26-
pre-commit install
26+
prek install
2727
```
2828

2929
- When submitting a pull request, make sure to fill all the required, relevant fields for your PR.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ export HTTP_PROXY="http://proxy.example.com:8080"
123123

124124
## Code check
125125

126-
We use pre-commit for code check.
126+
We use [prek](https://github.com/j178/prek) for code check.
127127

128128
```bash
129-
pre-commit install
129+
prek install
130130
```
131131

132132
Some code examples locate at [examples](examples) directory

class_generator/formatters/file_writer.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def write_and_format_rendered(filepath: str, output: str) -> None:
1010
"""
11-
Write rendered content to file and format it with pre-commit.
11+
Write rendered content to file and format it with prek.
1212
1313
Args:
1414
filepath: Path to write the file to
@@ -17,24 +17,20 @@ def write_and_format_rendered(filepath: str, output: str) -> None:
1717
with open(filepath, "w", encoding="utf-8") as fd:
1818
fd.write(output)
1919

20-
# Run pre-commit on the file
20+
# Run prek on the file
2121
try:
2222
rc, stdout, stderr = run_command(
23-
command=["uvx", "pre-commit", "run", "--files", filepath],
23+
command=["uvx", "prek", "run", "--files", filepath],
2424
verify_stderr=False,
2525
check=False,
2626
log_errors=False,
2727
)
2828
if not rc:
2929
if stderr:
30-
LOGGER.warning(
31-
f"Pre-commit hooks failed for {filepath}. This is non-fatal and generation will continue."
32-
)
33-
LOGGER.debug(f"Pre-commit stderr: {stderr}")
30+
LOGGER.warning(f"Prek hooks failed for {filepath}. This is non-fatal and generation will continue.")
31+
LOGGER.debug(f"prek stderr: {stderr}")
3432
if stdout:
35-
LOGGER.info(f"{filepath} fixed by pre-commit")
36-
LOGGER.debug(f"Pre-commit stdout: {stdout}")
33+
LOGGER.info(f"{filepath} fixed by prek")
34+
LOGGER.debug(f"rek stdout: {stdout}")
3735
except Exception as e:
38-
LOGGER.error(
39-
f"Failed to run pre-commit hooks for {filepath}: {e}. This is non-fatal and generation will continue."
40-
)
36+
LOGGER.error(f"Failed to run prek hooks for {filepath}: {e}. This is non-fatal and generation will continue.")

ocp_resources/gateway_class.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 Resource
6+
from ocp_resources.exceptions import MissingRequiredArgumentError
7+
8+
9+
class GatewayClass(Resource):
10+
"""
11+
GatewayClass describes a class of Gateways available to the user for creating
12+
Gateway resources.
13+
14+
It is recommended that this resource be used as a template for Gateways. This
15+
means that a Gateway is based on the state of the GatewayClass at the time it
16+
was created and changes to the GatewayClass or associated parameters are not
17+
propagated down to existing Gateways. This recommendation is intended to
18+
limit the blast radius of changes to GatewayClass or associated parameters.
19+
If implementations choose to propagate GatewayClass changes to existing
20+
Gateways, that MUST be clearly documented by the implementation.
21+
22+
Whenever one or more Gateways are using a GatewayClass, implementations SHOULD
23+
add the `gateway-exists-finalizer.gateway.networking.k8s.io` finalizer on the
24+
associated GatewayClass. This ensures that a GatewayClass associated with a
25+
Gateway is not deleted while in use.
26+
27+
GatewayClass is a Cluster level resource.
28+
"""
29+
30+
api_group: str = Resource.ApiGroup.GATEWAY_NETWORKING_K8S_IO
31+
32+
def __init__(
33+
self,
34+
controller_name: str | None = None,
35+
description: str | None = None,
36+
parameters_ref: dict[str, Any] | None = None,
37+
**kwargs: Any,
38+
) -> None:
39+
r"""
40+
Args:
41+
controller_name (str): ControllerName is the name of the controller that is managing Gateways
42+
of this class. The value of this field MUST be a domain prefixed
43+
path. Example: "example.net/gateway-controller". This field is
44+
not mutable and cannot be empty. Support: Core
45+
46+
description (str): Description helps describe a GatewayClass with more details.
47+
48+
parameters_ref (dict[str, Any]): ParametersRef is a reference to a resource that contains the
49+
configuration parameters corresponding to the GatewayClass. This
50+
is optional if the controller does not require any additional
51+
configuration. ParametersRef can reference a standard Kubernetes
52+
resource, i.e. ConfigMap, or an implementation-specific custom
53+
resource. The resource can be cluster-scoped or namespace-scoped.
54+
If the referent cannot be found, refers to an unsupported kind, or
55+
when the data within that resource is malformed, the GatewayClass
56+
SHOULD be rejected with the "Accepted" status condition set to
57+
"False" and an "InvalidParameters" reason. A Gateway for this
58+
GatewayClass may provide its own `parametersRef`. When both are
59+
specified, the merging behavior is implementation specific. It is
60+
generally recommended that GatewayClass provides defaults that can
61+
be overridden by a Gateway. Support: Implementation-specific
62+
63+
"""
64+
super().__init__(**kwargs)
65+
66+
self.controller_name = controller_name
67+
self.description = description
68+
self.parameters_ref = parameters_ref
69+
70+
def to_dict(self) -> None:
71+
super().to_dict()
72+
73+
if not self.kind_dict and not self.yaml_file:
74+
if self.controller_name is None:
75+
raise MissingRequiredArgumentError(argument="self.controller_name")
76+
77+
self.res["spec"] = {}
78+
_spec = self.res["spec"]
79+
80+
_spec["controllerName"] = self.controller_name
81+
82+
if self.description is not None:
83+
_spec["description"] = self.description
84+
85+
if self.parameters_ref is not None:
86+
_spec["parametersRef"] = self.parameters_ref
87+
88+
# End of generated code
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
7+
8+
class Gateway(NamespacedResource):
9+
"""
10+
No field description from API
11+
"""
12+
13+
api_group: str = NamespacedResource.ApiGroup.NETWORKING_ISTIO_IO
14+
15+
def __init__(
16+
self,
17+
selector: dict[str, Any] | None = None,
18+
servers: list[Any] | None = None,
19+
**kwargs: Any,
20+
) -> None:
21+
r"""
22+
Args:
23+
selector (dict[str, Any]): No field description from API
24+
25+
servers (list[Any]): A list of server specifications.
26+
27+
"""
28+
super().__init__(**kwargs)
29+
30+
self.selector = selector
31+
self.servers = servers
32+
33+
def to_dict(self) -> None:
34+
super().to_dict()
35+
36+
if not self.kind_dict and not self.yaml_file:
37+
self.res["spec"] = {}
38+
_spec = self.res["spec"]
39+
40+
if self.selector is not None:
41+
_spec["selector"] = self.selector
42+
43+
if self.servers is not None:
44+
_spec["servers"] = self.servers
45+
46+
# End of generated code

0 commit comments

Comments
 (0)