Skip to content

Commit

Permalink
Fixes to allow import of helm release (#2136)
Browse files Browse the repository at this point in the history
* Fixes to allow import of helm release

* Changelog

* Fix test
  • Loading branch information
viveklak committed Aug 15, 2022
1 parent cbc8c83 commit 5277945
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Fix Helm charts being ignored by policy packs. (https://github.com/pulumi/pulumi-kubernetes/pull/2133)
- Fix Helm charts being ignored by policy packs. (https://github.com/pulumi/pulumi-kubernetes/pull/2133)
- Fixes to allow import of helm release (https://github.com/pulumi/pulumi-kubernetes/pull/2136)

## 3.20.3 (August 9, 2022)

Expand Down
18 changes: 14 additions & 4 deletions provider/pkg/provider/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -347,10 +348,18 @@ func (r *helmReleaseProvider) Check(ctx context.Context, req *pulumirpc.CheckReq
}

resourceNames, err := r.computeResourceNames(new)
if err != nil {
if err != nil && errors.Is(err, fs.ErrNotExist) {
// Likely because the chart is not readily available (e.g. import of chart where no repo info is stored).
// Declare bankruptcy in being able to determine the underlying resources and hope for the best
// further down the operations.
resourceNames = nil
} else if err != nil {
return nil, err
}
new.ResourceNames = resourceNames

if len(new.ResourceNames) == 0 {
new.ResourceNames = resourceNames
}
logger.V(9).Infof("New: %+v", new)
news = resource.NewPropertyMap(new)
}
Expand Down Expand Up @@ -389,8 +398,9 @@ func (r *helmReleaseProvider) setDefaults(target resource.PropertyMap) {

skipAwaitVal, ok := target["skipAwait"]
if !ok || (skipAwaitVal.IsBool() && !skipAwaitVal.BoolValue()) {
timeout, has := target["timeout"]
if !has || (timeout.IsNumber() && timeout.NumberValue() == 0) {
// If timeout is specified (even if zero value), use that. Otherwise use default.
_, has := target["timeout"]
if !has {
target["timeout"] = resource.NewNumberProperty(defaultTimeoutSeconds)
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/sdk/go/helm-release-import/step1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func main() {
Chart: pulumi.String("nginx"),
Version: pulumi.String("6.0.5"),
Values: pulumi.Map{"service": pulumi.StringMap{"type": pulumi.String("ClusterIP")}},
Timeout: pulumi.Int(300),
// Timeouts are not recorded in the release by Helm either.
Timeout: pulumi.Int(0),
}, pulumi.Import(pulumi.ID(fmt.Sprintf("%s/mynginx", namespace))))
if err != nil {
return err
Expand Down

0 comments on commit 5277945

Please sign in to comment.