Skip to content

Commit

Permalink
Implement {ConfigFile, ConfigGroup, Chart}#get_resource
Browse files Browse the repository at this point in the history
Fixes #763.
  • Loading branch information
hausdorff committed Aug 28, 2019
1 parent 5ceddfd commit 87ab5f9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
18 changes: 16 additions & 2 deletions pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ class Chart(pulumi.ComponentResource):
none of Tiller's server-side validity testing is executed.
"""

resources: pulumi.Output[dict]
"""
Kubernetes resources contained in this Chart.
"""

def __init__(self, release_name, config, opts=None):
"""
Create an instance of the specified Helm chart.
Expand All @@ -420,6 +425,7 @@ def __init__(self, release_name, config, opts=None):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
__props__['resources'] = None

if config.resource_prefix:
release_name = f"{config.resource_prefix}-{release_name}"
Expand All @@ -440,5 +446,13 @@ def __init__(self, release_name, config, opts=None):
# Note: Unlike NodeJS, Python requires that we "pull" on our futures in order to get them scheduled for
# execution. In order to do this, we leverage the engine's RegisterResourceOutputs to wait for the
# resolution of all resources that this Helm chart created.
resources = all_config.apply(_parse_chart)
self.register_outputs({"output": resources})
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})

def get_resource(self, groupVersionKind: str, namespace=None, name=None) -> pulumi.Output[pulumi.CustomResource]:
# `id` will either be `${name}` or `${namespace}/${name}`.
id = name
if namespace != None:
id = f'{namespace}/{name}'

return self.resources.apply(lambda rs: rs[f'{groupVersionKind}:{id}'])
11 changes: 9 additions & 2 deletions pkg/gen/python-templates/yaml.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class ConfigFile(pulumi.ComponentResource):
ConfigFile creates a set of Kubernetes resources from a Kubernetes YAML file.
"""

resources: pulumi.Output[dict]
"""
Kubernetes resources contained in this ConfigFile.
"""


def __init__(self, name, file_id, opts=None, transformations=None, resource_prefix=None):
"""
:param str name: A name for a resource.
Expand All @@ -38,6 +44,7 @@ class ConfigFile(pulumi.ComponentResource):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
__props__['resources'] = None

if resource_prefix:
name = f"{resource_prefix}-{name}"
Expand All @@ -57,8 +64,8 @@ class ConfigFile(pulumi.ComponentResource):
# Note: Unlike NodeJS, Python requires that we "pull" on our futures in order to get them scheduled for
# execution. In order to do this, we leverage the engine's RegisterResourceOutputs to wait for the
# resolution of all resources that this YAML document created.
output = _parse_yaml_document(yaml.safe_load_all(text), opts, transformations, resource_prefix)
self.register_outputs({"output": output})
self.resources = _parse_yaml_document(yaml.safe_load_all(text), opts, transformations, resource_prefix)
self.register_outputs({"resources": self.resources})

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
18 changes: 16 additions & 2 deletions sdk/python/pulumi_kubernetes/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ class Chart(pulumi.ComponentResource):
none of Tiller's server-side validity testing is executed.
"""

resources: pulumi.Output[dict]
"""
Kubernetes resources contained in this Chart.
"""

def __init__(self, release_name, config, opts=None):
"""
Create an instance of the specified Helm chart.
Expand All @@ -420,6 +425,7 @@ def __init__(self, release_name, config, opts=None):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
__props__['resources'] = None

if config.resource_prefix:
release_name = f"{config.resource_prefix}-{release_name}"
Expand All @@ -440,5 +446,13 @@ def __init__(self, release_name, config, opts=None):
# Note: Unlike NodeJS, Python requires that we "pull" on our futures in order to get them scheduled for
# execution. In order to do this, we leverage the engine's RegisterResourceOutputs to wait for the
# resolution of all resources that this Helm chart created.
resources = all_config.apply(_parse_chart)
self.register_outputs({"output": resources})
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})

def get_resource(self, groupVersionKind: str, namespace=None, name=None) -> pulumi.Output[pulumi.CustomResource]:
# `id` will either be `${name}` or `${namespace}/${name}`.
id = name
if namespace != None:
id = f'{namespace}/{name}'

return self.resources.apply(lambda rs: rs[f'{groupVersionKind}:{id}'])
11 changes: 9 additions & 2 deletions sdk/python/pulumi_kubernetes/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class ConfigFile(pulumi.ComponentResource):
ConfigFile creates a set of Kubernetes resources from a Kubernetes YAML file.
"""

resources: pulumi.Output[dict]
"""
Kubernetes resources contained in this ConfigFile.
"""


def __init__(self, name, file_id, opts=None, transformations=None, resource_prefix=None):
"""
:param str name: A name for a resource.
Expand All @@ -38,6 +44,7 @@ def __init__(self, name, file_id, opts=None, transformations=None, resource_pref
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
__props__['resources'] = None

if resource_prefix:
name = f"{resource_prefix}-{name}"
Expand All @@ -57,8 +64,8 @@ def __init__(self, name, file_id, opts=None, transformations=None, resource_pref
# Note: Unlike NodeJS, Python requires that we "pull" on our futures in order to get them scheduled for
# execution. In order to do this, we leverage the engine's RegisterResourceOutputs to wait for the
# resolution of all resources that this YAML document created.
output = _parse_yaml_document(yaml.safe_load_all(text), opts, transformations, resource_prefix)
self.register_outputs({"output": output})
self.resources = _parse_yaml_document(yaml.safe_load_all(text), opts, transformations, resource_prefix)
self.register_outputs({"resources": self.resources})

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down

0 comments on commit 87ab5f9

Please sign in to comment.