Skip to content

Commit

Permalink
Fix panic resulting from passing kubeconfig as object during provider…
Browse files Browse the repository at this point in the history
… creation (#1373)
  • Loading branch information
EvanBoyle committed Nov 12, 2020
1 parent 028ce0f commit f1eacfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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)
- Fix concurrency issue in Helm + .NET SDK [#1311](https://github.com/pulumi/pulumi-kubernetes/issues/1311) and [#1374](https://github.com/pulumi/pulumi-kubernetes/issues/1374)

## 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

0 comments on commit f1eacfe

Please sign in to comment.