Skip to content

Commit

Permalink
Add option to disable Helm hook warnings (#1682)
Browse files Browse the repository at this point in the history
The warning for unsupported Helm hooks can now be disabled
using the `suppressHelmHookWarnings` Provider option, or by setting
the `PULUMI_SUPPRESS_HELM_HOOK_WARNINGS` environment variable.
  • Loading branch information
lblackstone committed Aug 19, 2021
1 parent bd2c26f commit 34530fd
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [sdk/python] Fix wait for metadata in `yaml._parse_yaml_object`. (https://github.com/pulumi/pulumi-kubernetes/pull/1675)
- Fix diff logic for server-side apply mode (https://github.com/pulumi/pulumi-kubernetes/pull/1679)
- Add option to disable Helm hook warnings (https://github.com/pulumi/pulumi-kubernetes/pull/1682)

## 3.6.0 (Auguest 4, 2021)

Expand Down
13 changes: 13 additions & 0 deletions provider/cmd/pulumi-resource-kubernetes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"suppressDeprecationWarnings": {
"type": "boolean",
"description": "If present and set to true, suppress apiVersion deprecation warnings from the CLI.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `suppressDeprecationWarnings` parameter.\n2. The `PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS` environment variable."
},
"suppressHelmHookWarnings": {
"type": "boolean",
"description": "If present and set to true, suppress unsupported Helm hook warnings from the CLI.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `suppressHelmHookWarnings` parameter.\n2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable."
}
}
},
Expand Down Expand Up @@ -29618,6 +29622,15 @@
"PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS"
]
}
},
"suppressHelmHookWarnings": {
"type": "boolean",
"description": "If present and set to true, suppress unsupported Helm hook warnings from the CLI.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `suppressHelmHookWarnings` parameter.\n2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.",
"defaultInfo": {
"environment": [
"PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS"
]
}
}
}
},
Expand Down
13 changes: 13 additions & 0 deletions provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func PulumiSchema(swagger map[string]interface{}) pschema.PackageSpec {
Description: "If present and set to true, suppress apiVersion deprecation warnings from the CLI.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `suppressDeprecationWarnings` parameter.\n2. The `PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS` environment variable.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
"suppressHelmHookWarnings": {
Description: "If present and set to true, suppress unsupported Helm hook warnings from the CLI.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `suppressHelmHookWarnings` parameter.\n2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
},
},

Expand Down Expand Up @@ -127,6 +131,15 @@ func PulumiSchema(swagger map[string]interface{}) pschema.PackageSpec {
Description: "If present and set to true, suppress apiVersion deprecation warnings from the CLI.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
"suppressHelmHookWarnings": {
DefaultInfo: &pschema.DefaultSpec{
Environment: []string{
"PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS",
},
},
Description: "If present and set to true, suppress unsupported Helm hook warnings from the CLI.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `suppressHelmHookWarnings` parameter.\n2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
},
},

Expand Down
68 changes: 46 additions & 22 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type kubeProvider struct {
enableDryRun bool
enableSecrets bool
suppressDeprecationWarnings bool
suppressHelmHookWarnings bool

yamlRenderMode bool
yamlDirectory string
Expand Down Expand Up @@ -429,6 +430,22 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
k.suppressDeprecationWarnings = true
}

suppressHelmHookWarnings := func() bool {
// If the provider flag is set, use that value to determine behavior. This will override the ENV var.
if enabled, exists := vars["kubernetes:config:suppressHelmHookWarnings"]; exists {
return enabled == trueStr
}
// If the provider flag is not set, fall back to the ENV var.
if enabled, exists := os.LookupEnv("PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS"); exists {
return enabled == trueStr
}
// Default to false.
return false
}
if suppressHelmHookWarnings() {
k.suppressHelmHookWarnings = true
}

