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

Add optional resourcePrefix param for Chart #599

Merged
merged 9 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Improvements

- Enable multiple instances of Helm charts per stack (https://github.com/pulumi/pulumi-kubernetes/pull/599).
- Enable multiple instances of YAML manifests per stack (https://github.com/pulumi/pulumi-kubernetes/pull/594).

### Bug fixes
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ require (
github.com/google/gofuzz v1.0.0 // indirect
github.com/googleapis/gnostic v0.2.0
github.com/gophercloud/gophercloud v0.0.0-20190418141522-bb98932a7b3a // indirect
github.com/grpc/grpc-go v0.0.0-00010101000000-000000000000 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/jinzhu/copier v0.0.0-20180308034124-7e38e58719c3
github.com/json-iterator/go v1.1.6 // indirect
github.com/mitchellh/go-wordwrap v1.0.0
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.1
github.com/pulumi/pulumi v0.17.15
github.com/stretchr/testify v1.2.2
Expand All @@ -31,7 +29,6 @@ require (
k8s.io/kube-openapi v0.0.0-20190418160015-6b3d3b2d5666
k8s.io/kubernetes v1.14.1
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
sigs.k8s.io/kustomize v1.0.11 // indirect
)

replace (
Expand Down
28 changes: 26 additions & 2 deletions go.sum

Large diffs are not rendered by default.

85 changes: 51 additions & 34 deletions pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@ def __init__(self,
self.verify = verify


class ChartOpts:
"""
ChartOpts is a bag of configuration options for a remote Helm chart.
"""

chart: pulumi.Input[str]
"""
The chart to deploy. If [repo] is provided, this chart name is looked up in the given repository.
Otherwise, this chart name must be a fully qualified chart URL or `repo/chartname`.
"""

class BaseChartOpts:
namespace: Optional[pulumi.Input[str]]
"""
Optional namespace to install chart resources into.
Expand All @@ -185,6 +175,43 @@ class ChartOpts:
creation. Allows customization of the chart behaviour without directly modifying the chart itself.
"""

resource_prefix: Optional[str]
"""
Optional prefix for the auto-generated resource names.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

def __init__(self,
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[List[Callable]] = None,
resource_prefix: Optional[str] = None) -> 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[Callable]] 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.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""
self.namespace = namespace
self.values = values
self.transformations = transformations
self.resource_prefix = resource_prefix


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rm extra line

class ChartOpts(BaseChartOpts):
"""
ChartOpts is a bag of configuration options for a remote Helm chart.
"""

chart: pulumi.Input[str]
"""
The chart to deploy. If [repo] is provided, this chart name is looked up in the given repository.
Otherwise, this chart name must be a fully qualified chart URL or `repo/chartname`.
"""

repo: Optional[pulumi.Input[str]]
"""
The repository containing the desired chart. If not provided, [chart] must be a fully qualified
Expand All @@ -206,6 +233,7 @@ def __init__(self,
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[List[Callable]] = 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) -> None:
Expand All @@ -218,17 +246,17 @@ def __init__(self,
:param Optional[List[Callable] 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.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
:param Optional[pulumi.Input[str]] repo: The repository containing the desired chart. If not
provided, [chart] must be a fully qualified chart URL or repo/chartname.
:param Optional[pulumi.Input[str]] version: The version of the chart to deploy. If not provided,
the latest version will be deployed.
:param Optional[pulumi.Input[FetchOpts]] fetch_opts: Additional options to customize the
fetching of the Helm chart.
"""
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
self.chart = chart
self.namespace = namespace
self.values = values
self.transformations = transformations
self.repo = repo
self.version = version
self.fetch_opts = fetch_opts
Expand All @@ -244,27 +272,12 @@ class LocalChartOpts:
The path to the chart directory which contains the `Chart.yaml` file.
"""

namespace: Optional[pulumi.Input[str]]
"""
Optional namespace to install chart resources into.
"""

values: Optional[pulumi.Inputs]
"""
Optional overrides for chart values.
"""

transformations: Optional[List[Callable]]
"""
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.
"""

def __init__(self,
path: pulumi.Input[str],
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[List[Callable]] = None) -> None:
transformations: Optional[List[Callable]] = None,
resource_prefix: Optional[str] = None) -> None:
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
Expand All @@ -273,11 +286,12 @@ def __init__(self,
:param Optional[List[Callable]] 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.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
lblackstone marked this conversation as resolved.
Show resolved Hide resolved
"""

super(LocalChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
self.path = path
self.namespace = namespace
self.values = values
self.transformations = transformations


def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi.ResourceOptions]) -> pulumi.Output:
Expand Down Expand Up @@ -402,6 +416,9 @@ def __init__(self, release_name: str,

__props__ = dict()

if config.resource_prefix:
release_name = f"{config.resource_prefix}-{release_name}"

super(Chart, self).__init__(
"kubernetes:helm.sh/v2:Chart",
release_name,
Expand Down
13 changes: 11 additions & 2 deletions sdk/nodejs/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ interface BaseChartOpts {
* creation. Allows customization of the chart behaviour without directly modifying the chart itself.
*/
transformations?: ((o: any, opts: pulumi.CustomResourceOptions) => void)[];

/**
* An optional prefix for the auto-generated resource names.
* Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
*/
resourcePrefix?: string
}

export interface ChartOpts extends BaseChartOpts {
Expand Down Expand Up @@ -107,6 +113,9 @@ export class Chart extends yaml.CollectionComponentResource {
config: ChartOpts | LocalChartOpts,
opts?: pulumi.ComponentResourceOptions
) {
if (config.resourcePrefix !== undefined) {
releaseName = `${config.resourcePrefix}-${releaseName}`
}
super("kubernetes:helm.sh/v2:Chart", releaseName, config, opts);

const allConfig = pulumi.output(config);
Expand Down Expand Up @@ -180,7 +189,7 @@ export class Chart extends yaml.CollectionComponentResource {
parseTemplate(
yamlStream: string,
transformations: ((o: any, opts: pulumi.CustomResourceOptions) => void)[] | undefined,
dependsOn: pulumi.Resource[]
dependsOn: pulumi.Resource[],
): pulumi.Output<{ [key: string]: pulumi.CustomResource }> {
// NOTE: We must manually split the YAML stream because of js-yaml#456. Perusing the
// code and the spec, it looks like a YAML stream is delimited by `^---`, though it is
Expand All @@ -196,7 +205,7 @@ export class Chart extends yaml.CollectionComponentResource {
return yaml.parse(
{
yaml: objs.map(o => jsyaml.safeDump(o)),
transformations: transformations || []
transformations: transformations || [],
},
{ parent: this, dependsOn: dependsOn }
);
Expand Down
85 changes: 51 additions & 34 deletions sdk/python/pulumi_kubernetes/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@ def __init__(self,
self.verify = verify


class ChartOpts:
"""
ChartOpts is a bag of configuration options for a remote Helm chart.
"""

chart: pulumi.Input[str]
"""
The chart to deploy. If [repo] is provided, this chart name is looked up in the given repository.
Otherwise, this chart name must be a fully qualified chart URL or `repo/chartname`.
"""

class BaseChartOpts:
namespace: Optional[pulumi.Input[str]]
"""
Optional namespace to install chart resources into.
Expand All @@ -185,6 +175,43 @@ class ChartOpts:
creation. Allows customization of the chart behaviour without directly modifying the chart itself.
"""

resource_prefix: Optional[str]
"""
Optional prefix for the auto-generated resource names.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

def __init__(self,
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[List[Callable]] = None,
resource_prefix: Optional[str] = None) -> 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[Callable]] 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.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""
self.namespace = namespace
self.values = values
self.transformations = transformations
self.resource_prefix = resource_prefix


class ChartOpts(BaseChartOpts):
"""
ChartOpts is a bag of configuration options for a remote Helm chart.
"""

chart: pulumi.Input[str]
"""
The chart to deploy. If [repo] is provided, this chart name is looked up in the given repository.
Otherwise, this chart name must be a fully qualified chart URL or `repo/chartname`.
"""

repo: Optional[pulumi.Input[str]]
"""
The repository containing the desired chart. If not provided, [chart] must be a fully qualified
Expand All @@ -206,6 +233,7 @@ def __init__(self,
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[List[Callable]] = 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) -> None:
Expand All @@ -218,17 +246,17 @@ def __init__(self,
:param Optional[List[Callable] 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.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
:param Optional[pulumi.Input[str]] repo: The repository containing the desired chart. If not
provided, [chart] must be a fully qualified chart URL or repo/chartname.
:param Optional[pulumi.Input[str]] version: The version of the chart to deploy. If not provided,
the latest version will be deployed.
:param Optional[pulumi.Input[FetchOpts]] fetch_opts: Additional options to customize the
fetching of the Helm chart.
"""
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
self.chart = chart
self.namespace = namespace
self.values = values
self.transformations = transformations
self.repo = repo
self.version = version
self.fetch_opts = fetch_opts
Expand All @@ -244,27 +272,12 @@ class LocalChartOpts:
The path to the chart directory which contains the `Chart.yaml` file.
"""

namespace: Optional[pulumi.Input[str]]
"""
Optional namespace to install chart resources into.
"""

values: Optional[pulumi.Inputs]
"""
Optional overrides for chart values.
"""

transformations: Optional[List[Callable]]
"""
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.
"""

def __init__(self,
path: pulumi.Input[str],
namespace: Optional[pulumi.Input[str]] = None,
values: Optional[pulumi.Inputs] = None,
transformations: Optional[List[Callable]] = None) -> None:
transformations: Optional[List[Callable]] = None,
resource_prefix: Optional[str] = None) -> None:
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
Expand All @@ -273,11 +286,12 @@ def __init__(self,
:param Optional[List[Callable]] 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.
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

super(LocalChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
self.path = path
self.namespace = namespace
self.values = values
self.transformations = transformations


def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi.ResourceOptions]) -> pulumi.Output:
Expand Down Expand Up @@ -402,6 +416,9 @@ def __init__(self, release_name: str,

__props__ = dict()

if config.resource_prefix:
release_name = f"{config.resource_prefix}-{release_name}"

super(Chart, self).__init__(
"kubernetes:helm.sh/v2:Chart",
release_name,
Expand Down
16 changes: 14 additions & 2 deletions tests/examples/examples_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
// Copyright 2016-2019, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package examples

Expand Down Expand Up @@ -157,7 +169,7 @@ func TestExamples(t *testing.T) {
t *testing.T, stackInfo integration.RuntimeValidationStackInfo,
) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 9, len(stackInfo.Deployment.Resources))
assert.Equal(t, 15, len(stackInfo.Deployment.Resources))
lblackstone marked this conversation as resolved.
Show resolved Hide resolved
},
}),

Expand Down
Loading