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

Support local charts in helm.Release resource #1809

Merged
merged 5 commits into from
Dec 4, 2021
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Breaking change note:
resource definition from the Go SDK. Following this change, use the Provider resource at
`github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes` instead.

- Helm Release: Make RepositoryOpts optional (https://github.com/pulumi/pulumi-kubernetes/pull/1806)
- Helm Release: Make RepositoryOpts optional (https://github.com/pulumi/pulumi-kubernetes/pull/1806)
- Helm Release: Support local charts (https://github.com/pulumi/pulumi-kubernetes/pull/1809)
- Update pulumi dependencies v3.19.0 (https://github.com/pulumi/pulumi-kubernetes/pull/1816)
- [go/sdk] Remove deprecated providers/Provider resource (https://github.com/pulumi/pulumi-kubernetes/pull/1817)

Expand Down
71 changes: 36 additions & 35 deletions provider/pkg/provider/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,26 +355,19 @@ func (r *helmReleaseProvider) Check(ctx context.Context, req *pulumirpc.CheckReq
return &pulumirpc.CheckResponse{Inputs: autonamedInputs}, nil
}

func (r *helmReleaseProvider) helmCreate(ctx context.Context, urn resource.URN, news resource.PropertyMap, newRelease *Release) error {
func (r *helmReleaseProvider) helmCreate(ctx context.Context, urn resource.URN, newRelease *Release) error {
conf, err := r.getActionConfig(newRelease.Namespace)
if err != nil {
return err
}
client := action.NewInstall(conf)
logger.V(9).Infof("Looking up chart path options for release: %q", newRelease.Name)
cpo, chartName, err := chartPathOptions(newRelease)
if err != nil {
return err
}

logger.V(9).Infof("getChart: %q settings: %#v, cpo: %+v", chartName, r.settings, cpo)
c, path, err := getChart(chartName, r.settings, cpo)
c, path, err := getChart(r.settings, newRelease)
if err != nil {
logger.V(9).Infof("getChart failed: %+v", err)
return err
}

logger.V(9).Infof("Checking chart dependencies for chart: %q with path: %q", chartName, path)
logger.V(9).Infof("Checking chart dependencies for chart: %q with path: %q", newRelease.Chart, path)
// check and update the chart's dependencies if needed
updated, err := checkChartDependencies(
c,
Expand Down Expand Up @@ -405,7 +398,6 @@ func (r *helmReleaseProvider) helmCreate(ctx context.Context, urn resource.URN,
return err
}

client.ChartPathOptions = *cpo
client.ClientOnly = false
client.DisableHooks = newRelease.DisableWebhooks
client.Wait = !newRelease.SkipAwait
Expand Down Expand Up @@ -467,14 +459,9 @@ func (r *helmReleaseProvider) helmCreate(ctx context.Context, urn resource.URN,
}

func (r *helmReleaseProvider) helmUpdate(ctx context.Context, urn resource.URN, news resource.PropertyMap, newRelease, oldRelease *Release) error {
cpo, chartName, err := chartPathOptions(newRelease)
if err != nil {
return err
}

logger.V(9).Infof("getChart: %q settings: %#v, cpo: %+v", chartName, r.settings, cpo)
logger.V(9).Infof("getChart: %q settings: %#v", newRelease.Chart, r.settings)
// Get Chart metadata, if we fail - we're done
chart, path, err := getChart(chartName, r.settings, cpo)
chart, path, err := getChart(r.settings, newRelease)
if err != nil {
return err
}
Expand All @@ -497,7 +484,7 @@ func (r *helmReleaseProvider) helmUpdate(ctx context.Context, urn resource.URN,
}

if newRelease.Lint {
if err := resourceReleaseValidate(newRelease, news, r.settings, cpo); err != nil {
if err := resourceReleaseValidate(newRelease, r.settings); err != nil {
return err
}
}
Expand All @@ -513,7 +500,6 @@ func (r *helmReleaseProvider) helmUpdate(ctx context.Context, urn resource.URN,
}

client := action.NewUpgrade(actionConfig)
client.ChartPathOptions = *cpo
client.Devel = newRelease.Devel
client.Namespace = newRelease.Namespace
client.Timeout = time.Duration(newRelease.Timeout) * time.Second
Expand Down Expand Up @@ -689,7 +675,7 @@ func (r *helmReleaseProvider) Diff(ctx context.Context, req *pulumirpc.DiffReque
}, nil
}

func resourceReleaseValidate(release *Release, pm resource.PropertyMap, settings *cli.EnvSettings, cpo *action.ChartPathOptions) error {
func resourceReleaseValidate(release *Release, settings *cli.EnvSettings) error {
cpo, name, err := chartPathOptions(release)
if err != nil {
return fmt.Errorf("malformed values: \n\t%s", err)
Expand Down Expand Up @@ -753,7 +739,7 @@ func (r *helmReleaseProvider) Create(ctx context.Context, req *pulumirpc.CreateR
}

if !req.GetPreview() {
if err = r.helmCreate(ctx, urn, news, newRelease); err != nil {
if err = r.helmCreate(ctx, urn, newRelease); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -837,16 +823,11 @@ func (r *helmReleaseProvider) Read(ctx context.Context, req *pulumirpc.ReadReque
return nil, err
}

cpo, chartName, err := chartPathOptions(existingRelease)
if err != nil {
return nil, err
}

logger.V(9).Infof("Trying to get chart: %q, settings: %#v", chartName, r.settings)
logger.V(9).Infof("Trying to get chart: %q, settings: %#v", existingRelease.Chart, r.settings)

// Helm itself doesn't store any information about where the Chart was downloaded from.
// We need the user to ensure the chart is downloadable by using `helm repo add` etc.
_, _, err = getChart(chartName, r.settings, cpo)
_, _, err = getChart(r.settings, existingRelease)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1197,14 +1178,34 @@ func mergeMaps(a, b map[string]interface{}) map[string]interface{} {
return out
}

func getChart(name string, settings *cli.EnvSettings, cpo *action.ChartPathOptions) (*helmchart.Chart, string, error) {
path, err := cpo.LocateChart(name, settings)
if err != nil {
return nil, "", err
func getChart(settings *cli.EnvSettings, newRelease *Release) (*helmchart.Chart, string, error) {
logger.V(9).Infof("Looking up chart path options for release: %q", newRelease.Name)

var path string
if newRelease.RepositoryOpts != nil {
cpo, chartName, err := chartPathOptions(newRelease)
if err != nil {
return nil, "", err
}

path, err = cpo.LocateChart(chartName, settings)
if err != nil {
return nil, "", err
}

logger.V(9).Infof("Trying to load chart: %q from path: %q", chartName, path)
c, err := loader.Load(path)
if err != nil {
return nil, "", err
}

return c, path, nil
}

logger.V(9).Infof("Trying to load chart: %q from path: %q", name, path)
c, err := loader.Load(path)
path = newRelease.Chart

logger.V(9).Infof("Trying to load chart from path: %q", path)
c, err := loader.Load(newRelease.Chart)
if err != nil {
return nil, "", err
}
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
}
}
} else {
// Use client-go to resolve the final configuration values for the client. Typically these
// values would would reside in the $KUBECONFIG file, but can also be altered in several
// Use client-go to resolve the final configuration values for the client. Typically, these
// values would reside in the $KUBECONFIG file, but can also be altered in several
// places, including in env variables, client-go default values, and (if we allowed it) CLI
// flags.
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
Expand Down
15 changes: 8 additions & 7 deletions tests/sdk/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ func TestGo(t *testing.T) {
options := baseOptions.With(integration.ProgramTestOptions{
Dir: filepath.Join(cwd, "helm-release", "step1"),
Quick: true,
EditDirs: []integration.EditDir{
{
Dir: filepath.Join("helm-release", "step2"),
Additive: true,
ExpectNoChanges: true,
},
},
})
integration.ProgramTest(t, &options)
})

t.Run("Helm Release Local", func(t *testing.T) {
options := baseOptions.With(integration.ProgramTestOptions{
Dir: filepath.Join(cwd, "helm-release-local", "step1"),
Quick: true,
})
integration.ProgramTest(t, &options)
})
Expand Down
3 changes: 3 additions & 0 deletions tests/sdk/go/helm-release-local/step1/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: go_helm_release
description: Test Kubernetes Helm Release resource with remote Chart.
runtime: go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ns, err := corev1.NewNamespace(ctx, "test", &corev1.NamespaceArgs{})
if err != nil {
return err
}

rel, err := helm.NewRelease(ctx, "test", &helm.ReleaseArgs{
Chart: pulumi.String("nginx"),
Version: pulumi.String("6.0.4"),
RepositoryOpts: helm.RepositoryOptsArgs{
Repo: pulumi.String("https://charts.bitnami.com/bitnami"),
},
Values: pulumi.Map{"service": pulumi.StringMap{"type": pulumi.String("ClusterIP")}},
Timeout: pulumi.Int(300),
Chart: pulumi.String("nginx"),
Namespace: ns.Metadata.Name(),
Values: pulumi.Map{"service": pulumi.StringMap{"type": pulumi.String("ClusterIP")}},
Timeout: pulumi.Int(300),
})
if err != nil {
return err
Expand Down
21 changes: 21 additions & 0 deletions tests/sdk/go/helm-release-local/step1/nginx/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
21 changes: 21 additions & 0 deletions tests/sdk/go/helm-release-local/step1/nginx/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
annotations:
category: Infrastructure
apiVersion: v1
appVersion: 1.19.1
description: Chart for the nginx server
engine: gotpl
home: http://www.nginx.org
icon: https://bitnami.com/assets/stacks/nginx/img/nginx-stack-220x234.png
keywords:
- nginx
- http
- web
- www
- reverse proxy
maintainers:
- email: containers@bitnami.com
name: Bitnami
name: nginx
sources:
- https://github.com/bitnami/bitnami-docker-nginx
version: 6.0.5
Loading