From: Yolanda Robla Date: Tue, 9 Jul 2019 14:17:17 +0000 (+0200) Subject: Create profile.env to source on cluster creation X-Git-Tag: akraino_r2~59 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=da3a3a4744b8239f3d61da951db133cd22cc9f8a;p=kni%2Finstaller.git Create profile.env to source on cluster creation 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 Change-Id: Ie2d90c613757c458a7b56b85cc31921fde96ac0c --- diff --git a/cmd/prepare_manifests.go b/cmd/prepare_manifests.go index edee639..2aed5fc 100644 --- a/cmd/prepare_manifests.go +++ b/cmd/prepare_manifests.go @@ -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() }, } diff --git a/pkg/manifests/manifests.go b/pkg/manifests/manifests.go index 43ab69c..ea8434b 100644 --- a/pkg/manifests/manifests.go +++ b/pkg/manifests/manifests.go @@ -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)) } diff --git a/pkg/site/site.go b/pkg/site/site.go index 66ac819..6b9d428 100644 --- a/pkg/site/site.go +++ b/pkg/site/site.go @@ -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)