summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb/profile.go
diff options
context:
space:
mode:
authorVictor Morales <victor.morales@intel.com>2019-03-21 01:40:19 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-21 01:40:19 +0000
commit57ba15140f909434bd309a447c53eb6db4147f8f (patch)
tree623eeabee5b57c7d32cd80497309155da9a189f1 /src/k8splugin/internal/rb/profile.go
parent69320e75210709ad2dadf3c183289e9a67cf4817 (diff)
parent17275e9b6899ba611458f8ca9aaa868c70d7d0cf (diff)
Merge "Bring in all the other helper code"
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
+}