renderYamlToDirectory := func() string {
// Read the config from the Provider.
if directory, exists := vars["kubernetes:config:renderYamlToDirectory"]; exists {
Expand Down Expand Up @@ -1046,28 +1063,7 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (

var failures []*pulumirpc.CheckFailure

hasHelmHook := false
for key, value := range newInputs.GetAnnotations() {
// If annotations with a reserved internal prefix exist, ignore them.
if metadata.IsInternalAnnotation(key) {
_ = k.host.Log(ctx, diag.Warning, urn,
fmt.Sprintf("ignoring user-specified value for internal annotation %q", key))
}

// If the Helm hook annotation is found, set the hasHelmHook flag.
if has := metadata.IsHelmHookAnnotation(key); has {
// Test hooks are handled, so ignore this one.
if match, _ := regexp.MatchString(`test|test-success|test-failure`, value); !match {
hasHelmHook = hasHelmHook || has
}
}
}
if hasHelmHook {
_ = k.host.Log(ctx, diag.Warning, urn,
"This resource contains Helm hooks that are not currently supported by Pulumi. The resource will "+
"be created, but any hooks will not be executed. Hooks support is tracked at "+
"https://github.com/pulumi/pulumi-kubernetes/issues/555")
}
k.helmHookWarning(ctx, newInputs, urn)

annotatedInputs, err := legacyInitialAPIVersion(oldInputs, newInputs)
if err != nil {
Expand Down Expand Up @@ -1206,6 +1202,34 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
return &pulumirpc.CheckResponse{Inputs: autonamedInputs, Failures: failures}, nil
}

// helmHookWarning logs a warning if a Chart contains unsupported hooks. The warning can be disabled by setting
// the suppressHelmHookWarnings provider flag or related ENV var.
func (k *kubeProvider) helmHookWarning(ctx context.Context, newInputs *unstructured.Unstructured, urn resource.URN) {
hasHelmHook := false
for key, value := range newInputs.GetAnnotations() {
// If annotations with a reserved internal prefix exist, ignore them.
if metadata.IsInternalAnnotation(key) {
_ = k.host.Log(ctx, diag.Warning, urn,
fmt.Sprintf("ignoring user-specified value for internal annotation %q", key))
}

// If the Helm hook annotation is found, set the hasHelmHook flag.
if has := metadata.IsHelmHookAnnotation(key); has {
// Test hooks are handled, so ignore this one.
if match, _ := regexp.MatchString(`test|test-success|test-failure`, value); !match {
hasHelmHook = hasHelmHook || has
}
}
}
if hasHelmHook && !k.suppressHelmHookWarnings {
_ = k.host.Log(ctx, diag.Warning, urn,
"This resource contains Helm hooks that are not currently supported by Pulumi. The resource will "+
"be created, but any hooks will not be executed. Hooks support is tracked at "+
"https://github.com/pulumi/pulumi-kubernetes/issues/555 -- This warning can be disabled by setting "+
"the PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING environment variable")
}
}

// Diff checks what impacts a hypothetical update will have on the resource's properties.
func (k *kubeProvider) Diff(
ctx context.Context, req *pulumirpc.DiffRequest,
Expand Down
14 changes: 14 additions & 0 deletions sdk/dotnet/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,19 @@ public void Set(T value)
set => _suppressDeprecationWarnings.Set(value);
}

private static readonly __Value<bool?> _suppressHelmHookWarnings = new __Value<bool?>(() => __config.GetBoolean("suppressHelmHookWarnings"));
/// <summary>
/// If present and set to true, suppress unsupported Helm hook warnings from the CLI.
///
/// This config can be specified in the following ways, using this precedence:
/// 1. This `suppressHelmHookWarnings` parameter.
/// 2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
/// </summary>
public static bool? SuppressHelmHookWarnings
{
get => _suppressHelmHookWarnings.Get();
set => _suppressHelmHookWarnings.Set(value);
}

}
}
11 changes: 11 additions & 0 deletions sdk/dotnet/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,22 @@ public sealed class ProviderArgs : Pulumi.ResourceArgs
[Input("suppressDeprecationWarnings", json: true)]
public Input<bool>? SuppressDeprecationWarnings { get; set; }

/// <summary>
/// If present and set to true, suppress unsupported Helm hook warnings from the CLI.
///
/// This config can be specified in the following ways, using this precedence:
/// 1. This `suppressHelmHookWarnings` parameter.
/// 2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
/// </summary>
[Input("suppressHelmHookWarnings", json: true)]
public Input<bool>? SuppressHelmHookWarnings { get; set; }

public ProviderArgs()
{
EnableDryRun = Utilities.GetEnvBoolean("PULUMI_K8S_ENABLE_DRY_RUN");
KubeConfig = Utilities.GetEnv("KUBECONFIG");
SuppressDeprecationWarnings = Utilities.GetEnvBoolean("PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS");
SuppressHelmHookWarnings = Utilities.GetEnvBoolean("PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS");
}
}
}
9 changes: 9 additions & 0 deletions sdk/go/kubernetes/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ func GetRenderYamlToDirectory(ctx *pulumi.Context) string {
func GetSuppressDeprecationWarnings(ctx *pulumi.Context) bool {
return config.GetBool(ctx, "kubernetes:suppressDeprecationWarnings")
}

// If present and set to true, suppress unsupported Helm hook warnings from the CLI.
//
// This config can be specified in the following ways, using this precedence:
// 1. This `suppressHelmHookWarnings` parameter.
// 2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
func GetSuppressHelmHookWarnings(ctx *pulumi.Context) bool {
return config.GetBool(ctx, "kubernetes:suppressHelmHookWarnings")
}
15 changes: 15 additions & 0 deletions sdk/go/kubernetes/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func NewProvider(ctx *pulumi.Context,
if args.SuppressDeprecationWarnings == nil {
args.SuppressDeprecationWarnings = pulumi.BoolPtr(getEnvOrDefault(false, parseEnvBool, "PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS").(bool))
}
if args.SuppressHelmHookWarnings == nil {
args.SuppressHelmHookWarnings = pulumi.BoolPtr(getEnvOrDefault(false, parseEnvBool, "PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS").(bool))
}
var resource Provider
err := ctx.RegisterResource("pulumi:providers:kubernetes", name, args, &resource, opts...)
if err != nil {
Expand Down Expand Up @@ -67,6 +70,12 @@ type providerArgs struct {
RenderYamlToDirectory *string `pulumi:"renderYamlToDirectory"`
// If present and set to true, suppress apiVersion deprecation warnings from the CLI.
SuppressDeprecationWarnings *bool `pulumi:"suppressDeprecationWarnings"`
// If present and set to true, suppress unsupported Helm hook warnings from the CLI.
//
// This config can be specified in the following ways, using this precedence:
// 1. This `suppressHelmHookWarnings` parameter.
// 2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
SuppressHelmHookWarnings *bool `pulumi:"suppressHelmHookWarnings"`
}

// The set of arguments for constructing a Provider resource.
Expand Down Expand Up @@ -98,6 +107,12 @@ type ProviderArgs struct {
RenderYamlToDirectory pulumi.StringPtrInput
// If present and set to true, suppress apiVersion deprecation warnings from the CLI.
SuppressDeprecationWarnings pulumi.BoolPtrInput
// If present and set to true, suppress unsupported Helm hook warnings from the CLI.
//
// This config can be specified in the following ways, using this precedence:
// 1. This `suppressHelmHookWarnings` parameter.
// 2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
SuppressHelmHookWarnings pulumi.BoolPtrInput
}

func (ProviderArgs) ElementType() reflect.Type {
Expand Down
9 changes: 9 additions & 0 deletions sdk/nodejs/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class Provider extends pulumi.ProviderResource {
inputs["namespace"] = args ? args.namespace : undefined;
inputs["renderYamlToDirectory"] = args ? args.renderYamlToDirectory : undefined;
inputs["suppressDeprecationWarnings"] = pulumi.output((args ? args.suppressDeprecationWarnings : undefined) ?? <any>utilities.getEnvBoolean("PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS")).apply(JSON.stringify);
inputs["suppressHelmHookWarnings"] = pulumi.output((args ? args.suppressHelmHookWarnings : undefined) ?? <any>utilities.getEnvBoolean("PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS")).apply(JSON.stringify);
}
if (!opts.version) {
opts = pulumi.mergeOptions(opts, { version: utilities.getVersion()});
Expand Down Expand Up @@ -94,4 +95,12 @@ export interface ProviderArgs {
* If present and set to true, suppress apiVersion deprecation warnings from the CLI.
*/
suppressDeprecationWarnings?: pulumi.Input<boolean>;
/**
* If present and set to true, suppress unsupported Helm hook warnings from the CLI.
*
* This config can be specified in the following ways, using this precedence:
* 1. This `suppressHelmHookWarnings` parameter.
* 2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
*/
suppressHelmHookWarnings?: pulumi.Input<boolean>;
}
38 changes: 37 additions & 1 deletion sdk/python/pulumi_kubernetes/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __init__(__self__, *,
kubeconfig: Optional[pulumi.Input[str]] = None,
namespace: Optional[pulumi.Input[str]] = None,
render_yaml_to_directory: Optional[pulumi.Input[str]] = None,
suppress_deprecation_warnings: Optional[pulumi.Input[bool]] = None):
suppress_deprecation_warnings: Optional[pulumi.Input[bool]] = None,
suppress_helm_hook_warnings: Optional[pulumi.Input[bool]] = None):
"""
The set of arguments for constructing a Provider resource.
:param pulumi.Input[str] cluster: If present, the name of the kubeconfig cluster to use.
Expand All @@ -42,6 +43,11 @@ def __init__(__self__, *,
and may result in an error if they are referenced by other resources. Also note that any secret values
used in these resources will be rendered in plaintext to the resulting YAML.
:param pulumi.Input[bool] suppress_deprecation_warnings: If present and set to true, suppress apiVersion deprecation warnings from the CLI.
:param pulumi.Input[bool] suppress_helm_hook_warnings: If present and set to true, suppress unsupported Helm hook warnings from the CLI.
This config can be specified in the following ways, using this precedence:
1. This `suppressHelmHookWarnings` parameter.
2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
"""
if cluster is not None:
pulumi.set(__self__, "cluster", cluster)
Expand All @@ -63,6 +69,10 @@ def __init__(__self__, *,
suppress_deprecation_warnings = _utilities.get_env_bool('PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS')
if suppress_deprecation_warnings is not None:
pulumi.set(__self__, "suppress_deprecation_warnings", suppress_deprecation_warnings)
if suppress_helm_hook_warnings is None:
suppress_helm_hook_warnings = _utilities.get_env_bool('PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS')
if suppress_helm_hook_warnings is not None:
pulumi.set(__self__, "suppress_helm_hook_warnings", suppress_helm_hook_warnings)

@property
@pulumi.getter
Expand Down Expand Up @@ -161,6 +171,22 @@ def suppress_deprecation_warnings(self) -> Optional[pulumi.Input[bool]]:
def suppress_deprecation_warnings(self, value: Optional[pulumi.Input[bool]]):
pulumi.set(self, "suppress_deprecation_warnings", value)

@property
@pulumi.getter(name="suppressHelmHookWarnings")
def suppress_helm_hook_warnings(self) -> Optional[pulumi.Input[bool]]:
"""
If present and set to true, suppress unsupported Helm hook warnings from the CLI.
This config can be specified in the following ways, using this precedence:
1. This `suppressHelmHookWarnings` parameter.
2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
"""
return pulumi.get(self, "suppress_helm_hook_warnings")

@suppress_helm_hook_warnings.setter
def suppress_helm_hook_warnings(self, value: Optional[pulumi.Input[bool]]):
pulumi.set(self, "suppress_helm_hook_warnings", value)


class Provider(pulumi.ProviderResource):
@overload
Expand All @@ -174,6 +200,7 @@ def __init__(__self__,
namespace: Optional[pulumi.Input[str]] = None,
render_yaml_to_directory: Optional[pulumi.Input[str]] = None,
suppress_deprecation_warnings: Optional[pulumi.Input[bool]] = None,
suppress_helm_hook_warnings: Optional[pulumi.Input[bool]] = None,
__props__=None):
"""
The provider type for the kubernetes package.
Expand All @@ -200,6 +227,11 @@ def __init__(__self__,
and may result in an error if they are referenced by other resources. Also note that any secret values
used in these resources will be rendered in plaintext to the resulting YAML.
:param pulumi.Input[bool] suppress_deprecation_warnings: If present and set to true, suppress apiVersion deprecation warnings from the CLI.
:param pulumi.Input[bool] suppress_helm_hook_warnings: If present and set to true, suppress unsupported Helm hook warnings from the CLI.
This config can be specified in the following ways, using this precedence:
1. This `suppressHelmHookWarnings` parameter.
2. The `PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNING` environment variable.
"""
...
@overload
Expand Down Expand Up @@ -232,6 +264,7 @@ def _internal_init(__self__,
namespace: Optional[pulumi.Input[str]] = None,
render_yaml_to_directory: Optional[pulumi.Input[str]] = None,
suppress_deprecation_warnings: Optional[pulumi.Input[bool]] = None,
suppress_helm_hook_warnings: Optional[pulumi.Input[bool]] = None,
__props__=None):
if opts is None:
opts = pulumi.ResourceOptions()
Expand All @@ -257,6 +290,9 @@ def _internal_init(__self__,
if suppress_deprecation_warnings is None:
suppress_deprecation_warnings = _utilities.get_env_bool('PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS')
__props__.__dict__["suppress_deprecation_warnings"] = pulumi.Output.from_input(suppress_deprecation_warnings).apply(pulumi.runtime.to_json) if suppress_deprecation_warnings is not None else None
if suppress_helm_hook_warnings is None:
suppress_helm_hook_warnings = _utilities.get_env_bool('PULUMI_K8S_SUPPRESS_HELM_HOOK_WARNINGS')
__props__.__dict__["suppress_helm_hook_warnings"] = pulumi.Output.from_input(suppress_helm_hook_warnings).apply(pulumi.runtime.to_json) if suppress_helm_hook_warnings is not None else None
super(Provider, __self__).__init__(
'kubernetes',
resource_name,
Expand Down

0 comments on commit 34530fd

Please sign in to comment.