Repository: crossplane-contrib/provider-helm
Pull request #28 (2020-09-11 15:05:58)

Better representation of Inline values
This PR allows to represent inline values as maps instead of string.
In other words, changes following:

```
    ...
    values: |
      mariadb:
        enabled: false
        ...
```

to:


```
    ...
    values: 
      mariadb:
        enabled: false
        ...
```
Signed-off-by: Hasan Turken <turkenh@gmail.com>


Patch:
diff --git a/apis/release/v1alpha1/types.go b/apis/release/v1alpha1/types.go
index b1274d1..2740e67 100644
--- a/apis/release/v1alpha1/types.go
+++ b/apis/release/v1alpha1/types.go
@@ -20,6 +20,7 @@ import (
 	runtimev1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
 	"helm.sh/helm/v3/pkg/release"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	runtime "k8s.io/apimachinery/pkg/runtime"
 )
 
 // A ChartSpec defines the chart spec for a Release
@@ -58,10 +59,9 @@ type SetVal struct {
 
 // ValuesSpec defines the Helm value overrides spec for a Release
 type ValuesSpec struct {
-	// TODO: investigate using map[string]interface{} instead
-	Values     string            `json:"values,omitempty"`
-	ValuesFrom []ValueFromSource `json:"valuesFrom,omitempty"`
-	Set        []SetVal          `json:"set,omitempty"`
+	Values     runtime.RawExtension `json:"values,omitempty"`
+	ValuesFrom []ValueFromSource    `json:"valuesFrom,omitempty"`
+	Set        []SetVal             `json:"set,omitempty"`
 }
 
 // ReleaseParameters are the configurable fields of a Release.
diff --git a/apis/release/v1alpha1/zz_generated.deepcopy.go b/apis/release/v1alpha1/zz_generated.deepcopy.go
index b8c25d0..5c7526e 100644
--- a/apis/release/v1alpha1/zz_generated.deepcopy.go
+++ b/apis/release/v1alpha1/zz_generated.deepcopy.go
@@ -21,7 +21,7 @@ limitations under the License.
 package v1alpha1
 
 import (
-	runtime "k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/runtime"
 )
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
@@ -256,6 +256,7 @@ func (in *ValueFromSource) DeepCopy() *ValueFromSource {
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ValuesSpec) DeepCopyInto(out *ValuesSpec) {
 	*out = *in
+	in.Values.DeepCopyInto(&out.Values)
 	if in.ValuesFrom != nil {
 		in, out := &in.ValuesFrom, &out.ValuesFrom
 		*out = make([]ValueFromSource, len(*in))
diff --git a/config/crd/helm.crossplane.io_releases.yaml b/config/crd/helm.crossplane.io_releases.yaml
index 86a87cc..a3cdf31 100644
--- a/config/crd/helm.crossplane.io_releases.yaml
+++ b/config/crd/helm.crossplane.io_releases.yaml
@@ -210,8 +210,7 @@ spec:
                     type: object
                   type: array
                 values:
-                  description: 'TODO: investigate using map[string]interface{} instead'
-                  type: string
+                  type: object
                 valuesFrom:
                   items:
                     description: ValueFromSource represents source of a value
diff --git a/examples/in-composition/composition.yaml b/examples/in-composition/composition.yaml
index 32dae28..45ddfa6 100644
--- a/examples/in-composition/composition.yaml
+++ b/examples/in-composition/composition.yaml
@@ -185,14 +185,13 @@ spec:
               repository: https://turkenh.github.io/bitnami-charts
               version: 9.5.1
             namespace: wordpress
-            values: |
+            values:
               mariadb:
                 enabled: false
               externalDatabase:
                 create: true
                 database: wordpress
                 port: 3306
-
             set: 
               - name: externalDatabase.host
                 valueFrom: 
diff --git a/examples/sample/patch-release.yaml b/examples/sample/patch-release.yaml
index 9835ad4..6b77e01 100644
--- a/examples/sample/patch-release.yaml
+++ b/examples/sample/patch-release.yaml
@@ -31,7 +31,7 @@ spec:
       repository: https://charts.bitnami.com/bitnami
       version: 9.3.19
     namespace: wordpress
-    values: |
+    values:
       param1: value1
       param2: 1
     set:
diff --git a/examples/sample/release.yaml b/examples/sample/release.yaml
index c2780a6..fb1380d 100644
--- a/examples/sample/release.yaml
+++ b/examples/sample/release.yaml
@@ -13,7 +13,7 @@ spec:
 #        name: museum-creds
 #        namespace: default
     namespace: wordpress
-    values: |
+    values:
       param1: value1
       param2: 1
     set:
diff --git a/pkg/controller/values.go b/pkg/controller/values.go
index d91dab0..5ffa196 100644
--- a/pkg/controller/values.go
+++ b/pkg/controller/values.go
@@ -57,7 +57,7 @@ func composeValuesFromSpec(ctx context.Context, kube client.Client, spec v1alpha
 	}
 
 	var inlineVals map[string]interface{}
-	err := yaml.Unmarshal([]byte(spec.Values), &inlineVals)
+	err := yaml.Unmarshal(spec.Values.Raw, &inlineVals)
 	if err != nil {
 		return nil, errors.Wrap(err, errFailedToUnmarshalDesiredValues)
 	}


Test patch:
diff --git a/pkg/controller/observe_test.go b/pkg/controller/observe_test.go
index 2e1a6dc..60f741a 100644
--- a/pkg/controller/observe_test.go
+++ b/pkg/controller/observe_test.go
@@ -4,6 +4,8 @@ import (
 	"context"
 	"testing"
 
+	"k8s.io/apimachinery/pkg/runtime"
+
 	"github.com/crossplane/crossplane-runtime/pkg/test"
 	"github.com/google/go-cmp/cmp"
 	"github.com/pkg/errors"
@@ -164,7 +166,10 @@ func Test_isUpToDate(t *testing.T) {
 						Version: testVersion,
 					},
 					ValuesSpec: v1alpha1.ValuesSpec{
-						Values: "invalid-yaml",
+						Values: runtime.RawExtension{
+							Raw:    []byte("invalid-yaml"),
+							Object: nil,
+						},
 					},
 				},
 				observed: &release.Release{
@@ -199,7 +204,9 @@ func Test_isUpToDate(t *testing.T) {
 						Version: testVersion,
 					},
 					ValuesSpec: v1alpha1.ValuesSpec{
-						Values: testReleaseConfigStr,
+						Values: runtime.RawExtension{
+							Raw: []byte(testReleaseConfigStr),
+						},
 					},
 				},
 				observed: &release.Release{
@@ -230,7 +237,9 @@ func Test_isUpToDate(t *testing.T) {
 						Version: "another-version",
 					},
 					ValuesSpec: v1alpha1.ValuesSpec{
-						Values: testReleaseConfigStr,
+						Values: runtime.RawExtension{
+							Raw: []byte(testReleaseConfigStr),
+						},
 					},
 				},
 				observed: &release.Release{
@@ -261,7 +270,9 @@ func Test_isUpToDate(t *testing.T) {
 						Version: testVersion,
 					},
 					ValuesSpec: v1alpha1.ValuesSpec{
-						Values: "keyA: valX",
+						Values: runtime.RawExtension{
+							Raw: []byte("keyA: valX"),
+						},
 					},
 				},
 				observed: &release.Release{
@@ -292,7 +303,9 @@ func Test_isUpToDate(t *testing.T) {
 						Version: testVersion,
 					},
 					ValuesSpec: v1alpha1.ValuesSpec{
-						Values: testReleaseConfigStr,
+						Values: runtime.RawExtension{
+							Raw: []byte(testReleaseConfigStr),
+						},
 					},
 				},
 				observed: &release.Release{
@@ -323,7 +336,9 @@ func Test_isUpToDate(t *testing.T) {
 						Version: testVersion,
 					},
 					ValuesSpec: v1alpha1.ValuesSpec{
-						Values: testReleaseConfigStr,
+						Values: runtime.RawExtension{
+							Raw: []byte(testReleaseConfigStr),
+						},
 					},
 				},
 				observed: &release.Release{
diff --git a/pkg/controller/values_test.go b/pkg/controller/values_test.go
index a91323f..6ce3813 100644
--- a/pkg/controller/values_test.go
+++ b/pkg/controller/values_test.go
@@ -37,7 +37,9 @@ func Test_composeValuesFromSpec(t *testing.T) {
 					MockGet: nil,
 				},
 				spec: v1alpha1.ValuesSpec{
-					Values:     testReleaseConfigStr,
+					Values: runtime.RawExtension{
+						Raw: []byte(testReleaseConfigStr),
+					},
 					ValuesFrom: nil,
 					Set:        nil,
 				},
@@ -53,7 +55,9 @@ func Test_composeValuesFromSpec(t *testing.T) {
 					MockGet: nil,
 				},
 				spec: v1alpha1.ValuesSpec{
-					Values:     "invalid-yaml",
+					Values: runtime.RawExtension{
+						Raw: []byte("invalid-yaml"),
+					},
 					ValuesFrom: nil,
 					Set:        nil,
 				},
@@ -177,11 +181,13 @@ func Test_composeValuesFromSpec(t *testing.T) {
 					MockGet: nil,
 				},
 				spec: v1alpha1.ValuesSpec{
-					Values: `
+					Values: runtime.RawExtension{
+						Raw: []byte(`
 keyA: valA
 keyB:
   subKeyA: subValA
-`,
+`),
+					},
 					ValuesFrom: nil,
 					Set: []v1alpha1.SetVal{
 						{
@@ -236,11 +242,13 @@ keyB:
 					},
 				},
 				spec: v1alpha1.ValuesSpec{
-					Values: `
+					Values: runtime.RawExtension{
+						Raw: []byte(`
 keyA: valA
 keyB:
   subKeyA: subValA
-`,
+`),
+					},
 					ValuesFrom: nil,
 					Set: []v1alpha1.SetVal{
 						{
@@ -280,11 +288,13 @@ keyB:
 					},
 				},
 				spec: v1alpha1.ValuesSpec{
-					Values: `
+					Values: runtime.RawExtension{
+						Raw: []byte(`
 keyA: valA
 keyB:
   subKeyA: subValA
-`,
+`),
+					},
 					ValuesFrom: nil,
 					Set: []v1alpha1.SetVal{
 						{