Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Add type annotations to overlays #1259

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions provider/pkg/gen/python-templates/apiextensions/CustomResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import warnings
from typing import Any, Optional

import pulumi
import pulumi.runtime
Expand All @@ -11,8 +12,15 @@


class CustomResource(pulumi.CustomResource):
def __init__(self, resource_name, api_version, kind, spec=None, metadata=None, opts=None,
__name__=None, __opts__=None):
def __init__(self,
resource_name: str,
api_version: str,
kind: str,
spec: Optional[pulumi.Input[Any]] = None,
metadata: Optional[pulumi.Input[Any]] = None,
opts: Optional[pulumi.ResourceOptions] = None,
__name__=None,
Comment on lines +21 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just here to complain about the discrepancy in python's whitespacing convention when there's a type annotation + default value vs. just a default value. Thanks 🐍

__opts__=None):
"""
CustomResource represents an instance of a CustomResourceDefinition (CRD). For example, the
CoreOS Prometheus operator exposes a CRD `monitoring.coreos.com/ServiceMonitor`; to
Expand All @@ -25,7 +33,7 @@ def __init__(self, resource_name, api_version, kind, spec=None, metadata=None, o
API server.
:param str kind: The kind of the apiextensions.CustomResource we wish to select,
as specified by the CustomResourceDefinition that defines it on the API server.
:param pulumi.Input[Any] spec: Specification of the CustomResource.
:param Optional[pulumi.Input[Any]] spec: Specification of the CustomResource.
:param Optional[pulumi.Input[Any]] metadata: Standard object metadata; More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
:param Optional[pulumi.ResourceOptions] opts: A bag of options that control this
Expand Down Expand Up @@ -60,7 +68,11 @@ def __init__(self, resource_name, api_version, kind, spec=None, metadata=None, o
opts)

@staticmethod
def get(resource_name, api_version, kind, id, opts=None):
def get(resource_name: str,
api_version: str,
kind: str,
id: pulumi.Input[str],
opts: Optional[pulumi.ResourceOptions] = None):
"""
Get the state of an existing `CustomResource` resource, as identified by `id`.
Typically this ID is of the form [namespace]/[name]; if [namespace] is omitted,
Expand Down
55 changes: 45 additions & 10 deletions provider/pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class Chart(pulumi.ComponentResource):
Kubernetes resources contained in this Chart.
"""

def __init__(self, release_name, config, opts=None):
def __init__(self,
release_name: str,
config: Union['ChartOpts', 'LocalChartOpts'],
opts: Optional[pulumi.ResourceOptions] = None):
"""
Chart is a component representing a collection of resources described by an arbitrary Helm
Chart. The Chart can be fetched from any source that is accessible to the `helm` command
Expand Down Expand Up @@ -183,14 +186,17 @@ def omit_resource(obj, opts):
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})

def get_resource(self, group_version_kind, name, namespace=None) -> pulumi.Output[pulumi.CustomResource]:
def get_resource(self,
group_version_kind: str,
name: str,
namespace: Optional[str] = None) -> pulumi.Output[pulumi.CustomResource]:
"""
get_resource returns a resource defined by a built-in Kubernetes group/version/kind and
name. For example: `get_resource("apps/v1/Deployment", "nginx")`

:param str group_version_kind: Group/Version/Kind of the resource, e.g., `apps/v1/Deployment`
:param str name: Name of the resource to retrieve
:param str namespace: Optional namespace of the resource to retrieve
:param Optional[str] namespace: Optional namespace of the resource to retrieve
"""

# `id` will either be `${name}` or `${namespace}/${name}`.
Expand Down Expand Up @@ -285,9 +291,22 @@ class FetchOpts:
Verify the package against its signature.
"""

def __init__(self, version=None, ca_file=None, cert_file=None, key_file=None, destination=None, keyring=None,
password=None, repo=None, untar_dir=None, username=None, home=None, devel=None, prov=None,
untar=None, verify=None):
def __init__(self,
version: Optional[pulumi.Input[str]] = None,
ca_file: Optional[pulumi.Input[str]] = None,
cert_file: Optional[pulumi.Input[str]] = None,
key_file: Optional[pulumi.Input[str]] = None,
destination: Optional[pulumi.Input[str]] = None,
keyring: Optional[pulumi.Input[str]] = None,
password: Optional[pulumi.Input[str]] = None,
repo: Optional[pulumi.Input[str]] = None,
untar_dir: Optional[pulumi.Input[str]] = None,
username: Optional[pulumi.Input[str]] = None,
home: Optional[pulumi.Input[str]] = None,
devel: Optional[pulumi.Input[bool]] = None,
prov: Optional[pulumi.Input[bool]] = None,
untar: Optional[pulumi.Input[bool]] = None,
verify: Optional[pulumi.Input[bool]] = None):
"""
:param Optional[pulumi.Input[str]] version: Specific version of a chart. If unset,
the latest version is fetched.
Expand Down Expand Up @@ -362,7 +381,11 @@ class BaseChartOpts:
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

