aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb/profile.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-01-24 15:40:12 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-19 19:12:04 -0700
commit17275e9b6899ba611458f8ca9aaa868c70d7d0cf (patch)
tree25169d02625832fb2eb7e5a9ff08c43737dd4ef6 /src/k8splugin/internal/rb/profile.go
parente50daed19bbaec979a91f2677289f1c2e6e0d0d9 (diff)
Bring in all the other helper code
Bring in all the helper functions added for end to end integration. This allows the api level upload of helm charts, profiles and also instantiation of said helm charts. P3: Plugin index is based on lowercase kind name whereas the map contains the correct case for kind. Convert to lower case before loading the plugin. Changes after rebasing on the new folder structure. Rebasing over the new folder structure P8: Add unit tests for Resolve function Fix the integration tests for createvnf I had to add a huge blob of base64 encoded data based on the profile and sample helm chart to test the flow. P12: Update the integration test with the rb_profile_id parameter Issue-ID: MULTICLOUD-291 Change-Id: If04c41cb185074989ab6c96557958140c43e456d Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/rb/profile.go')
-rw-r--r--src/k8splugin/internal/rb/profile.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go
index d78e32e4..086c3486 100644
--- a/src/k8splugin/internal/rb/profile.go
+++ b/src/k8splugin/internal/rb/profile.go
@@ -21,9 +21,12 @@ import (
"encoding/base64"
"k8splugin/internal/db"
"log"
+ "path/filepath"
uuid "github.com/hashicorp/go-uuid"
pkgerrors "github.com/pkg/errors"
+
+ "k8splugin/internal/helm"
)
// Profile contains the parameters needed for resource bundle (rb) profiles
@@ -216,3 +219,74 @@ func (v *ProfileClient) Download(id string) ([]byte, error) {
}
return nil, pkgerrors.New("Error downloading Profile content")
}
+
+//Resolve returns the path where the helm chart merged with
+//configuration overrides resides.
+func (v *ProfileClient) Resolve(id string, values []string) (map[string][]string, error) {
+
+ var retMap map[string][]string
+
+ //Download and process the profile first
+ //If everything seems okay, then download the definition
+ prData, err := v.Download(id)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Downloading Profile")
+ }
+
+ prPath, err := ExtractTarBall(bytes.NewBuffer(prData))
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Extracting Profile Content")
+ }
+
+ prYamlClient, err := ProcessProfileYaml(prPath, v.manifestName)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Processing Profile Manifest")
+ }
+
+ //Get the definition ID and download its contents
+ profile, err := v.Get(id)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Getting Profile")
+ }
+
+ definitionClient := NewDefinitionClient()
+
+ definition, err := definitionClient.Get(profile.RBDID)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Getting Definition Metadata")
+ }
+
+ defData, err := definitionClient.Download(profile.RBDID)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Downloading Definition")
+ }
+
+ chartBasePath, err := ExtractTarBall(bytes.NewBuffer(defData))
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Extracting Definition Charts")
+ }
+
+ //Copy the profile configresources to the chart locations
+ //Corresponds to the following from the profile yaml
+ // configresource:
+ // - filepath: config.yaml
+ // chartpath: chart/config/resources/config.yaml
+ err = prYamlClient.CopyConfigurationOverrides(chartBasePath)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Copying configresources to chart")
+ }
+
+ helmClient := helm.NewTemplateClient(profile.KubernetesVersion,
+ profile.Namespace,
+ profile.Name)
+
+ chartPath := filepath.Join(chartBasePath, definition.ChartName)
+ retMap, err = helmClient.GenerateKubernetesArtifacts(chartPath,
+ []string{prYamlClient.GetValues()},
+ values)
+ if err != nil {
+ return retMap, pkgerrors.Wrap(err, "Generate final k8s yaml")
+ }
+
+ return retMap, nil
+}