Skip to content

Commit

Permalink
types_generator - get value from the type key (#2041)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnetser authored Aug 15, 2024
1 parent 522c5e5 commit 405a60d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 75 deletions.
6 changes: 3 additions & 3 deletions class_generator/class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,14 @@ def types_generator(key_dict: Dict[str, Any]) -> Dict[str, str]:
if key_dict["type"] == "array":
type_for_docstring = "List[Any]"

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

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

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

if not type_from_dict_for_init:
Expand Down
4 changes: 2 additions & 2 deletions class_generator/tests/manifests/ConfigMap/config_map_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(
self,
binary_data: Optional[Dict[str, Any]] = None,
data: Optional[Dict[str, Any]] = None,
immutable: Optional[Dict[str, Any]] = None,
immutable: Optional[bool] = None,
**kwargs: Any,
) -> None:
"""
Expand All @@ -33,7 +33,7 @@ def __init__(
Data must not overlap with the keys in the BinaryData field, this
is enforced during validation process.
immutable(Dict[str, Any]): Immutable, if set to true, ensures that data stored in the ConfigMap
immutable(bool): Immutable, if set to true, ensures that data stored in the ConfigMap
cannot be updated (only object metadata can be modified). If not
set to true, the field can be modified at any time. Defaulted to
nil.
Expand Down
20 changes: 10 additions & 10 deletions class_generator/tests/manifests/Deployment/deployment_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ class Deployment(NamespacedResource):

def __init__(
self,
min_ready_seconds: Optional[Dict[str, Any]] = None,
paused: Optional[Dict[str, Any]] = None,
progress_deadline_seconds: Optional[Dict[str, Any]] = None,
replicas: Optional[Dict[str, Any]] = None,
revision_history_limit: Optional[Dict[str, Any]] = None,
min_ready_seconds: Optional[int] = None,
paused: Optional[bool] = None,
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,
**kwargs: Any,
) -> None:
"""
Args:
min_ready_seconds(Dict[str, Any]): Minimum number of seconds for which a newly created pod should be
min_ready_seconds(int): Minimum number of seconds for which a newly created pod should be
ready without any of its container crashing, for it to be
considered available. Defaults to 0 (pod will be considered
available as soon as it is ready)
paused(Dict[str, Any]): Indicates that the deployment is paused.
paused(bool): Indicates that the deployment is paused.
progress_deadline_seconds(Dict[str, Any]): The maximum time in seconds for a deployment to make progress before
progress_deadline_seconds(int): The maximum time in seconds for a deployment to make progress before
it is considered to be failed. The deployment controller will
continue to process failed deployments and a condition with a
ProgressDeadlineExceeded reason will be surfaced in the deployment
status. Note that progress will not be estimated during the time a
deployment is paused. Defaults to 600s.
replicas(Dict[str, Any]): Number of desired pods. This is a pointer to distinguish between
replicas(int): Number of desired pods. This is a pointer to distinguish between
explicit zero and not specified. Defaults to 1.
revision_history_limit(Dict[str, Any]): The number of old ReplicaSets to retain to allow rollback. This is a
revision_history_limit(int): The number of old ReplicaSets to retain to allow rollback. This is a
pointer to distinguish between explicit zero and not specified.
Defaults to 10.
Expand Down
88 changes: 44 additions & 44 deletions class_generator/tests/manifests/Pod/pod_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,57 @@ class Pod(NamespacedResource):

def __init__(
self,
active_deadline_seconds: Optional[Dict[str, Any]] = None,
active_deadline_seconds: Optional[int] = None,
affinity: Optional[Dict[str, Any]] = None,
automount_service_account_token: Optional[Dict[str, Any]] = None,
automount_service_account_token: Optional[bool] = None,
containers: Optional[List[Any]] = None,
dns_config: Optional[Dict[str, Any]] = None,
dns_policy: Optional[Dict[str, Any]] = None,
enable_service_links: Optional[Dict[str, Any]] = None,
dns_policy: Optional[str] = "",
enable_service_links: Optional[bool] = None,
ephemeral_containers: Optional[List[Any]] = None,
host_aliases: Optional[List[Any]] = None,
host_ipc: Optional[Dict[str, Any]] = None,
host_network: Optional[Dict[str, Any]] = None,
host_pid: Optional[Dict[str, Any]] = None,
host_users: Optional[Dict[str, Any]] = None,
hostname: Optional[Dict[str, Any]] = None,
host_ipc: Optional[bool] = None,
host_network: Optional[bool] = None,
host_pid: Optional[bool] = None,
host_users: Optional[bool] = None,
hostname: Optional[str] = "",
image_pull_secrets: Optional[List[Any]] = None,
init_containers: Optional[List[Any]] = None,
node_name: Optional[Dict[str, Any]] = None,
node_name: Optional[str] = "",
node_selector: Optional[Dict[str, Any]] = None,
os: Optional[Dict[str, Any]] = None,
overhead: Optional[Dict[str, Any]] = None,
preemption_policy: Optional[Dict[str, Any]] = None,
priority: Optional[Dict[str, Any]] = None,
priority_class_name: Optional[Dict[str, Any]] = None,
preemption_policy: Optional[str] = "",
priority: Optional[int] = None,
priority_class_name: Optional[str] = "",
readiness_gates: Optional[List[Any]] = None,
resource_claims: Optional[List[Any]] = None,
restart_policy: Optional[Dict[str, Any]] = None,
runtime_class_name: Optional[Dict[str, Any]] = None,
scheduler_name: Optional[Dict[str, Any]] = None,
restart_policy: Optional[str] = "",
runtime_class_name: Optional[str] = "",
scheduler_name: Optional[str] = "",
scheduling_gates: Optional[List[Any]] = None,
security_context: Optional[Dict[str, Any]] = None,
service_account: Optional[Dict[str, Any]] = None,
service_account_name: Optional[Dict[str, Any]] = None,
set_hostname_as_fqdn: Optional[Dict[str, Any]] = None,
share_process_namespace: Optional[Dict[str, Any]] = None,
subdomain: Optional[Dict[str, Any]] = None,
termination_grace_period_seconds: Optional[Dict[str, Any]] = None,
service_account: Optional[str] = "",
service_account_name: Optional[str] = "",
set_hostname_as_fqdn: Optional[bool] = None,
share_process_namespace: Optional[bool] = None,
subdomain: Optional[str] = "",
termination_grace_period_seconds: Optional[int] = None,
tolerations: Optional[List[Any]] = None,
topology_spread_constraints: Optional[List[Any]] = None,
volumes: Optional[List[Any]] = None,
**kwargs: Any,
) -> None:
"""
Args:
active_deadline_seconds(Dict[str, Any]): Optional duration in seconds the pod may be active on the node
active_deadline_seconds(int): Optional duration in seconds the pod may be active on the node
relative to StartTime before the system will actively try to mark
it failed and kill associated containers. Value must be a positive
integer.
affinity(Dict[str, Any]): Affinity is a group of affinity scheduling rules.
automount_service_account_token(Dict[str, Any]): AutomountServiceAccountToken indicates whether a service account token
automount_service_account_token(bool): AutomountServiceAccountToken indicates whether a service account token
should be automatically mounted.
containers(List[Any]): List of containers belonging to the pod. Containers cannot currently
Expand All @@ -73,7 +73,7 @@ def __init__(
dns_config(Dict[str, Any]): PodDNSConfig defines the DNS parameters of a pod in addition to those
generated from DNSPolicy.
dns_policy(Dict[str, Any]): Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values
dns_policy(str): Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values
are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or
'None'. DNS parameters given in DNSConfig will be merged with the
policy selected with DNSPolicy. To have DNS options set along with
Expand All @@ -90,7 +90,7 @@ def __init__(
use empty DNS settings. DNS parameters such as nameservers and
search paths should be defined via DNSConfig.
enable_service_links(Dict[str, Any]): EnableServiceLinks indicates whether information about services should
enable_service_links(bool): EnableServiceLinks indicates whether information about services should
be injected into pod's environment variables, matching the syntax
of Docker links. Optional: Defaults to true.
Expand All @@ -104,15 +104,15 @@ def __init__(
host_aliases(List[Any]): HostAliases is an optional list of hosts and IPs that will be injected
into the pod's hosts file if specified.
host_ipc(Dict[str, Any]): Use the host's ipc namespace. Optional: Default to false.
host_ipc(bool): Use the host's ipc namespace. Optional: Default to false.
host_network(Dict[str, Any]): Host networking requested for this pod. Use the host's network
host_network(bool): Host networking requested for this pod. Use the host's network
namespace. If this option is set, the ports that will be used must
be specified. Default to false.
host_pid(Dict[str, Any]): Use the host's pid namespace. Optional: Default to false.
host_pid(bool): Use the host's pid namespace. Optional: Default to false.
host_users(Dict[str, Any]): Use the host's user namespace. Optional: Default to true. If set to
host_users(bool): Use the host's user namespace. Optional: Default to true. If set to
true or not present, the pod will be run in the host user
namespace, useful for when the pod needs a feature only available
to the host user namespace, such as loading a kernel module with
Expand All @@ -123,7 +123,7 @@ def __init__(
field is alpha-level and is only honored by servers that enable
the UserNamespacesSupport feature.
hostname(Dict[str, Any]): Specifies the hostname of the Pod If not specified, the pod's hostname
hostname(str): Specifies the hostname of the Pod If not specified, the pod's hostname
will be set to a system-defined value.
image_pull_secrets(List[Any]): ImagePullSecrets is an optional list of references to secrets in the
Expand All @@ -149,7 +149,7 @@ def __init__(
https://kubernetes.io/docs/concepts/workloads/pods/init-
containers/
node_name(Dict[str, Any]): NodeName is a request to schedule this pod onto a specific node. If it
node_name(str): NodeName is a request to schedule this pod onto a specific node. If it
is non-empty, the scheduler simply schedules this pod onto that
node, assuming that it fits resource requirements.
Expand All @@ -172,20 +172,20 @@ def __init__(
More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-
overhead/README.md
preemption_policy(Dict[str, Any]): PreemptionPolicy is the Policy for preempting pods with lower
preemption_policy(str): PreemptionPolicy is the Policy for preempting pods with lower
priority. One of Never, PreemptLowerPriority. Defaults to
PreemptLowerPriority if unset. Possible enum values: - `"Never"`
means that pod never preempts other pods with lower priority. -
`"PreemptLowerPriority"` means that pod can preempt other pods
with lower priority.
priority(Dict[str, Any]): The priority value. Various system components use this field to find
priority(int): The priority value. Various system components use this field to find
the priority of the pod. When Priority Admission Controller is
enabled, it prevents users from setting this field. The admission
controller populates this field from PriorityClassName. The higher
the value, the higher the priority.
priority_class_name(Dict[str, Any]): If specified, indicates the pod's priority. "system-node-critical" and
priority_class_name(str): If specified, indicates the pod's priority. "system-node-critical" and
"system-cluster-critical" are two special keywords which indicate
the highest priorities with the former being the highest priority.
Any other name must be defined by creating a PriorityClass object
Expand All @@ -204,22 +204,22 @@ def __init__(
This is an alpha field and requires enabling the
DynamicResourceAllocation feature gate. This field is immutable.
restart_policy(Dict[str, Any]): Restart policy for all containers within the pod. One of Always,
restart_policy(str): Restart policy for all containers within the pod. One of Always,
OnFailure, Never. In some contexts, only a subset of those values
may be permitted. Default to Always. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-
lifecycle/#restart-policy Possible enum values: - `"Always"` -
`"Never"` - `"OnFailure"`
runtime_class_name(Dict[str, Any]): RuntimeClassName refers to a RuntimeClass object in the node.k8s.io
runtime_class_name(str): RuntimeClassName refers to a RuntimeClass object in the node.k8s.io
group, which should be used to run this pod. If no RuntimeClass
resource matches the named class, the pod will not be run. If
unset or empty, the "legacy" RuntimeClass will be used, which is
an implicit class with an empty definition that uses the default
runtime handler. More info:
https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class
scheduler_name(Dict[str, Any]): If specified, the pod will be dispatched by specified scheduler. If
scheduler_name(str): If specified, the pod will be dispatched by specified scheduler. If
not specified, the pod will be dispatched by default scheduler.
scheduling_gates(List[Any]): SchedulingGates is an opaque list of values that if specified will
Expand All @@ -234,14 +234,14 @@ def __init__(
container.securityContext take precedence over field values of
PodSecurityContext.
service_account(Dict[str, Any]): DeprecatedServiceAccount is a deprecated alias for ServiceAccountName.
service_account(str): DeprecatedServiceAccount is a deprecated alias for ServiceAccountName.
Deprecated: Use serviceAccountName instead.
service_account_name(Dict[str, Any]): ServiceAccountName is the name of the ServiceAccount to use to run
service_account_name(str): ServiceAccountName is the name of the ServiceAccount to use to run
this pod. More info: https://kubernetes.io/docs/tasks/configure-
pod-container/configure-service-account/
set_hostname_as_fqdn(Dict[str, Any]): If true the pod's hostname will be configured as the pod's FQDN,
set_hostname_as_fqdn(bool): If true the pod's hostname will be configured as the pod's FQDN,
rather than the leaf name (the default). In Linux containers, this
means setting the FQDN in the hostname field of the kernel (the
nodename field of struct utsname). In Windows containers, this
Expand All @@ -250,18 +250,18 @@ def __init__(
ers to FQDN. If a pod does not have FQDN, this has no effect.
Default to false.
share_process_namespace(Dict[str, Any]): Share a single process namespace between all of the containers in a
share_process_namespace(bool): Share a single process namespace between all of the containers in a
pod. When this is set containers will be able to view and signal
processes from other containers in the same pod, and the first
process in each container will not be assigned PID 1. HostPID and
ShareProcessNamespace cannot both be set. Optional: Default to
false.
subdomain(Dict[str, Any]): If specified, the fully qualified Pod hostname will be
subdomain(str): If specified, the fully qualified Pod hostname will be
"<hostname>.<subdomain>.<pod namespace>.svc.<cluster domain>". If
not specified, the pod will not have a domainname at all.
termination_grace_period_seconds(Dict[str, Any]): Optional duration in seconds the pod needs to terminate gracefully.
termination_grace_period_seconds(int): Optional duration in seconds the pod needs to terminate gracefully.
May be decreased in delete request. Value must be non-negative
integer. The value zero indicates stop immediately via the kill
signal (no opportunity to shut down). If this value is nil, the
Expand Down
8 changes: 4 additions & 4 deletions class_generator/tests/manifests/Secret/secret_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Secret(NamespacedResource):
def __init__(
self,
data: Optional[Dict[str, Any]] = None,
immutable: Optional[Dict[str, Any]] = None,
immutable: Optional[bool] = None,
string_data: Optional[Dict[str, Any]] = None,
type: Optional[Dict[str, Any]] = None,
type: Optional[str] = "",
**kwargs: Any,
) -> None:
"""
Expand All @@ -27,7 +27,7 @@ def __init__(
(possibly non-string) data value here. Described in
https://tools.ietf.org/html/rfc4648#section-4
immutable(Dict[str, Any]): Immutable, if set to true, ensures that data stored in the Secret
immutable(bool): Immutable, if set to true, ensures that data stored in the Secret
cannot be updated (only object metadata can be modified). If not
set to true, the field can be modified at any time. Defaulted to
nil.
Expand All @@ -38,7 +38,7 @@ def __init__(
any existing values. The stringData field is never output when
reading from the API.
type(Dict[str, Any]): Used to facilitate programmatic handling of secret data. More info:
type(str): Used to facilitate programmatic handling of secret data. More info:
https://kubernetes.io/docs/concepts/configuration/secret/#secret-
types
Expand Down
Loading

0 comments on commit 405a60d

Please sign in to comment.