aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-16 18:09:13 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-16 18:09:27 -0700
commitbf49d552b003072c6bc64ae838a4699c1f4028bd (patch)
tree57c2b6130781f8215b0544e6b6f126ec8e2f8152 /src/k8splugin/internal/rb
parent244578803033f17781b10be283aef43fa6f0aa60 (diff)
Replace Kind with GroupVersionKind
Kind is not unique to track resources in Kubernetes GroupVersionKind is unique. We are just using that to track our data. It is abstracted behind a couple of new types for templates and resources. This change makes a lot of the old kind based operations redundant and simplified. Issue-ID: MULTICLOUD-573 Change-Id: I8f4ded2ba6a0821a8fbd679dc99ce3a44d805524 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/rb')
-rw-r--r--src/k8splugin/internal/rb/config_backend.go30
-rw-r--r--src/k8splugin/internal/rb/profile.go32
2 files changed, 31 insertions, 31 deletions
diff --git a/src/k8splugin/internal/rb/config_backend.go b/src/k8splugin/internal/rb/config_backend.go
index b61fc493..e2fa5b3c 100644
--- a/src/k8splugin/internal/rb/config_backend.go
+++ b/src/k8splugin/internal/rb/config_backend.go
@@ -19,16 +19,16 @@ package rb
import (
"bytes"
"encoding/json"
- "k8splugin/internal/db"
- "k8splugin/internal/helm"
+ "io/ioutil"
"log"
+ "path/filepath"
"strconv"
"strings"
-
- "io/ioutil"
- "path/filepath"
"sync"
+ "k8splugin/internal/db"
+ "k8splugin/internal/helm"
+
"github.com/ghodss/yaml"
pkgerrors "github.com/pkg/errors"
)
@@ -56,9 +56,9 @@ type ConfigVersionStore struct {
}
type configResourceList struct {
- retmap map[string][]string
- profile Profile
- action string
+ resourceTemplates []helm.KubernetesResourceTemplate
+ profile Profile
+ action string
}
type profileDataManager struct {
@@ -341,13 +341,13 @@ func scheduleResources(c chan configResourceList) {
//TODO: ADD Check to see if Application running
switch {
case data.action == "POST":
- log.Printf("[scheduleResources]: POST %v %v", data.profile, data.retmap)
+ log.Printf("[scheduleResources]: POST %v %v", data.profile, data.resourceTemplates)
//TODO: Needs to add code to call Kubectl create
case data.action == "PUT":
- log.Printf("[scheduleResources]: PUT %v %v", data.profile, data.retmap)
+ log.Printf("[scheduleResources]: PUT %v %v", data.profile, data.resourceTemplates)
//TODO: Needs to add code to call Kubectl apply
case data.action == "DELETE":
- log.Printf("[scheduleResources]: DELETE %v %v", data.profile, data.retmap)
+ log.Printf("[scheduleResources]: DELETE %v %v", data.profile, data.resourceTemplates)
//TODO: Needs to add code to call Kubectl delete
}
@@ -358,7 +358,7 @@ func scheduleResources(c chan configResourceList) {
//configuration overrides resides.
var resolve = func(rbName, rbVersion, profileName string, p Config) (configResourceList, error) {
- var retMap map[string][]string
+ var resTemplates []helm.KubernetesResourceTemplate
profile, err := NewProfileClient().Get(rbName, rbVersion, profileName)
if err != nil {
@@ -408,15 +408,15 @@ var resolve = func(rbName, rbVersion, profileName string, p Config) (configResou
profile.ReleaseName)
chartPath := filepath.Join(chartBasePath, t.ChartName)
- retMap, err = helmClient.GenerateKubernetesArtifacts(chartPath,
+ resTemplates, err = helmClient.GenerateKubernetesArtifacts(chartPath,
[]string{outputfile.Name()},
nil)
if err != nil {
return configResourceList{}, pkgerrors.Wrap(err, "Generate final k8s yaml")
}
crl := configResourceList{
- retmap: retMap,
- profile: profile,
+ resourceTemplates: resTemplates,
+ profile: profile,
}
return crl, nil
diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go
index 679815ac..7d3902f2 100644
--- a/src/k8splugin/internal/rb/profile.go
+++ b/src/k8splugin/internal/rb/profile.go
@@ -20,12 +20,12 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
- "k8splugin/internal/db"
"path/filepath"
- pkgerrors "github.com/pkg/errors"
-
+ "k8splugin/internal/db"
"k8splugin/internal/helm"
+
+ pkgerrors "github.com/pkg/errors"
)
// Profile contains the parameters needed for resource bundle (rb) profiles
@@ -236,48 +236,48 @@ func (v *ProfileClient) Download(rbName, rbVersion, prName string) ([]byte, erro
//Resolve returns the path where the helm chart merged with
//configuration overrides resides.
func (v *ProfileClient) Resolve(rbName string, rbVersion string,
- profileName string, values []string) (map[string][]string, error) {
+ profileName string, values []string) ([]helm.KubernetesResourceTemplate, error) {
- var retMap map[string][]string
+ var sortedTemplates []helm.KubernetesResourceTemplate
//Download and process the profile first
//If everything seems okay, then download the definition
prData, err := v.Download(rbName, rbVersion, profileName)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Downloading Profile")
+ return sortedTemplates, pkgerrors.Wrap(err, "Downloading Profile")
}
prPath, err := ExtractTarBall(bytes.NewBuffer(prData))
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Extracting Profile Content")
+ return sortedTemplates, pkgerrors.Wrap(err, "Extracting Profile Content")
}
prYamlClient, err := ProcessProfileYaml(prPath, v.manifestName)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Processing Profile Manifest")
+ return sortedTemplates, pkgerrors.Wrap(err, "Processing Profile Manifest")
}
definitionClient := NewDefinitionClient()
definition, err := definitionClient.Get(rbName, rbVersion)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Getting Definition Metadata")
+ return sortedTemplates, pkgerrors.Wrap(err, "Getting Definition Metadata")
}
defData, err := definitionClient.Download(rbName, rbVersion)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Downloading Definition")
+ return sortedTemplates, pkgerrors.Wrap(err, "Downloading Definition")
}
chartBasePath, err := ExtractTarBall(bytes.NewBuffer(defData))
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Extracting Definition Charts")
+ return sortedTemplates, pkgerrors.Wrap(err, "Extracting Definition Charts")
}
//Get the definition ID and download its contents
profile, err := v.Get(rbName, rbVersion, profileName)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Getting Profile")
+ return sortedTemplates, pkgerrors.Wrap(err, "Getting Profile")
}
//Copy the profile configresources to the chart locations
@@ -287,7 +287,7 @@ func (v *ProfileClient) Resolve(rbName string, rbVersion string,
// chartpath: chart/config/resources/config.yaml
err = prYamlClient.CopyConfigurationOverrides(chartBasePath)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Copying configresources to chart")
+ return sortedTemplates, pkgerrors.Wrap(err, "Copying configresources to chart")
}
helmClient := helm.NewTemplateClient(profile.KubernetesVersion,
@@ -295,12 +295,12 @@ func (v *ProfileClient) Resolve(rbName string, rbVersion string,
profile.ReleaseName)
chartPath := filepath.Join(chartBasePath, definition.ChartName)
- retMap, err = helmClient.GenerateKubernetesArtifacts(chartPath,
+ sortedTemplates, err = helmClient.GenerateKubernetesArtifacts(chartPath,
[]string{prYamlClient.GetValues()},
values)
if err != nil {
- return retMap, pkgerrors.Wrap(err, "Generate final k8s yaml")
+ return sortedTemplates, pkgerrors.Wrap(err, "Generate final k8s yaml")
}
- return retMap, nil
+ return sortedTemplates, nil
}