Skip to content

Commit

Permalink
Merge pull request #1 from cdibble/helm_provider/allow_null_values
Browse files Browse the repository at this point in the history
Helm provider/allow null values
  • Loading branch information
cdibble authored Oct 27, 2022
2 parents 5ebd95c + e6665a5 commit d86e8b9
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ for additional information about using Server-Side Apply with Pulumi's Kubernete

- Fix values precedence in helm release (https://github.com/pulumi/pulumi-kubernetes/pull/2191)
- Enable Server-Side Apply mode by default (https://github.com/pulumi/pulumi-kubernetes/pull/2206)
- Add allowNullValues boolean option to pass Null values through helm configs without having them scrubbed (https://github.com/pulumi/pulumi-kubernetes/issues/2089)

## 3.21.4 (September 22, 2022)

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Run the following command to build and install the source.
The output will be stored in `/opt/pulumi/node_modules/@pulumi/kubernetes`.

```bash
$ make build && make install
$ make ensure build install
```

`cd` into your Pulumi program directory. After `make` has completed,
Expand Down
4 changes: 4 additions & 0 deletions provider/cmd/pulumi-resource-kubernetes/schema.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion provider/pkg/gen/overlays.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ var helmV3ReleaseResource = pschema.ResourceSpec{
},
Description: "Specification defining the Helm chart repository to use.",
},

"chart": {
TypeSpec: pschema.TypeSpec{
Type: "string",
Expand Down Expand Up @@ -753,6 +752,12 @@ var helmV3ReleaseResource = pschema.ResourceSpec{
},
Description: "Status of the deployed release.",
},
"allowNullValues": {
TypeSpec: pschema.TypeSpec{
Type: "boolean",
},
Description: "Whether to allow Null values in helm chart configs.",
},
},
Type: "object",
Required: []string{
Expand Down
43 changes: 36 additions & 7 deletions provider/pkg/provider/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ var errReleaseNotFound = errors.New("release not found")

// Release should explicitly track the shape of helm.sh/v3:Release resource
type Release struct {
// When combinging Values with mergeMaps, allow Nulls
AllowNullValues bool `json:"allowNullValues,omitempty"`
// If set, installation process purges chart on fail. The wait flag will be set automatically if atomic is used
Atomic bool `json:"atomic,omitempty"`
// Chart name to be installed. A path may be used.
Expand Down Expand Up @@ -304,7 +306,7 @@ func decodeRelease(pm resource.PropertyMap, label string) (*Release, error) {
if err = mapstructure.Decode(stripped, &release); err != nil {
return nil, fmt.Errorf("decoding failure: %w", err)
}
release.Values, err = mergeMaps(values, release.Values)
release.Values, err = mergeMaps(values, release.Values, release.AllowNullValues)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1178,7 +1180,7 @@ func setReleaseAttributes(release *Release, r *release.Release, isPreview bool)
}
var err error
logger.V(9).Infof("Setting release values: %+v", r.Config)
release.Values, err = mergeMaps(release.Values, r.Config)
release.Values, err = mergeMaps(release.Values, r.Config, release.AllowNullValues)
if err != nil {
return err
}
Expand Down Expand Up @@ -1266,7 +1268,7 @@ func isChartInstallable(ch *helmchart.Chart) error {
func getValues(release *Release) (map[string]interface{}, error) {
var err error
base := map[string]interface{}{}
base, err = mergeMaps(base, release.Values)
base, err = mergeMaps(base, release.Values, release.AllowNullValues)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1296,10 +1298,14 @@ func logValues(values map[string]interface{}) error {
}

// Merges a and b map, preferring values from b map
func mergeMaps(a, b map[string]interface{}) (map[string]interface{}, error) {
a = excludeNulls(a).(map[string]interface{})
b = excludeNulls(b).(map[string]interface{})

func mergeMaps(a, b map[string]interface{}, allowNullValues bool) (map[string]interface{}, error) {
if allowNullValues {
a = mapToInterface(a).(map[string]interface{})
b = mapToInterface(b).(map[string]interface{})
} else {
a = excludeNulls(a).(map[string]interface{})
b = excludeNulls(b).(map[string]interface{})
}
if err := mergo.Merge(&a, b, mergo.WithOverride, mergo.WithTypeCheck); err != nil {
return nil, err
}
Expand Down Expand Up @@ -1337,6 +1343,29 @@ func excludeNulls(in interface{}) interface{} {
return in
}

func mapToInterface(in interface{}) interface{} {
switch reflect.TypeOf(in).Kind() {
case reflect.Map:
out := map[string]interface{}{}
m := in.(map[string]interface{})
for k, v := range m {
val := reflect.ValueOf(v)
if val.IsValid() {
out[k] = mapToInterface(v)
}
}
return out
case reflect.Slice, reflect.Array:
var out []interface{}
s := in.([]interface{})
for _, i := range s {
out = append(out, mapToInterface(i))
}
return out
}
return in
}

func getChart(cpo *action.ChartPathOptions, registryClient *registry.Client, settings *cli.EnvSettings,
newRelease *Release) (*helmchart.Chart, string,
error) {
Expand Down
6 changes: 6 additions & 0 deletions sdk/dotnet/Helm/V3/Release.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ namespace Pulumi.Kubernetes.Helm.V3
[KubernetesResourceType("kubernetes:helm.sh/v3:Release")]
public partial class Release : KubernetesResource
{
/// <summary>
/// Whether to allow Null values in helm chart configs.
/// </summary>
[Output("allowNullValues")]
public Output<bool> AllowNullValues { get; private set; } = null!;

/// <summary>
/// If set, installation process purges chart on fail. `skipAwait` will be disabled automatically if atomic is used.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions sdk/go/kubernetes/helm/v3/release.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions sdk/java/src/main/java/com/pulumi/kubernetes/helm/v3/Release.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
*/
@ResourceType(type="kubernetes:helm.sh/v3:Release")
public class Release extends com.pulumi.resources.CustomResource {
/**
* Whether to allow Null values in helm chart configs.
*
*/
@Export(name="allowNullValues", type=Boolean.class, parameters={})
private Output</* @Nullable */ Boolean> allowNullValues;

/**
* @return Whether to allow Null values in helm chart configs.
*
*/
public Output<Optional<Boolean>> allowNullValues() {
return Codegen.optional(this.allowNullValues);
}
/**
* If set, installation process purges chart on fail. `skipAwait` will be disabled automatically if atomic is used.
*
Expand Down
6 changes: 6 additions & 0 deletions sdk/nodejs/helm/v3/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export class Release extends pulumi.CustomResource {
return obj['__pulumiType'] === Release.__pulumiType;
}

/**
* Whether to allow Null values in helm chart configs.
*/
public /*out*/ readonly allowNullValues!: pulumi.Output<boolean>;
/**
* If set, installation process purges chart on fail. `skipAwait` will be disabled automatically if atomic is used.
*/
Expand Down Expand Up @@ -370,8 +374,10 @@ export class Release extends pulumi.CustomResource {
resourceInputs["verify"] = args ? args.verify : undefined;
resourceInputs["version"] = args ? args.version : undefined;
resourceInputs["waitForJobs"] = args ? args.waitForJobs : undefined;
resourceInputs["allowNullValues"] = undefined /*out*/;
resourceInputs["status"] = undefined /*out*/;
} else {
resourceInputs["allowNullValues"] = undefined /*out*/;
resourceInputs["atomic"] = undefined /*out*/;
resourceInputs["chart"] = undefined /*out*/;
resourceInputs["cleanupOnFail"] = undefined /*out*/;
Expand Down
10 changes: 10 additions & 0 deletions sdk/python/pulumi_kubernetes/helm/v3/Release.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ def _internal_init(__self__,
__props__.__dict__["verify"] = verify
__props__.__dict__["version"] = version
__props__.__dict__["wait_for_jobs"] = wait_for_jobs
__props__.__dict__["allow_null_values"] = None
__props__.__dict__["status"] = None
super(Release, __self__).__init__(
'kubernetes:helm.sh/v3:Release',
Expand All @@ -1085,6 +1086,7 @@ def get(resource_name: str,

__props__ = ReleaseArgs.__new__(ReleaseArgs)

__props__.__dict__["allow_null_values"] = None
__props__.__dict__["atomic"] = None
__props__.__dict__["chart"] = None
__props__.__dict__["cleanup_on_fail"] = None
Expand Down Expand Up @@ -1121,6 +1123,14 @@ def get(resource_name: str,
__props__.__dict__["wait_for_jobs"] = None
return Release(resource_name, opts=opts, __props__=__props__)

@property
@pulumi.getter(name="allowNullValues")
def allow_null_values(self) -> pulumi.Output[Optional[bool]]:
"""
Whether to allow Null values in helm chart configs.
"""
return pulumi.get(self, "allow_null_values")

@property
@pulumi.getter
def atomic(self) -> pulumi.Output[Optional[bool]]:
Expand Down

0 comments on commit d86e8b9

Please sign in to comment.