def __init__(self, namespace=None, values=None, transformations=None, resource_prefix=None):
def __init__(self,
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[pulumi.Inputs] = None,
resource_prefix: Optional[str] = None):
"""
:param Optional[pulumi.Input[str]] namespace: Optional namespace to install chart resources into.
:param Optional[pulumi.Inputs] values: Optional overrides for chart values.
Expand Down Expand Up @@ -406,8 +429,15 @@ class ChartOpts(BaseChartOpts):
Additional options to customize the fetching of the Helm chart.
"""

def __init__(self, chart, namespace=None, values=None, transformations=None, resource_prefix=None, repo=None,
version=None, fetch_opts=None):
def __init__(self,
chart: pulumi.Input[str],
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[pulumi.Inputs] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be more specific here? The docstring looks a bit different than this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Copy/paste mistake. Will fix.

resource_prefix: Optional[str] = None,
repo: Optional[pulumi.Input[str]] = None,
version: Optional[pulumi.Input[str]] = None,
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None):
"""
:param pulumi.Input[str] chart: The name of the chart to deploy. If `repo` is provided, this chart name
will be prefixed by the repo name.
Expand Down Expand Up @@ -444,7 +474,12 @@ class LocalChartOpts(BaseChartOpts):
The path to the chart directory which contains the `Chart.yaml` file.
"""

def __init__(self, path, namespace=None, values=None, transformations=None, resource_prefix=None):
def __init__(self,
path: pulumi.Input[str],
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[pulumi.Inputs] = None,
resource_prefix: Optional[str] = None):
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
Expand Down
16 changes: 13 additions & 3 deletions provider/pkg/gen/python-templates/kustomize/kustomize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

from typing import Callable, List, Optional, Tuple

import pulumi.runtime
import pulumi_kubernetes as k8s

Expand All @@ -15,7 +17,12 @@ class Directory(pulumi.ComponentResource):
Kubernetes resources contained in this Directory.
"""

def __init__(self, name, directory, opts=None, transformations=None, resource_prefix=None):
def __init__(self,
name: str,
directory: str,
opts: Optional[pulumi.ResourceOptions] = None,
transformations: Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] = None,
resource_prefix: Optional[str] = None):
"""
Directory is a component representing a collection of resources described by a kustomize directory
(kustomization).
Expand Down Expand Up @@ -121,14 +128,17 @@ def translate_output_property(self, prop: str) -> str:
def translate_input_property(self, prop: str) -> str:
return _tables.SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop

def get_resource(self, group_version_kind, name, namespace=None) -> pulumi.Output[pulumi.CustomResource]:
def get_resource(self,
group_version_kind: str,
name: str,
namespace: Optional[str] = None) -> pulumi.Output[pulumi.CustomResource]:
"""
get_resource returns a resource defined by a built-in Kubernetes group/version/kind and
name. For example: `get_resource("apps/v1/Deployment", "nginx")`

:param str group_version_kind: Group/Version/Kind of the resource, e.g., `apps/v1/Deployment`
:param str name: Name of the resource to retrieve
:param str namespace: Optional namespace of the resource to retrieve
:param Optional[str] namespace: Optional namespace of the resource to retrieve
"""

# `id` will either be `${name}` or `${namespace}/${name}`.
Expand Down
32 changes: 25 additions & 7 deletions provider/pkg/gen/python-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class ConfigGroup(pulumi.ComponentResource):
Kubernetes resources contained in this ConfigGroup.
"""

def __init__(self, name, files=None, yaml=None, opts=None, transformations=None, resource_prefix=None):
def __init__(self,
name: str,
files: Optional[List[str]] = None,
yaml: Optional[List[str]] = None,
opts: Optional[pulumi.ResourceOptions] = None,
transformations: Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] = None,
resource_prefix: Optional[str] = None):
"""
ConfigGroup creates a set of Kubernetes resources from Kubernetes YAML text. The YAML text
may be supplied using any of the following methods:
Expand Down Expand Up @@ -194,14 +200,17 @@ class ConfigGroup(pulumi.ComponentResource):
def translate_input_property(self, prop: str) -> str:
return _tables.SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop

