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

Fix panic resulting from passing kubeconfig as object during provider creation #1373

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Add support for previewing Create and Update operations for API servers that support dry-run (https://github.com/pulumi/pulumi-kubernetes/pull/1355)
- Fix panic introduced in #1355 (https://github.com/pulumi/pulumi-kubernetes/pull/1368)
- Update Helm to v3.4.0 and client-go to v1.19.2 (https://github.com/pulumi/pulumi-kubernetes/pull/1360)
- Fix panic when provider is given kubeconfig as an object instead of string (https://github.com/pulumi/pulumi-kubernetes/pull/1373)

## 2.6.3 (October 12, 2020)

Expand Down
18 changes: 16 additions & 2 deletions provider/pkg/provider/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -75,14 +76,27 @@ func fqName(namespace, name string) string {
// --------------------------------------------------------------------------

// parseKubeconfigPropertyValue takes a PropertyValue that possibly contains a raw kubeconfig
// (YAML or JSON) string and attempts to unmarshal it into a Config struct. If the property value
// (YAML or JSON) string or map and attempts to unmarshal it into a Config struct. If the property value
// is empty, an empty Config is returned.
func parseKubeconfigPropertyValue(kubeconfig resource.PropertyValue) (*clientapi.Config, error) {
if kubeconfig.IsNull() {
return &clientapi.Config{}, nil
}

config, err := clientcmd.Load([]byte(kubeconfig.StringValue()))
var cfg []byte
if kubeconfig.IsString() {
cfg = []byte(kubeconfig.StringValue())
} else if kubeconfig.IsObject() {
raw := kubeconfig.ObjectValue().Mappable()
jsonBytes, err := json.Marshal(raw)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal kubeconfig: %v", err)
}
cfg = jsonBytes
} else {
return nil, fmt.Errorf("unexpected kubeconfig format, type: %v", kubeconfig.TypeString())
}
config, err := clientcmd.Load(cfg)
if err != nil {
return nil, fmt.Errorf("failed to parse kubeconfig: %v", err)
}
Expand Down