aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app/vnfhelper.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/app/vnfhelper.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/app/vnfhelper.go')
-rw-r--r--src/k8splugin/internal/app/vnfhelper.go50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/k8splugin/internal/app/vnfhelper.go b/src/k8splugin/internal/app/vnfhelper.go
index 3deb9f21..f7c4596d 100644
--- a/src/k8splugin/internal/app/vnfhelper.go
+++ b/src/k8splugin/internal/app/vnfhelper.go
@@ -19,6 +19,7 @@ import (
"log"
"math/rand"
"os"
+ "strings"
"k8s.io/client-go/kubernetes"
@@ -26,6 +27,7 @@ import (
yaml "gopkg.in/yaml.v2"
utils "k8splugin/internal"
+ "k8splugin/internal/rb"
)
func generateExternalVNFID() string {
@@ -71,40 +73,46 @@ func ensuresNamespace(namespace string, kubeclient kubernetes.Interface) error {
}
// CreateVNF reads the CSAR files from the files system and creates them one by one
-var CreateVNF = func(csarID string, cloudRegionID string, namespace string, kubeclient *kubernetes.Clientset) (string, map[string][]string, error) {
- if err := ensuresNamespace(namespace, kubeclient); err != nil {
- return "", nil, pkgerrors.Wrap(err, "Error while ensuring namespace: "+namespace)
+var CreateVNF = func(csarID string, cloudRegionID string, rbProfileID string, kubeclient *kubernetes.Clientset) (string, map[string][]string, error) {
+
+ overrideValues := []string{}
+ rbProfileClient := rb.NewProfileClient()
+ rbProfile, err := rbProfileClient.Get(rbProfileID)
+ if err != nil {
+ return "", nil, pkgerrors.Wrap(err, "Error getting profile info")
}
- externalVNFID := generateExternalVNFID()
- internalVNFID := cloudRegionID + "-" + namespace + "-" + externalVNFID
- csarDirPath := os.Getenv("CSAR_DIR") + "/" + csarID
- metadataYAMLPath := csarDirPath + "/metadata.yaml"
+ //Make sure that the namespace exists before trying to create any resources
+ if err := ensuresNamespace(rbProfile.Namespace, kubeclient); err != nil {
+ return "", nil, pkgerrors.Wrap(err, "Error while ensuring namespace: "+rbProfile.Namespace)
+ }
+ externalVNFID := generateExternalVNFID()
+ internalVNFID := cloudRegionID + "-" + rbProfile.Namespace + "-" + externalVNFID
- log.Println("Reading " + metadataYAMLPath + " file")
- metadataFile, err := ReadMetadataFile(metadataYAMLPath)
+ metaMap, err := rb.NewProfileClient().Resolve(rbProfileID, overrideValues)
if err != nil {
- return "", nil, pkgerrors.Wrap(err, "Error while reading Metadata File: "+metadataYAMLPath)
+ return "", nil, pkgerrors.Wrap(err, "Error resolving helm charts")
}
- var path string
resourceYAMLNameMap := make(map[string][]string)
- // Iterates over the resources defined in the metadata file to create kubernetes resources
- log.Println(string(len(metadataFile.ResourceTypePathMap)) + " resource(s) type(s) to be processed")
- for resource, fileNames := range metadataFile.ResourceTypePathMap {
+ // Iterates over the resources defined in the metadata map to create kubernetes resources
+ log.Printf("%d resource(s) type(s) to be processed", len(metaMap))
+ for res, filePaths := range metaMap {
+ //Convert resource to lower case as the map index is lowercase
+ resource := strings.ToLower(res)
log.Println("Processing items of " + string(resource) + " resource")
var resourcesCreated []string
- for _, filename := range fileNames {
- path = csarDirPath + "/" + filename
+ for _, filepath := range filePaths {
- if _, err := os.Stat(path); os.IsNotExist(err) {
- return "", nil, pkgerrors.New("File " + path + "does not exists")
+ if _, err := os.Stat(filepath); os.IsNotExist(err) {
+ return "", nil, pkgerrors.New("File " + filepath + "does not exists")
}
- log.Println("Processing file: " + path)
+ log.Println("Processing file: " + filepath)
+ //Populate the namespace from profile instead of instance body
genericKubeData := &utils.ResourceData{
- YamlFilePath: path,
- Namespace: namespace,
+ YamlFilePath: filepath,
+ Namespace: rbProfile.Namespace,
VnfId: internalVNFID,
}