Skip to content

Commit

Permalink
[python] Add type annotations to overlays (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvp committed Aug 19, 2020
1 parent 974fe10 commit 8394ba2
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Improvements

- Handle kubeconfig contents or path in provider. (https://github.com/pulumi/pulumi-kubernetes/pull/1255)
- Add type annotations to Python SDK for API Extensions, Helm, Kustomize, and YAML. (https://github.com/pulumi/pulumi-kubernetes/pull/1259)

## 2.4.3 (August 14, 2020)

Expand Down
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,
__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
63 changes: 49 additions & 14 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 @@ -350,7 +369,7 @@ class BaseChartOpts:
Optional overrides for chart values.
"""

transformations: Optional[List[Callable]]
transformations: Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]]
"""
Optional list of transformations to apply to resources that will be created by this chart prior to
creation. Allows customization of the chart behaviour without directly modifying the chart itself.
Expand All @@ -362,11 +381,15 @@ 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[List[Callable[[Any, pulumi.ResourceOptions], None]]] = 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.
:param Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] transformations: Optional list
:param Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]] transformations: Optional list
of transformations to apply to resources that will be created by this chart prior to creation.
Allows customization of the chart behaviour without directly modifying the chart itself.
:param Optional[str] resource_prefix: An optional prefix for the auto-generated resource names.
Expand Down Expand Up @@ -406,16 +429,23 @@ 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[List[Callable[[Any, pulumi.ResourceOptions], None]]] = None,
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.
Example: repo: "stable", chart: "nginx-ingress" -> "stable/nginx-ingress"
Example: chart: "stable/nginx-ingress" -> "stable/nginx-ingress"
:param Optional[pulumi.Input[str]] namespace: Optional namespace to install chart resources into.
:param Optional[pulumi.Inputs] values: Optional overrides for chart values.
:param Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] transformations: Optional list of
:param Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]] transformations: Optional list of
transformations to apply to resources that will be created by this chart prior to creation.
Allows customization of the chart behaviour without directly modifying the chart itself.
:param Optional[str] resource_prefix: An optional prefix for the auto-generated resource names.
Expand Down Expand Up @@ -444,13 +474,18 @@ 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[List[Callable[[Any, pulumi.ResourceOptions], None]]] = None,
resource_prefix: Optional[str] = None):
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
:param Optional[pulumi.Input[str]] namespace: Optional namespace to install chart resources into.
:param Optional[pulumi.Inputs] values: Optional overrides for chart values.
:param Optional[List[Tuple[Callable, Optional[pulumi.ResourceOptions]]]] transformations: Optional list of
:param Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]] transformations: Optional list of
transformations to apply to resources that will be created by this chart prior to creation.
Allows customization of the chart behaviour without directly modifying the chart itself.
:param Optional[str] resource_prefix: An optional prefix for the auto-generated resource names.
Expand Down
18 changes: 14 additions & 4 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 Any, Callable, List, Optional

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[Callable[[Any, pulumi.ResourceOptions], None]]] = 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 @@ -82,7 +89,7 @@ def omit_resource(obj, opts):
Example: ./helloWorld
Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
: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
:param Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]] transformations: A set of
transformations to apply to Kubernetes resource definitions before registering with engine.
:param Optional[str] resource_prefix: An optional prefix for the auto-generated resource names.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
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
38 changes: 28 additions & 10 deletions provider/pkg/gen/python-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import warnings
from copy import copy
from glob import glob
from inspect import getargspec
from typing import Callable, Dict, List, Optional
from typing import Any, Callable, Dict, List, Optional

import pulumi
import pulumi.runtime
Expand All @@ -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[Callable[[Any, pulumi.ResourceOptions], None]]] = 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 @@ -130,7 +136,7 @@ class ConfigGroup(pulumi.ComponentResource):
:param Optional[List[str]] files: Set of paths or a URLs that uniquely identify files.
:param Optional[List[str]] yaml: YAML text containing Kubernetes resource definitions.
: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
:param Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]] transformations: A set of
transformations to apply to Kubernetes resource definitions before registering with engine.
:param Optional[str] resource_prefix: An optional prefix for the auto-generated resource names.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
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[Callable[[Any, pulumi.ResourceOptions], None]]] = 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,9 +286,9 @@ 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
:param Optional[List[Callable[[Any, pulumi.ResourceOptions], None]]] transformations: A set of
transformations to apply to Kubernetes resource definitions before registering with engine.
:param Optional[str] resource_prefix: An optional prefix for the auto-generated resource names.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
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
Loading

0 comments on commit 8394ba2

Please sign in to comment.