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

Always override namespace for helm release operations #1747

Merged
merged 3 commits into from
Oct 2, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## HEAD (Unreleased)
(None)
- Always override namespace for helm release operations (https://github.com/pulumi/pulumi-kubernetes/pull/1747)

## 3.7.3 (September 30, 2021)
- Use helm release's namespace on templates where namespace is left unspecified (https://github.com/pulumi/pulumi-kubernetes/pull/1733)
Expand Down
24 changes: 11 additions & 13 deletions provider/pkg/provider/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,18 @@ func debug(format string, a ...interface{}) {
logger.V(9).Infof("[DEBUG] %s", fmt.Sprintf(format, a...))
}

func (r *helmReleaseProvider) getActionConfig(namespace string, override bool) (*action.Configuration, error) {
func (r *helmReleaseProvider) getActionConfig(namespace string) (*action.Configuration, error) {
conf := new(action.Configuration)
var overrides clientcmd.ConfigOverrides
if r.defaultOverrides != nil {
overrides = *r.defaultOverrides
}

if override {
// This essentially points the client to use the specified namespace when a namespaced
// object doesn't have the namespace specified. This allows us to interpolate the
// release's namespace as the default namespace on charts with templates that don't
// explicitly set the namespace (e.g. through namespace: {{ .Release.Namespace }}).
overrides.Context.Namespace = namespace
}
// This essentially points the client to use the specified namespace when a namespaced
// object doesn't have the namespace specified. This allows us to interpolate the
// release's namespace as the default namespace on charts with templates that don't
// explicitly set the namespace (e.g. through namespace: {{ .Release.Namespace }}).
overrides.Context.Namespace = namespace

var clientConfig clientcmd.ClientConfig
if r.apiConfig != nil {
Expand Down Expand Up @@ -307,7 +305,7 @@ func (r *helmReleaseProvider) Check(ctx context.Context, req *pulumirpc.CheckReq
templateRelease = true
} else {
assignNameIfAutonameable(new, news, "release")
conf, err := r.getActionConfig(new.Namespace, false)
conf, err := r.getActionConfig(new.Namespace)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -377,7 +375,7 @@ func (r *helmReleaseProvider) Check(ctx context.Context, req *pulumirpc.CheckReq
}

func (r *helmReleaseProvider) helmCreate(ctx context.Context, urn resource.URN, news resource.PropertyMap, newRelease *Release) error {
conf, err := r.getActionConfig(newRelease.Namespace, true)
conf, err := r.getActionConfig(newRelease.Namespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -523,7 +521,7 @@ func (r *helmReleaseProvider) helmUpdate(ctx context.Context, urn resource.URN,
}
}

actionConfig, err := r.getActionConfig(oldRelease.Namespace, true)
actionConfig, err := r.getActionConfig(oldRelease.Namespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -834,7 +832,7 @@ func (r *helmReleaseProvider) Read(ctx context.Context, req *pulumirpc.ReadReque

logger.V(9).Infof("%s Starting import for %s/%s", label, namespace, name)

actionConfig, err := r.getActionConfig(namespace, false)
actionConfig, err := r.getActionConfig(namespace)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -975,7 +973,7 @@ func (r *helmReleaseProvider) Delete(ctx context.Context, req *pulumirpc.DeleteR
}

namespace := release.Namespace
actionConfig, err := r.getActionConfig(namespace, false)
actionConfig, err := r.getActionConfig(namespace)
if err != nil {
return nil, err
}
Expand Down