Skip to content

Commit

Permalink
Update resources with multiple api groups and use get for type an…
Browse files Browse the repository at this point in the history
…d `description` (RedHatQE#2067)

* Update resources with multiple api groups

* Update resources with multiple api groups

* replace unknown with Any

* update docstring

* deprectae nmestate
  • Loading branch information
rnetser authored Aug 22, 2024
1 parent 8e66461 commit f9d0ec4
Show file tree
Hide file tree
Showing 19 changed files with 712 additions and 789 deletions.
26 changes: 15 additions & 11 deletions class_generator/class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,23 @@ def generate_resource_file_from_dict(


def types_generator(key_dict: Dict[str, Any]) -> Dict[str, str]:
type_for_docstring: str = "Dict[str, Any]"
type_for_docstring: str = "Any"
type_from_dict_for_init: str = ""
# A resource field may be defined with `x-kubernetes-preserve-unknown-fields`. In this case, `type` is not provided.
resource_type = key_dict.get("type")

# All fields must be set with Optional since resource can have yaml_file to cover all args.
if key_dict["type"] == "array":
if resource_type == "array":
type_for_docstring = "List[Any]"

elif key_dict["type"] == "string":
elif resource_type == "string":
type_for_docstring = "str"
type_from_dict_for_init = f'Optional[{type_for_docstring}] = ""'

elif key_dict["type"] == "boolean":
elif resource_type == "boolean":
type_for_docstring = "bool"

elif key_dict["type"] == "integer":
elif resource_type == "integer":
type_for_docstring = "int"

if not type_from_dict_for_init:
Expand All @@ -389,11 +391,11 @@ def types_generator(key_dict: Dict[str, Any]) -> Dict[str, str]:
return {"type-for-init": type_from_dict_for_init, "type-for-doc": type_for_docstring}


def get_property_schema(property: Dict[str, Any]) -> Dict[str, Any]:
if _ref := property.get("$ref"):
def get_property_schema(property_: Dict[str, Any]) -> Dict[str, Any]:
if _ref := property_.get("$ref"):
with open(f"{SCHEMA_DIR}/{_ref.rsplit('.')[-1].lower()}.json") as fd:
return json.load(fd)
return property
return property_


def format_description(description: str) -> str:
Expand All @@ -419,14 +421,16 @@ def prepare_property_dict(
if key in keys_to_ignore:
continue

val_schema = get_property_schema(property=val)
val_schema = get_property_schema(property_=val)
type_dict = types_generator(key_dict=val_schema)
python_name = convert_camel_case_to_snake_case(string_=key)
resource_dict[dict_key].append({
"name-for-class-arg": python_name,
"property-name": key,
"required": key in required,
"description": format_description(description=val_schema["description"]),
"description": format_description(
description=val_schema.get("description", "No field description from API; please add description")
),
"type-for-docstring": type_dict["type-for-doc"],
"type-for-class-arg": f"{python_name}: {type_dict['type-for-init']}",
})
Expand Down Expand Up @@ -455,7 +459,7 @@ def parse_explain(
resource_dict.update(_kind_schema["x-kubernetes-group-version-kind"][0])

if spec_schema := schema_properties.get("spec", {}):
spec_schema = get_property_schema(property=spec_schema)
spec_schema = get_property_schema(property_=spec_schema)
spec_required = spec_schema.get("required", [])
resource_dict = prepare_property_dict(
schema=spec_schema.get("properties", {}),
Expand Down
22 changes: 11 additions & 11 deletions class_generator/tests/manifests/APIServer/api_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, List, Optional
from typing import Any, List, Optional
from ocp_resources.resource import Resource


Expand All @@ -15,11 +15,11 @@ class APIServer(Resource):
def __init__(
self,
additional_cors_allowed_origins: Optional[List[Any]] = None,
audit: Optional[Dict[str, Any]] = None,
client_ca: Optional[Dict[str, Any]] = None,
encryption: Optional[Dict[str, Any]] = None,
serving_certs: Optional[Dict[str, Any]] = None,
tls_security_profile: Optional[Dict[str, Any]] = None,
audit: Optional[Any] = None,
client_ca: Optional[Any] = None,
encryption: Optional[Any] = None,
serving_certs: Optional[Any] = None,
tls_security_profile: Optional[Any] = None,
**kwargs: Any,
) -> None:
"""
Expand All @@ -31,10 +31,10 @@ def __init__(
The values are regular expressions that correspond to the Golang
regular expression language.
audit(Dict[str, Any]): audit specifies the settings for audit configuration to be applied to
audit(Any): audit specifies the settings for audit configuration to be applied to
all OpenShift-provided API servers in the cluster.
client_ca(Dict[str, Any]): clientCA references a ConfigMap containing a certificate bundle for
client_ca(Any): clientCA references a ConfigMap containing a certificate bundle for
the signers that will be recognized for incoming client
certificates in addition to the operator managed signers. If this
is empty, then only operator managed signers are valid. You
Expand All @@ -43,14 +43,14 @@ def __init__(
openshift-config namespace and contain the following required
fields: - ConfigMap.Data["ca-bundle.crt"] - CA bundle.
encryption(Dict[str, Any]): encryption allows the configuration of encryption of resources at the
encryption(Any): encryption allows the configuration of encryption of resources at the
datastore layer.
serving_certs(Dict[str, Any]): servingCert is the TLS cert info for serving secure traffic. If not
serving_certs(Any): servingCert is the TLS cert info for serving secure traffic. If not
specified, operator managed certificates will be used for serving
secure traffic.
tls_security_profile(Dict[str, Any]): tlsSecurityProfile specifies settings for TLS connections for
tls_security_profile(Any): tlsSecurityProfile specifies settings for TLS connections for
externally exposed servers. If unset, a default (which may
change between releases) is chosen. Note that only Old,
Intermediate and Custom profiles are currently supported, and the
Expand Down
10 changes: 5 additions & 5 deletions class_generator/tests/manifests/ConfigMap/config_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, Optional
from typing import Any, Optional
from ocp_resources.resource import NamespacedResource


Expand All @@ -13,21 +13,21 @@ class ConfigMap(NamespacedResource):

def __init__(
self,
binary_data: Optional[Dict[str, Any]] = None,
data: Optional[Dict[str, Any]] = None,
binary_data: Optional[Any] = None,
data: Optional[Any] = None,
immutable: Optional[bool] = None,
**kwargs: Any,
) -> None:
"""
Args:
binary_data(Dict[str, Any]): BinaryData contains the binary data. Each key must consist of
binary_data(Any): BinaryData contains the binary data. Each key must consist of
alphanumeric characters, '-', '_' or '.'. BinaryData can contain
byte sequences that are not in the UTF-8 range. The keys stored in
BinaryData must not overlap with the ones in the Data field, this
is enforced during validation process. Using this field will
require 1.10+ apiserver and kubelet.
data(Dict[str, Any]): Data contains the configuration data. Each key must consist of
data(Any): Data contains the configuration data. Each key must consist of
alphanumeric characters, '-', '_' or '.'. Values with non-UTF-8
byte sequences must use the BinaryData field. The keys stored in
Data must not overlap with the keys in the BinaryData field, this
Expand Down
14 changes: 7 additions & 7 deletions class_generator/tests/manifests/DNS/dns_config_openshift_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, Optional
from typing import Any, Optional
from ocp_resources.resource import Resource


Expand All @@ -15,9 +15,9 @@ class DNS(Resource):
def __init__(
self,
base_domain: Optional[str] = "",
platform: Optional[Dict[str, Any]] = None,
private_zone: Optional[Dict[str, Any]] = None,
public_zone: Optional[Dict[str, Any]] = None,
platform: Optional[Any] = None,
private_zone: Optional[Any] = None,
public_zone: Optional[Any] = None,
**kwargs: Any,
) -> None:
"""
Expand All @@ -28,17 +28,17 @@ def __init__(
created for `cluster-api.openshift.example.com`. Once set, this
field cannot be changed.
platform(Dict[str, Any]): platform holds configuration specific to the underlying infrastructure
platform(Any): platform holds configuration specific to the underlying infrastructure
provider for DNS. When omitted, this means the user has no opinion
and the platform is left to choose reasonable defaults. These
defaults are subject to change over time.
private_zone(Dict[str, Any]): privateZone is the location where all the DNS records that are only
private_zone(Any): privateZone is the location where all the DNS records that are only
available internally to the cluster exist. If this field is nil,
no private records should be created. Once set, this field
cannot be changed.
public_zone(Dict[str, Any]): publicZone is the location where all the DNS records that are publicly
public_zone(Any): publicZone is the location where all the DNS records that are publicly
accessible to the internet exist. If this field is nil, no
public records should be created. Once set, this field cannot be
changed.
Expand Down
14 changes: 7 additions & 7 deletions class_generator/tests/manifests/DNS/dns_operator_openshift_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, List, Optional
from typing import Any, List, Optional
from ocp_resources.resource import Resource


Expand All @@ -16,18 +16,18 @@ class DNS(Resource):

def __init__(
self,
cache: Optional[Dict[str, Any]] = None,
cache: Optional[Any] = None,
log_level: Optional[str] = "",
management_state: Optional[str] = "",
node_placement: Optional[Dict[str, Any]] = None,
node_placement: Optional[Any] = None,
operator_log_level: Optional[str] = "",
servers: Optional[List[Any]] = None,
upstream_resolvers: Optional[Dict[str, Any]] = None,
upstream_resolvers: Optional[Any] = None,
**kwargs: Any,
) -> None:
"""
Args:
cache(Dict[str, Any]): cache describes the caching configuration that applies to all server
cache(Any): cache describes the caching configuration that applies to all server
blocks listed in the Corefile. This field allows a cluster admin
to optionally configure: * positiveTTL which is a duration for
which positive responses should be cached. * negativeTTL which is
Expand All @@ -48,7 +48,7 @@ def __init__(
management_state(str): managementState indicates whether the DNS operator should manage
cluster DNS
node_placement(Dict[str, Any]): nodePlacement provides explicit control over the scheduling of DNS
node_placement(Any): nodePlacement provides explicit control over the scheduling of DNS
pods. Generally, it is useful to run a DNS pod on every node so
that DNS queries are always handled by a local DNS pod instead of
going over the network to a DNS pod on another node. However,
Expand All @@ -75,7 +75,7 @@ def __init__(
routed to the Server with Zone "a.foo.com". If this field is
nil, no servers are created.
upstream_resolvers(Dict[str, Any]): upstreamResolvers defines a schema for configuring CoreDNS to proxy
upstream_resolvers(Any): upstreamResolvers defines a schema for configuring CoreDNS to proxy
DNS messages to upstream resolvers for the case of the default
(".") server If this field is not specified, the upstream used
will default to /etc/resolv.conf, with policy "sequential"
Expand Down
14 changes: 7 additions & 7 deletions class_generator/tests/manifests/Deployment/deployment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, Optional
from typing import Any, Optional
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError


Expand All @@ -18,9 +18,9 @@ def __init__(
progress_deadline_seconds: Optional[int] = None,
replicas: Optional[int] = None,
revision_history_limit: Optional[int] = None,
selector: Optional[Dict[str, Any]] = None,
strategy: Optional[Dict[str, Any]] = None,
template: Optional[Dict[str, Any]] = None,
selector: Optional[Any] = None,
strategy: Optional[Any] = None,
template: Optional[Any] = None,
**kwargs: Any,
) -> None:
"""
Expand All @@ -46,15 +46,15 @@ def __init__(
pointer to distinguish between explicit zero and not specified.
Defaults to 10.
selector(Dict[str, Any]): A label selector is a label query over a set of resources. The result
selector(Any): A label selector is a label query over a set of resources. The result
of matchLabels and matchExpressions are ANDed. An empty label
selector matches all objects. A null label selector matches no
objects.
strategy(Dict[str, Any]): DeploymentStrategy describes how to replace existing pods with new
strategy(Any): DeploymentStrategy describes how to replace existing pods with new
ones.
template(Dict[str, Any]): PodTemplateSpec describes the data a pod should have when created from
template(Any): PodTemplateSpec describes the data a pod should have when created from
a template
"""
Expand Down
14 changes: 7 additions & 7 deletions class_generator/tests/manifests/Machine/machine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, List, Optional
from typing import Any, List, Optional
from ocp_resources.resource import NamespacedResource


Expand All @@ -13,19 +13,19 @@ class Machine(NamespacedResource):

def __init__(
self,
lifecycle_hooks: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict[str, Any]] = None,
lifecycle_hooks: Optional[Any] = None,
metadata: Optional[Any] = None,
provider_id: Optional[str] = "",
provider_spec: Optional[Dict[str, Any]] = None,
provider_spec: Optional[Any] = None,
taints: Optional[List[Any]] = None,
**kwargs: Any,
) -> None:
"""
Args:
lifecycle_hooks(Dict[str, Any]): LifecycleHooks allow users to pause operations on the machine at
lifecycle_hooks(Any): LifecycleHooks allow users to pause operations on the machine at
certain predefined points within the machine lifecycle.
metadata(Dict[str, Any]): ObjectMeta will autopopulate the Node created. Use this to indicate
metadata(Any): ObjectMeta will autopopulate the Node created. Use this to indicate
what labels, annotations, name prefix, etc., should be used when
creating the Node.
Expand All @@ -45,7 +45,7 @@ def __init__(
autoscaler that will be interfacing with cluster-api as generic
provider.
provider_spec(Dict[str, Any]): ProviderSpec details Provider-specific configuration to use during
provider_spec(Any): ProviderSpec details Provider-specific configuration to use during
node creation.
taints(List[Any]): The list of the taints to be applied to the corresponding Node in
Expand Down
22 changes: 11 additions & 11 deletions class_generator/tests/manifests/NMState/nm_state.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md

from typing import Any, Dict, List, Optional
from typing import Any, List, Optional
from ocp_resources.resource import Resource


Expand All @@ -13,24 +13,24 @@ class NMState(Resource):

def __init__(
self,
affinity: Optional[Dict[str, Any]] = None,
infra_affinity: Optional[Dict[str, Any]] = None,
infra_node_selector: Optional[Dict[str, Any]] = None,
affinity: Optional[Any] = None,
infra_affinity: Optional[Any] = None,
infra_node_selector: Optional[Any] = None,
infra_tolerations: Optional[List[Any]] = None,
node_selector: Optional[Dict[str, Any]] = None,
self_sign_configuration: Optional[Dict[str, Any]] = None,
node_selector: Optional[Any] = None,
self_sign_configuration: Optional[Any] = None,
tolerations: Optional[List[Any]] = None,
**kwargs: Any,
) -> None:
"""
Args:
affinity(Dict[str, Any]): Affinity is an optional affinity selector that will be added to
affinity(Any): Affinity is an optional affinity selector that will be added to
handler DaemonSet manifest.
infra_affinity(Dict[str, Any]): Affinity is an optional affinity selector that will be added to
infra_affinity(Any): Affinity is an optional affinity selector that will be added to
webhook & certmanager Deployment manifests.
infra_node_selector(Dict[str, Any]): InfraNodeSelector is an optional selector that will be added to
infra_node_selector(Any): InfraNodeSelector is an optional selector that will be added to
webhook & certmanager Deployment manifests If InfraNodeSelector is
specified, the webhook and certmanager will run only on nodes that
have each of the indicated key-value pairs as labels applied to
Expand All @@ -41,14 +41,14 @@ def __init__(
specified, the webhook and certmanager will be able to be
scheduled on nodes with corresponding taints
node_selector(Dict[str, Any]): NodeSelector is an optional selector that will be added to handler
node_selector(Any): NodeSelector is an optional selector that will be added to handler
DaemonSet manifest for both workers and control-plane
(https://github.com/nmstate/kubernetes-
nmstate/blob/main/deploy/handler/operator.yaml). If NodeSelector
is specified, the handler will run only on nodes that have each of
the indicated key-value pairs as labels applied to the node.
self_sign_configuration(Dict[str, Any]): SelfSignConfiguration defines self signed certificate configuration
self_sign_configuration(Any): SelfSignConfiguration defines self signed certificate configuration
tolerations(List[Any]): Tolerations is an optional list of tolerations to be added to handler
DaemonSet manifest If Tolerations is specified, the handler
Expand Down
Loading

0 comments on commit f9d0ec4

Please sign in to comment.