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 option to disable Helm hook warnings #1682

Merged
merged 3 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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
58 changes: 36 additions & 22 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,28 +1046,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 +1185,41 @@ 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 PULUMI_DISABLE_HELM_HOOK_WARNING environment variable.
lblackstone marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
}
disableHelmHookWarning := false
if v, ok := os.LookupEnv("PULUMI_DISABLE_HELM_HOOK_WARNING"); ok {
lower := strings.ToLower(v)
if lower != "false" && lower != "0" {
disableHelmHookWarning = true
}
}
if hasHelmHook && !disableHelmHookWarning {
_ = 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_DISABLE_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