Add support for override values 86/99686/2
authorKiran Kamineni <kiran.k.kamineni@intel.com>
Tue, 17 Dec 2019 00:04:55 +0000 (16:04 -0800)
committerKiran Kamineni <kiran.k.kamineni@intel.com>
Fri, 20 Dec 2019 00:52:16 +0000 (16:52 -0800)
Add support for override values which are equivalent to
HELM --set options.
A typical JSON with this option would look like this:
{
  "rb-name": "edgex",
  "rb-version": "v1",
  "profile-name": "profile1",
  "override-values": {
    "edgex-core-consul.enabled": "false",
    "edgex-core-data.enabled": "false"
  },
  "cloud-region": "k8sregionone"
}

Issue-ID: MULTICLOUD-863
Change-Id: I050b4c1a2922bfe1206964a0135863448638e4ef
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
src/k8splugin/internal/app/instance.go

index fef9962..5d8b210 100644 (file)
@@ -32,19 +32,21 @@ import (
 // InstanceRequest contains the parameters needed for instantiation
 // of profiles
 type InstanceRequest struct {
-       RBName      string            `json:"rb-name"`
-       RBVersion   string            `json:"rb-version"`
-       ProfileName string            `json:"profile-name"`
-       CloudRegion string            `json:"cloud-region"`
-       Labels      map[string]string `json:"labels"`
+       RBName         string            `json:"rb-name"`
+       RBVersion      string            `json:"rb-version"`
+       ProfileName    string            `json:"profile-name"`
+       CloudRegion    string            `json:"cloud-region"`
+       Labels         map[string]string `json:"labels"`
+       OverrideValues map[string]string `json:"override-values"`
 }
 
 // InstanceResponse contains the response from instantiation
 type InstanceResponse struct {
-       ID        string                    `json:"id"`
-       Request   InstanceRequest           `json:"request"`
-       Namespace string                    `json:"namespace"`
-       Resources []helm.KubernetesResource `json:"resources"`
+       ID             string                    `json:"id"`
+       Request        InstanceRequest           `json:"request"`
+       Namespace      string                    `json:"namespace"`
+       Resources      []helm.KubernetesResource `json:"resources"`
+       OverrideValues map[string]string         `json:"override-values"`
 }
 
 // InstanceMiniResponse contains the response from instantiation
@@ -133,7 +135,14 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) {
                return InstanceResponse{}, pkgerrors.New("Unable to find Profile to create instance")
        }
 
+       //Convert override values from map to array of strings of the following format
+       //foo=bar
        overrideValues := []string{}
+       if i.OverrideValues != nil {
+               for k, v := range i.OverrideValues {
+                       overrideValues = append(overrideValues, k+"="+v)
+               }
+       }
 
        //Execute the kubernetes create command
        sortedTemplates, err := rb.NewProfileClient().Resolve(i.RBName, i.RBVersion, i.ProfileName, overrideValues)