def get_resource(self, group_version_kind, name, namespace=None) -> pulumi.Output[pulumi.CustomResource]:
def get_resource(self,
group_version_kind: str,
name: str,
namespace: Optional[str] = None) -> pulumi.Output[pulumi.CustomResource]:
"""
get_resource returns a resource defined by a built-in Kubernetes group/version/kind and
name. For example: `get_resource("apps/v1/Deployment", "nginx")`

:param str group_version_kind: Group/Version/Kind of the resource, e.g., `apps/v1/Deployment`
:param str name: Name of the resource to retrieve
:param str namespace: Optional namespace of the resource to retrieve
:param Optional[str] namespace: Optional namespace of the resource to retrieve
"""

# `id` will either be `${name}` or `${namespace}/${name}`.
Expand All @@ -219,7 +228,13 @@ class ConfigFile(pulumi.ComponentResource):
Kubernetes resources contained in this ConfigFile.
"""

def __init__(self, name, file=None, opts=None, transformations=None, resource_prefix=None, file_id=None):
def __init__(self,
name: str,
file: Optional[str] = None,
opts: Optional[pulumi.ResourceOptions] = None,
transformations: Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] = None,
resource_prefix: Optional[str] = None,
file_id: Optional[str] = None):
"""
ConfigFile creates a set of Kubernetes resources from a Kubernetes YAML file.

Expand Down Expand Up @@ -271,7 +286,7 @@ class ConfigFile(pulumi.ComponentResource):
```

:param str name: A name for a resource.
:param str file: Path or a URL that uniquely identifies a file.
:param Optional[str] file: Path or a URL that uniquely identifies a file.
:param Optional[pulumi.ResourceOptions] opts: A bag of optional settings that control a resource's behavior.
:param Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] transformations: A set of
transformations to apply to Kubernetes resource definitions before registering with engine.
Expand Down Expand Up @@ -326,14 +341,17 @@ class ConfigFile(pulumi.ComponentResource):
def translate_input_property(self, prop: str) -> str:
return _tables.SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop

def get_resource(self, group_version_kind, name, namespace=None) -> pulumi.Output[pulumi.CustomResource]:
def get_resource(self,
group_version_kind: str,
name: str,
namespace: Optional[str] = None) -> pulumi.Output[pulumi.CustomResource]:
"""
get_resource returns a resource defined by a built-in Kubernetes group/version/kind and
name. For example: `get_resource("apps/v1/Deployment", "nginx")`

:param str group_version_kind: Group/Version/Kind of the resource, e.g., `apps/v1/Deployment`
:param str name: Name of the resource to retrieve
:param str namespace: Optional namespace of the resource to retrieve
:param Optional[str] namespace: Optional namespace of the resource to retrieve
"""

# `id` will either be `${name}` or `${namespace}/${name}`.
Expand Down
20 changes: 16 additions & 4 deletions sdk/python/pulumi_kubernetes/apiextensions/CustomResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import warnings
from typing import Any, Optional

import pulumi
import pulumi.runtime
Expand All @@ -11,8 +12,15 @@


class CustomResource(pulumi.CustomResource):
def __init__(self, resource_name, api_version, kind, spec=None, metadata=None, opts=None,
__name__=None, __opts__=None):
def __init__(self,
resource_name: str,
api_version: str,
kind: str,
spec: Optional[pulumi.Input[Any]] = None,
metadata: Optional[pulumi.Input[Any]] = None,
opts: Optional[pulumi.ResourceOptions] = None,
__name__=None,
__opts__=None):
"""
CustomResource represents an instance of a CustomResourceDefinition (CRD). For example, the
CoreOS Prometheus operator exposes a CRD `monitoring.coreos.com/ServiceMonitor`; to
Expand All @@ -25,7 +33,7 @@ def __init__(self, resource_name, api_version, kind, spec=None, metadata=None, o
API server.
:param str kind: The kind of the apiextensions.CustomResource we wish to select,
as specified by the CustomResourceDefinition that defines it on the API server.
:param pulumi.Input[Any] spec: Specification of the CustomResource.
:param Optional[pulumi.Input[Any]] spec: Specification of the CustomResource.
:param Optional[pulumi.Input[Any]] metadata: Standard object metadata; More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
:param Optional[pulumi.ResourceOptions] opts: A bag of options that control this
Expand Down Expand Up @@ -60,7 +68,11 @@ def __init__(self, resource_name, api_version, kind, spec=None, metadata=None, o
opts)

@staticmethod
def get(resource_name, api_version, kind, id, opts=None):
def get(resource_name: str,
api_version: str,
kind: str,
id: pulumi.Input[str],
opts: Optional[pulumi.ResourceOptions] = None):
"""
Get the state of an existing `CustomResource` resource, as identified by `id`.
Typically this ID is of the form [namespace]/[name]; if [namespace] is omitted,
Expand Down
Loading