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

[helm.v4.Chart] Proposal: option to deploy helm hooks #3285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions provider/cmd/pulumi-resource-kubernetes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91043,6 +91043,10 @@
"type": "boolean",
"description": "If set, no CRDs will be installed. By default, CRDs are installed if not already present."
},
"deployHookedResources": {
"type": "boolean",
"description": "If set, deploy all resources that would be managed by Helm hooks as regular resources, ignoring their hook annotations. When disabled (default), these resources are ignored."
},
"valueYamlFiles": {
"type": "array",
"items": {
Expand Down
4 changes: 3 additions & 1 deletion provider/pkg/gen/examples/overlays/chartV4.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Use the `dependencyUpdate` input to have Pulumi update the dependencies (see: [H
The `Chart` resource renders the templates from your chart and then manages the resources directly with the
Pulumi Kubernetes provider. A default namespace is applied based on the `namespace` input, the provider's
configured namespace, and the active Kubernetes context. Use the `skipCrds` option to skip installing the
Custom Resource Definition (CRD) objects located in the chart's `crds/` special directory.
Custom Resource Definition (CRD) objects located in the chart's `crds/` special directory. By default,
resources managed by helm hooks are ignored, use `deployHookedResources` to deploy them as regular resources,
ignoring their `helm.sh/hook*` annotations.

Use the `postRenderer` input to pipe the rendered manifest through a [post-rendering command](https://helm.sh/docs/topics/advanced/#post-rendering).

Expand Down
6 changes: 6 additions & 0 deletions provider/pkg/gen/overlays.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ var helmV4ChartResource = pschema.ResourceSpec{
},
Description: "If set, no CRDs will be installed. By default, CRDs are installed if not already present.",
},
"deployHookedResourcess": {
TypeSpec: pschema.TypeSpec{
Type: "boolean",
},
Description: "If set, deploy all resources that would be managed by Helm hooks as regular resources, ignoring their hook annotations. When disabled (default), these resources are ignored.",
},
"postRenderer": {
TypeSpec: pschema.TypeSpec{
Ref: "#/types/kubernetes:helm.sh/v4:PostRenderer",
Expand Down
23 changes: 13 additions & 10 deletions provider/pkg/provider/helm/v4/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ type ChartArgs struct {
Verify pulumi.BoolInput `pulumi:"verify,optional"`
Keyring pulumi.AssetInput `pulumi:"keyring,optional"`

Values pulumi.MapInput `pulumi:"values,optional"`
ValuesFiles pulumi.AssetArrayInput `pulumi:"valueYamlFiles,optional"`
SkipCrds pulumi.BoolInput `pulumi:"skipCrds,optional"`
PostRenderer helmv4.PostRendererInput `pulumi:"postRenderer,optional"`
Values pulumi.MapInput `pulumi:"values,optional"`
ValuesFiles pulumi.AssetArrayInput `pulumi:"valueYamlFiles,optional"`
SkipCrds pulumi.BoolInput `pulumi:"skipCrds,optional"`
DeployHookedResources pulumi.BoolInput `pulumi:"DeployHookedResources,optional"`
PostRenderer helmv4.PostRendererInput `pulumi:"postRenderer,optional"`

ResourcePrefix pulumi.StringInput `pulumi:"resourcePrefix,optional"`
SkipAwait pulumi.BoolInput `pulumi:"skipAwait,optional"`
Expand All @@ -72,10 +73,11 @@ type chartArgs struct {
Verify bool
Keyring pulumi.Asset

Values map[string]any
ValuesFiles []pulumi.Asset
SkipCrds bool
PostRenderer *helmv4.PostRenderer
Values map[string]any
ValuesFiles []pulumi.Asset
SkipCrds bool
DeployHookedResources bool
PostRenderer *helmv4.PostRenderer

ResourcePrefix *string
SkipAwait bool
Expand All @@ -85,7 +87,7 @@ func unwrapChartArgs(ctx context.Context, args *ChartArgs) (*chartArgs, internal
result, err := internals.UnsafeAwaitOutput(ctx, pulumi.All(
args.Name, args.Namespace,
args.Chart, args.Version, args.Devel, args.RepositoryOpts, args.DependencyUpdate, args.Verify, args.Keyring,
args.Values, args.ValuesFiles, args.SkipCrds, args.PostRenderer,
args.Values, args.ValuesFiles, args.SkipCrds, args.DeployHookedResources, args.PostRenderer,
args.ResourcePrefix, args.SkipAwait))
if err != nil || !result.Known {
return nil, result, err
Expand All @@ -110,6 +112,7 @@ func unwrapChartArgs(ctx context.Context, args *ChartArgs) (*chartArgs, internal
r.Values, _ = pop().(map[string]any)
r.ValuesFiles, _ = pop().([]pulumi.Asset)
r.SkipCrds, _ = pop().(bool)
r.DeployHookedResources, _ = pop().(bool)
if v, ok := pop().(helmv4.PostRenderer); ok {
r.PostRenderer = &v
}
Expand Down Expand Up @@ -212,7 +215,7 @@ func (r *ChartProvider) Construct(ctx *pulumi.Context, typ, name string, inputs
cmd.Values.Values = chartArgs.Values
cmd.Values.ValuesFiles = chartArgs.ValuesFiles
cmd.IncludeCRDs = !chartArgs.SkipCrds
cmd.DisableHooks = true
cmd.DisableHooks = !chartArgs.DeployHookedResources
cmd.ReleaseName = chartArgs.Name
cmd.Namespace = chartArgs.Namespace

Expand Down
18 changes: 18 additions & 0 deletions provider/pkg/provider/helm/v4/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,24 @@ var _ = Describe("Construct", func() {
})
})

Describe("DeployHookedResources", func() {
Context("given deployHookedResources", func() {
BeforeEach(func() {
inputs["deployHookedResources"] = resource.NewBoolProperty(true)
})
It("should deploy hooked resources", func(ctx context.Context) {
resp, err := pulumiprovider.Construct(ctx, req, tc.EngineConn(), k.Construct)
Expect(err).ShouldNot(HaveOccurred())
outputs := unmarshalProperties(GinkgoTB(), resp.State)
Expect(outputs).To(MatchProps(IgnoreExtras, Props{
"resources": MatchArrayValue(ContainElements(
MatchResourceReferenceValue("urn:pulumi:stack::project::kubernetes:helm/v4:Chart$kubernetes:policy/v1:PodDisruptionBudget::test:default/test-reference", "test:default/test-reference"),
)),
}))
})
})
})

Describe("Post Renderer", func() {
Context("given a postRenderer", func() {
var tempdir string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "reference.fullname" . }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": before-hook-creation
spec:
minAvailable: 0
selector:
matchLabels: ~