Skip to content

Commit c080144

Browse files
authored
Add support for the takeOwnership flag on helm Release resources (#4476)
### Proposed changes This adds support for the `--take-ownership` in helm. I have also added an integration test to verify that the flag behaves as expected. And lastly I have updated the documentation with examples, though i'm not really sure it's necessary. Do note: All the changes here are written by Claude. I have reviewed them, and I can see that the new test passes. However I do also realize that not all projects appreciate AI generated code, thus this note :) ### Related issues (optional) Handles most of #3595. I have intentionally not done the ENV variable, as I felt that might be an expected change, but I can do it if desired :)
1 parent c2515e9 commit c080144

16 files changed

Lines changed: 480 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Added
77

8+
- [#3595](https://github.com/pulumi/pulumi-kubernetes/issues/3595) Add `takeOwnership` to `kubernetes.helm.sh/v3:Release`. When set, Helm skips the resource-conflict check and adopts existing resources into the release (equivalent to `helm upgrade`/`helm install --take-ownership`).
89
- [#3284](https://github.com/pulumi/pulumi-kubernetes/issues/3284) Add `includeHooks` to `kubernetes.helm.sh/v4:Chart`. When set together with the provider's `renderYamlToDirectory`, Helm hook resources (annotated `helm.sh/hook`) are included in the rendered output instead of being dropped, so that another tool (e.g. Argo CD) can apply them. Test hooks (`helm.sh/hook: test`) are excluded, and the flag has no effect outside of render mode. This only brings render mode up to par with `helm template`; it does not implement full Helm hook lifecycle support (ordering, weights, delete policies, execution), so #3284 remains open.
910

1011
### Changed

‎provider/cmd/pulumi-resource-kubernetes/schema.json‎

Lines changed: 10 additions & 1 deletion
Large diffs are not rendered by default.

‎provider/pkg/gen/examples/overlays/helmRelease.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,86 @@ func main() {
746746
}
747747
```
748748
{{% /example %}}
749+
{{% example %}}
750+
### Take Ownership of Existing Resources
751+
752+
```typescript
753+
import * as k8s from "@pulumi/kubernetes";
754+
755+
const nginxIngress = new k8s.helm.v3.Release("nginx-ingress", {
756+
chart: "nginx-ingress",
757+
version: "1.24.4",
758+
repositoryOpts: {
759+
repo: "https://charts.helm.sh/stable",
760+
},
761+
takeOwnership: true,
762+
});
763+
```
764+
```python
765+
from pulumi_kubernetes.helm.v3 import Release, ReleaseArgs, RepositoryOptsArgs
766+
767+
nginx_ingress = Release(
768+
"nginx-ingress",
769+
ReleaseArgs(
770+
chart="nginx-ingress",
771+
version="1.24.4",
772+
repository_opts=RepositoryOptsArgs(
773+
repo="https://charts.helm.sh/stable",
774+
),
775+
take_ownership=True,
776+
),
777+
)
778+
```
779+
```csharp
780+
using Pulumi;
781+
using Pulumi.Kubernetes.Types.Inputs.Helm.V3;
782+
using Pulumi.Kubernetes.Helm.V3;
783+
784+
class HelmStack : Stack
785+
{
786+
public HelmStack()
787+
{
788+
var nginx = new Release("nginx-ingress", new ReleaseArgs
789+
{
790+
Chart = "nginx-ingress",
791+
Version = "1.24.4",
792+
RepositoryOpts = new RepositoryOptsArgs
793+
{
794+
Repo = "https://charts.helm.sh/stable"
795+
},
796+
TakeOwnership = true,
797+
});
798+
799+
}
800+
}
801+
```
802+
```go
803+
package main
804+
805+
import (
806+
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3"
807+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
808+
)
809+
810+
func main() {
811+
pulumi.Run(func(ctx *pulumi.Context) error {
812+
_, err := helm.NewRelease(ctx, "nginx-ingress", &helm.ReleaseArgs{
813+
Chart: pulumi.String("nginx-ingress"),
814+
Version: pulumi.String("1.24.4"),
815+
RepositoryOpts: helm.RepositoryOptsArgs{
816+
Repo: pulumi.String("https://charts.helm.sh/stable"),
817+
},
818+
TakeOwnership: pulumi.Bool(true),
819+
})
820+
if err != nil {
821+
return err
822+
}
823+
824+
return nil
825+
})
826+
}
827+
```
828+
{{% /example %}}
749829
{{% /examples %}}
750830

751831
## Import

‎provider/pkg/gen/overlays.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,14 @@ var helmV3ReleaseResource = pschema.ResourceSpec{
855855
},
856856
Description: "If set, no CRDs will be installed. By default, CRDs are installed if not already present.",
857857
},
858+
"takeOwnership": {
859+
TypeSpec: pschema.TypeSpec{
860+
Type: "boolean",
861+
},
862+
Description: "If set, install/upgrade will skip the check for existing resource conflicts and " +
863+
"take ownership of the matching resources, adopting any that are not already managed by " +
864+
"this release. This mirrors the Helm `--take-ownership` flag.",
865+
},
858866
"renderSubchartNotes": {
859867
TypeSpec: pschema.TypeSpec{
860868
Type: "boolean",
@@ -960,6 +968,7 @@ var helmV3ReleaseResource = pschema.ResourceSpec{
960968
"maxHistory",
961969
"atomic",
962970
"skipCrds",
971+
"takeOwnership",
963972
"renderSubchartNotes",
964973
"disableOpenapiValidation",
965974
"skipAwait",
@@ -1134,6 +1143,14 @@ var helmV3ReleaseResource = pschema.ResourceSpec{
11341143
},
11351144
Description: "If set, no CRDs will be installed. By default, CRDs are installed if not already present.",
11361145
},
1146+
"takeOwnership": {
1147+
TypeSpec: pschema.TypeSpec{
1148+
Type: "boolean",
1149+
},
1150+
Description: "If set, install/upgrade will skip the check for existing resource conflicts and " +
1151+
"take ownership of the matching resources, adopting any that are not already managed by " +
1152+
"this release. This mirrors the Helm `--take-ownership` flag.",
1153+
},
11371154
"renderSubchartNotes": {
11381155
TypeSpec: pschema.TypeSpec{
11391156
Type: "boolean",

‎provider/pkg/provider/helm_release.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ type Release struct {
122122
Values map[string]any `json:"values,omitempty"`
123123
// If set, no CRDs will be installed. By default, CRDs are installed if not already present
124124
SkipCrds bool `json:"skipCrds,omitempty"`
125+
// If set, install/upgrade will skip the check for existing resource conflicts and take ownership
126+
// of the matching resources, adopting any that are not already managed by this release.
127+
TakeOwnership bool `json:"takeOwnership,omitempty"`
125128
// Time in seconds to wait for any individual kubernetes operation.
126129
Timeout int `json:"timeout,omitempty"`
127130
// Verify the package before installing it.
@@ -617,6 +620,7 @@ func (r *helmReleaseProvider) helmCreate(ctx context.Context, urn resource.URN,
617620
client.OutputDir = ""
618621
client.Atomic = newRelease.Atomic
619622
client.SkipCRDs = newRelease.SkipCrds
623+
client.TakeOwnership = newRelease.TakeOwnership
620624
client.SubNotes = newRelease.RenderSubchartNotes
621625
client.DisableOpenAPIValidation = newRelease.DisableOpenapiValidation
622626
client.Replace = newRelease.Replace
@@ -737,6 +741,7 @@ func (r *helmReleaseProvider) helmUpdate(newRelease, oldRelease *Release) error
737741
client.SubNotes = newRelease.RenderSubchartNotes
738742
client.WaitForJobs = !newRelease.SkipAwait && newRelease.WaitForJobs
739743
client.Force = newRelease.ForceUpdate
744+
client.TakeOwnership = newRelease.TakeOwnership
740745
client.ResetValues = newRelease.ResetValues
741746
client.ReuseValues = newRelease.ReuseValues
742747
client.Recreate = newRelease.RecreatePods

‎provider/pkg/provider/helm_release_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ images: ["bitnami/nginx"]
181181
},
182182
},
183183
},
184+
{
185+
name: "takeOwnership is decoded",
186+
given: resource.PropertyMap{
187+
"takeOwnership": resource.NewBoolProperty(true),
188+
},
189+
want: &Release{
190+
TakeOwnership: true,
191+
Values: map[string]any{},
192+
},
193+
},
184194
}
185195

186196
for _, tt := range tests {

‎sdk/dotnet/Helm/V3/Release.cs‎

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎sdk/go/kubernetes/helm/v3/release.go‎

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎sdk/java/src/main/java/com/pulumi/kubernetes/helm/v3/Release.java‎

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎sdk/java/src/main/java/com/pulumi/kubernetes/helm/v3/ReleaseArgs.java‎

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)