Create profile.env to source on cluster creation 47/1147/3
authorYolanda Robla <yroblamo@redhat.com>
Tue, 9 Jul 2019 14:17:17 +0000 (16:17 +0200)
committerYolanda Robla Mota <yroblamo@redhat.com>
Thu, 11 Jul 2019 13:09:56 +0000 (13:09 +0000)
In order to run the cluster with the specific env
vars we are creating a profile.env file with some
fixed values (TF_VAR_libvirt_master_* vars) , and
one env var in case we want to override the release
image.

Signed-off-by: Yolanda Robla <yroblamo@redhat.com>
Change-Id: Ie2d90c613757c458a7b56b85cc31921fde96ac0c

cmd/prepare_manifests.go
pkg/manifests/manifests.go
pkg/site/site.go

index edee639..2aed5fc 100644 (file)
@@ -47,6 +47,7 @@ var prepareManifestsCmd = &cobra.Command{
 
                // define a site object and proceed with requirements fetch
                s := site.NewWithName(siteName, buildPath)
+               s.WriteEnvFile()
                s.PrepareManifests()
        },
 }
index 43ab69c..ea8434b 100644 (file)
@@ -217,6 +217,7 @@ func MergeManifests(content string, siteBuildPath string) {
                os.Exit(1)
        } else {
                log.Println(fmt.Sprintf("*** Manifest generation finished. You can run now: %s/requirements/openshift-install create cluster --dir=%s/final_manifests to create the site cluster ***", siteBuildPath, siteBuildPath))
+               log.Println(fmt.Sprintf("A profile.env file has been generated inside %s/profile.env, you can source it before starting the openshift-install command", siteBuildPath))
                log.Println(fmt.Sprintf("In order to destroy the cluster you can run:  %s/requirements/openshift-install destroy cluster --dir %s/final_manifests", siteBuildPath, siteBuildPath))
        }
 
index 66ac819..6b9d428 100644 (file)
@@ -142,6 +142,44 @@ func (s Site) FetchRequirements() {
 
 }
 
+// writes an env file, that needs to be sourced before running cluster install
+func (s Site) WriteEnvFile() {
+       envContents := ""
+
+       // fist we check if release image override exists on site definition
+       siteBuildPath := fmt.Sprintf("%s/%s", s.buildPath, s.siteName)
+       installYaml := fmt.Sprintf("%s/site/00_install-config/site-config.yaml", siteBuildPath)
+
+       var configFileObj map[interface{}]interface{}
+       b, err := ioutil.ReadFile(installYaml)
+       if err != nil {
+               log.Fatal(fmt.Sprintf("Error reading site config file: %s", err))
+               os.Exit(1)
+       }
+
+       // parse the yaml and check for key value
+       err = yaml.Unmarshal(b, &configFileObj)
+       if err != nil {
+               log.Println(fmt.Sprintf("Error parsing manifest: %s", err))
+               os.Exit(1)
+       }
+
+       releaseImage, ok := configFileObj["config"].(map[interface{}]interface{})["releaseImageOverride"]
+       if ok {
+               // search for the releaseImageOverride key
+               envContents = fmt.Sprintf("%sexport OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE=%s\n", envContents, string(releaseImage.(string)))
+       }
+       envContents = fmt.Sprintf("%sexport TF_VAR_libvirt_master_memory=8192\n", envContents)
+       envContents = fmt.Sprintf("%sexport TF_VAR_libvirt_master_vcpu=4\n", envContents)
+
+       // write a profile.env in the siteBuildPath
+       err = ioutil.WriteFile(fmt.Sprintf("%s/profile.env", siteBuildPath), []byte(envContents), 0644)
+       if err != nil {
+               log.Fatal(fmt.Sprintf("Error writing profile.env file: %s", err))
+               os.Exit(1)
+       }
+}
+
 // using the downloaded site content, prepares the manifests for it
 func (s Site) PrepareManifests() {
        sitePath := fmt.Sprintf("%s/%s", s.buildPath, s.siteName)