summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb/profile.go
diff options
context:
space:
mode:
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
+}