Skip to content

Commit

Permalink
Fix Helm api-versions handling in all SDKs (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone authored Sep 9, 2020
1 parent e3aa302 commit 495d8e6
Show file tree
Hide file tree
Showing 35 changed files with 419 additions and 26 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 @@
### Bug Fixes

- Upgrade version of pyyaml to fix a [security vulnerability](https://nvd.nist.gov/vuln/detail/CVE-2019-20477) (https://github.com/pulumi/pulumi-kubernetes/pull/1230)
- Fix Helm api-versions handling in all SDKs. (https://github.com/pulumi/pulumi-kubernetes/pull/1307)

### Improvements

Expand Down
6 changes: 4 additions & 2 deletions provider/pkg/gen/dotnet-templates/helm/ChartBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ protected ChartBase(string releaseName, Union<ChartArgs, LocalChartArgs> args, C
});
if (cfgBase.ApiVersions.Length > 0)
{
flags.Add("--api-versions");
flags.Add(string.Join(",", cfgBase.ApiVersions));
foreach (string version in cfgBase.ApiVersions)
{
flags.Add($"--api-versions={version}");
}
}

if (!string.IsNullOrEmpty(cfgBase.Namespace))
Expand Down
4 changes: 4 additions & 0 deletions provider/pkg/gen/go-templates/helm/v2/chart.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ func parseChart(ctx *pulumi.Context, name string, args chartArgs, opts ...pulumi
helmArgs = append(helmArgs, "--namespace", args.Namespace)
}

for _, version := range args.APIVersions {
helmArgs = append(helmArgs, fmt.Sprintf("--api-versions=%s", version))
}

// Check for helm version
v3, err := isHelmV3()

Expand Down
27 changes: 22 additions & 5 deletions provider/pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,17 @@ class BaseChartOpts:
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

api_versions: Optional[List[pulumi.Input[str]]]
"""
Optional kubernetes api versions used for Capabilities.APIVersions.
"""

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):
resource_prefix: Optional[str] = None,
api_versions: Optional[List[pulumi.Input[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 All @@ -394,11 +400,14 @@ def __init__(self,
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[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""
self.namespace = namespace
self.values = values
self.transformations = transformations
self.resource_prefix = resource_prefix
self.api_versions = api_versions


class ChartOpts(BaseChartOpts):
Expand Down Expand Up @@ -437,7 +446,8 @@ def __init__(self,
resource_prefix: Optional[str] = None,
repo: Optional[pulumi.Input[str]] = None,
version: Optional[pulumi.Input[str]] = None,
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None):
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None,
api_versions: Optional[List[pulumi.Input[str]]] = 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 All @@ -456,8 +466,10 @@ def __init__(self,
the latest version will be deployed.
:param Optional[pulumi.Input[FetchOpts]] fetch_opts: Additional options to customize the
fetching of the Helm chart.
:param Optional[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix, api_versions)
self.chart = chart
self.repo = repo
self.version = version
Expand All @@ -479,7 +491,8 @@ 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):
resource_prefix: Optional[str] = None,
api_versions: Optional[List[pulumi.Input[str]]] = None):
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
Expand All @@ -490,9 +503,11 @@ def __init__(self,
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[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""

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


Expand Down Expand Up @@ -576,12 +591,14 @@ def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi
file = open(overrides, 'w')
pulumi.Output.all(file, data).apply(_write_override_file)

apiversions_arg = [f'--api-versions={version}' for version in config.api_versions] if config.api_versions else []
namespace_arg = ['--namespace', config.namespace] if config.namespace else []
crd_arg = ['--include-crds'] if _is_helm_v3() else []

# Use 'helm template' to create a combined YAML manifest.
cmd = ['helm', 'template', chart, '--name-template', release_name,
'--values', default_values, '--values', overrides_filename]
cmd.extend(apiversions_arg)
cmd.extend(namespace_arg)
cmd.extend(crd_arg)

Expand Down
25 changes: 20 additions & 5 deletions provider/pkg/gen/python-templates/helm/v3/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,17 @@ class BaseChartOpts:
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

api_versions: Optional[List[pulumi.Input[str]]]
"""
Optional kubernetes api versions used for Capabilities.APIVersions.
"""

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):
resource_prefix: Optional[str] = None,
api_versions: Optional[List[pulumi.Input[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 All @@ -391,11 +397,14 @@ def __init__(self,
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[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""
self.namespace = namespace
self.values = values
self.transformations = transformations
self.resource_prefix = resource_prefix
self.api_versions = api_versions

def to_json(self):
return pulumi.Output.from_input(self.__dict__).apply(
Expand Down Expand Up @@ -438,7 +447,8 @@ def __init__(self,
resource_prefix: Optional[str] = None,
repo: Optional[pulumi.Input[str]] = None,
version: Optional[pulumi.Input[str]] = None,
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None):
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None,
api_versions: Optional[List[pulumi.Input[str]]] = 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 All @@ -457,8 +467,10 @@ def __init__(self,
the latest version will be deployed.
:param Optional[pulumi.Input[FetchOpts]] fetch_opts: Additional options to customize the
fetching of the Helm chart.
:param Optional[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix, api_versions)
self.chart = chart
self.repo = repo
self.version = version
Expand All @@ -480,7 +492,8 @@ 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):
resource_prefix: Optional[str] = None,
api_versions: Optional[List[pulumi.Input[str]]] = None):
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
Expand All @@ -491,9 +504,11 @@ def __init__(self,
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[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""

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


Expand Down
6 changes: 4 additions & 2 deletions sdk/dotnet/Helm/ChartBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ protected ChartBase(string releaseName, Union<ChartArgs, LocalChartArgs> args, C
});
if (cfgBase.ApiVersions.Length > 0)
{
flags.Add("--api-versions");
flags.Add(string.Join(",", cfgBase.ApiVersions));
foreach (string version in cfgBase.ApiVersions)
{
flags.Add($"--api-versions={version}");
}
}

if (!string.IsNullOrEmpty(cfgBase.Namespace))
Expand Down
4 changes: 4 additions & 0 deletions sdk/go/kubernetes/helm/v2/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ func parseChart(ctx *pulumi.Context, name string, args chartArgs, opts ...pulumi
helmArgs = append(helmArgs, "--namespace", args.Namespace)
}

for _, version := range args.APIVersions {
helmArgs = append(helmArgs, fmt.Sprintf("--api-versions=%s", version))
}

// Check for helm version
v3, err := isHelmV3()

Expand Down
27 changes: 22 additions & 5 deletions sdk/python/pulumi_kubernetes/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,17 @@ class BaseChartOpts:
Example: A resource created with resource_prefix="foo" would produce a resource named "foo-resourceName".
"""

api_versions: Optional[List[pulumi.Input[str]]]
"""
Optional kubernetes api versions used for Capabilities.APIVersions.
"""

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):
resource_prefix: Optional[str] = None,
api_versions: Optional[List[pulumi.Input[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 All @@ -394,11 +400,14 @@ def __init__(self,
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[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""
self.namespace = namespace
self.values = values
self.transformations = transformations
self.resource_prefix = resource_prefix
self.api_versions = api_versions


class ChartOpts(BaseChartOpts):
Expand Down Expand Up @@ -437,7 +446,8 @@ def __init__(self,
resource_prefix: Optional[str] = None,
repo: Optional[pulumi.Input[str]] = None,
version: Optional[pulumi.Input[str]] = None,
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None):
fetch_opts: Optional[pulumi.Input[FetchOpts]] = None,
api_versions: Optional[List[pulumi.Input[str]]] = 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 All @@ -456,8 +466,10 @@ def __init__(self,
the latest version will be deployed.
:param Optional[pulumi.Input[FetchOpts]] fetch_opts: Additional options to customize the
fetching of the Helm chart.
:param Optional[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix)
super(ChartOpts, self).__init__(namespace, values, transformations, resource_prefix, api_versions)
self.chart = chart
self.repo = repo
self.version = version
Expand All @@ -479,7 +491,8 @@ 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):
resource_prefix: Optional[str] = None,
api_versions: Optional[List[pulumi.Input[str]]] = None):
"""
:param pulumi.Input[str] path: The path to the chart directory which contains the
`Chart.yaml` file.
Expand All @@ -490,9 +503,11 @@ def __init__(self,
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[List[pulumi.Input[str]]] api_versions: Optional kubernetes api versions used for
Capabilities.APIVersions.
"""

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


Expand Down Expand Up @@ -576,12 +591,14 @@ def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi
file = open(overrides, 'w')
pulumi.Output.all(file, data).apply(_write_override_file)

apiversions_arg = [f'--api-versions={version}' for version in config.api_versions] if config.api_versions else []
namespace_arg = ['--namespace', config.namespace] if config.namespace else []
crd_arg = ['--include-crds'] if _is_helm_v3() else []

# Use 'helm template' to create a combined YAML manifest.
cmd = ['helm', 'template', chart, '--name-template', release_name,
'--values', default_values, '--values', overrides_filename]
cmd.extend(apiversions_arg)
cmd.extend(namespace_arg)
cmd.extend(crd_arg)

Expand Down
Loading

0 comments on commit 495d8e6

Please sign in to comment.