Clean logging and fatal calls 87/3787/1
authorjcope <jcope@redhat.com>
Wed, 7 Oct 2020 20:58:39 +0000 (15:58 -0500)
committerjcope <jcope@redhat.com>
Thu, 8 Oct 2020 14:47:14 +0000 (09:47 -0500)
log.Fatal() calls os.Exit(1), making the explicit os.Exit() calls in source unreachable
condense string formatting and loging calls to single log.*f(...)

Change-Id: Ied2fadcfd878e7cf4021b2f183af1edca083e165
Signed-off-by: jcope <jcope@redhat.com>
13 files changed:
cmd/apply_workloads.go
cmd/binary.go
cmd/deploy_masters.go
cmd/deploy_workers.go
cmd/destroy_cluster.go
cmd/fetch_requirements.go
cmd/prepare_manifests.go
cmd/root.go
pkg/automation/baremetal.go
pkg/manifests/manifests.go
pkg/requirements/requirements.go
pkg/site/site.go
pkg/utils/utils.go

index f392134..52f35da 100644 (file)
@@ -39,8 +39,7 @@ var applyWorkloadsCmd = &cobra.Command{
                // retrieve config values and start fetching
                var siteName string
                if len(args) == 0 {
-                       log.Fatal("Please specify site name as first argument")
-                       os.Exit(1)
+                       log.Fatalln("Please specify site name as first argument")
                } else {
                        siteName = args[0]
                }
index 9d00f09..bdb6b1a 100644 (file)
@@ -42,11 +42,10 @@ func BuildBinary(binPath string, installerRepo string, installerTag string) {
        err := client.Get()
 
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error downloading installer repo: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error downloading installer repo: %s\n", err)
        }
 
-       log.Println(fmt.Sprintf("Building installer on %s", installerPath))
+       log.Printf("Building installer on %s\n", installerPath)
        cmd := exec.Command("hack/build.sh")
        cmd.Dir = installerPath
        cmd.Env = os.Environ()
@@ -60,8 +59,7 @@ func BuildBinary(binPath string, installerRepo string, installerTag string) {
 
        err = cmd.Run()
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error building binary: %s - %s", err, stdBuffer.String()))
-               os.Exit(1)
+               log.Fatalf("Error building binary: %s - %s\n", err, stdBuffer.String())
        }
        log.Println(stdBuffer.String())
 
@@ -69,10 +67,9 @@ func BuildBinary(binPath string, installerRepo string, installerTag string) {
        cmd = exec.Command("cp", fmt.Sprintf("%s/bin/openshift-install", installerPath), binPath)
        err = cmd.Run()
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error copying installer to buid path: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error copying installer to buid path: %s\n", err)
        }
-       log.Println(fmt.Sprintf("Installer is available on %s/openshift-install", binPath))
+       log.Printf("Installer is available on %s/openshift-install\n", binPath)
 
 }
 
index 7194978..386bfbf 100644 (file)
@@ -33,8 +33,7 @@ var deployMastersCmd = &cobra.Command{
                // retrieve config values and start fetching
                var siteName string
                if len(args) == 0 {
-                       log.Fatal("Please specify site name as first argument")
-                       os.Exit(1)
+                       log.Fatalln("Please specify site name as first argument")
                } else {
                        siteName = args[0]
                }
index c547303..e8dac94 100644 (file)
@@ -33,8 +33,7 @@ var deployWorkersCmd = &cobra.Command{
                // retrieve config values and start fetching
                var siteName string
                if len(args) == 0 {
-                       log.Fatal("Please specify site name as first argument")
-                       os.Exit(1)
+                       log.Fatalln("Please specify site name as first argument")
                } else {
                        siteName = args[0]
                }
index 747372f..b0f8332 100644 (file)
@@ -33,8 +33,7 @@ var destroyClusterCmd = &cobra.Command{
                // retrieve config values and start fetching
                var siteName string
                if len(args) == 0 {
-                       log.Fatal("Please specify site name as first argument")
-                       os.Exit(1)
+                       log.Fatalln("Please specify site name as first argument")
                } else {
                        siteName = args[0]
                }
index a8a877a..76f43c4 100644 (file)
@@ -34,8 +34,7 @@ var fetchRequirementsCmd = &cobra.Command{
                // we need to have at least site as first argument
                var siteRepo string
                if len(args) == 0 {
-                       log.Fatal("Please specify site repository as first argument")
-                       os.Exit(1)
+                       log.Fatalln("Please specify site repository as first argument")
                } else {
                        siteRepo = args[0]
                }
index 2aed5fc..f850ef7 100644 (file)
@@ -33,8 +33,7 @@ var prepareManifestsCmd = &cobra.Command{
                // retrieve config values and start fetching
                var siteName string
                if len(args) == 0 {
-                       log.Fatal("Please specify site name as first argument")
-                       os.Exit(1)
+                       log.Fatalln("Please specify site name as first argument")
                } else {
                        siteName = args[0]
                }
index b5a9f08..42b1db8 100644 (file)
@@ -16,13 +16,9 @@ package cmd
 
 import (
        "fmt"
-       "os"
-
        "github.com/spf13/cobra"
 )
 
-var cfgFile string
-
 // rootCmd represents the base command when called without any subcommands
 var rootCmd = &cobra.Command{
        Use:   "knictl",
@@ -36,9 +32,5 @@ var rootCmd = &cobra.Command{
 func Execute() {
        if err := rootCmd.Execute(); err != nil {
                fmt.Println(err)
-               os.Exit(1)
        }
 }
-
-func init() {
-}
index 8a87373..a52ec81 100644 (file)
@@ -268,7 +268,7 @@ func (bad baremetalAutomatedDeployment) FinalizeAutomationPreparation() error {
                if err != nil {
                        // Requirement was missing, so warn the user (in this case, automation will use
                        // the OCP binaries pulled by the call to prep_bm_host.sh below)
-                       log.Printf("WARNING: '%s' requirement not specified; automation will use the default selected version for OpenShift binaries!", requirement)
+                       log.Printf("WARNING: '%s' requirement not specified; automation will use the default selected version for OpenShift binaries!\n", requirement)
                        prepHostSkipOcpBinariesArg = ""
                        break
                }
@@ -276,7 +276,7 @@ func (bad baremetalAutomatedDeployment) FinalizeAutomationPreparation() error {
                utils.ExecuteCommand("", nil, true, false, "cp", requirementFullPath, requirementsDestination)
        }
 
-       log.Printf("baremetalAutomatedDeployment: FinalizeAutomationPreparation: finished injecting OpenShift binaries for automation repo\n")
+       log.Println("baremetalAutomatedDeployment: FinalizeAutomationPreparation: finished injecting OpenShift binaries for automation repo")
 
        // Execute automation's prep_bm_host script now that all manifests have been
        // copied to the baremetal automation repo's cluster manifests directory
@@ -359,7 +359,7 @@ func (bad baremetalAutomatedDeployment) DeployMasters() error {
                return err
        }
 
-       log.Printf("baremetalAutomatedDeployment: DeployMasters: bootstrap and master(s) deploy initiated...\n")
+       log.Println("baremetalAutomatedDeployment: DeployMasters: bootstrap and master(s) deploy initiated...")
 
        return nil
 }
@@ -406,7 +406,7 @@ func (bad baremetalAutomatedDeployment) runContainers(automationRepoPath string)
                args:        []string{"start"},
        })
 
-       log.Printf("baremetalAutomatedDeployment: runContainers: starting bastion containers...\n")
+       log.Println("baremetalAutomatedDeployment: runContainers: starting bastion containers...")
 
        err := bad.runScripts(automationRepoPath, scripts)
 
@@ -414,7 +414,7 @@ func (bad baremetalAutomatedDeployment) runContainers(automationRepoPath string)
                return err
        }
 
-       log.Printf("baremetalAutomatedDeployment: runContainers: bastion containers successfully started\n")
+       log.Println("baremetalAutomatedDeployment: runContainers: bastion containers successfully started")
 
        return nil
 }
@@ -485,7 +485,7 @@ func (bad baremetalAutomatedDeployment) runConfigGenerationScripts(automationRep
                })
        }
 
-       log.Printf("baremetalAutomatedDeployment: runConfigGenerationScripts: generating configuration...\n")
+       log.Println("baremetalAutomatedDeployment: runConfigGenerationScripts: generating configuration...")
 
        err := bad.runScripts(automationRepoPath, scripts)
 
@@ -493,7 +493,7 @@ func (bad baremetalAutomatedDeployment) runConfigGenerationScripts(automationRep
                return err
        }
 
-       log.Printf("baremetalAutomatedDeployment: runConfigGenerationScripts: configuration successfully generated\n")
+       log.Println("baremetalAutomatedDeployment: runConfigGenerationScripts: configuration successfully generated")
 
        return nil
 }
@@ -539,7 +539,7 @@ func (bad baremetalAutomatedDeployment) DeployWorkers() error {
                return err
        }
 
-       log.Printf("baremetalAutomatedDeployment: DeployWorkers: worker(s) deploy initiated...\n")
+       log.Println("baremetalAutomatedDeployment: DeployWorkers: worker(s) deploy initiated...")
 
        return nil
 }
@@ -622,7 +622,7 @@ func (bad baremetalAutomatedDeployment) DestroyCluster() error {
                os.RemoveAll(fmt.Sprintf("%s/%s", automationRepoPath, dir))
        }
 
-       log.Printf("baremetalAutomatedDeployment: DestroyCluster: cluster teardown completed\n")
+       log.Println("baremetalAutomatedDeployment: DestroyCluster: cluster teardown completed")
 
        return nil
 }
@@ -630,7 +630,7 @@ func (bad baremetalAutomatedDeployment) DestroyCluster() error {
 func (bad baremetalAutomatedDeployment) runTerraform(automationRepoPath string, targetType string, operation terraformOperation) error {
        terraformPath := fmt.Sprintf("%s/terraform/%s", automationRepoPath, targetType)
 
-       log.Printf("baremetalAutomatedDeployment: runTerraform: initializing terraform...\n")
+       log.Println("baremetalAutomatedDeployment: runTerraform: initializing terraform...")
 
        // Init
        cmd := exec.Command("terraform", string(terraformInit))
@@ -644,7 +644,7 @@ func (bad baremetalAutomatedDeployment) runTerraform(automationRepoPath string,
                return fmt.Errorf("baremetalAutomatedDeployment: runTerraform: error running baremetal automation %s terraform init: %s", targetType, err)
        }
 
-       log.Printf("baremetalAutomatedDeployment: runTerraform: terraform successfully initialized\n")
+       log.Println("baremetalAutomatedDeployment: runTerraform: terraform successfully initialized")
        log.Printf("baremetalAutomatedDeployment: runTerraform: running terraform %s...\n", operation)
 
        // Apply
@@ -659,7 +659,7 @@ func (bad baremetalAutomatedDeployment) runTerraform(automationRepoPath string,
                return fmt.Errorf("baremetalAutomatedDeployment: runTerraform: error running baremetal automation %s terraform %s: %s", targetType, operation, err)
        }
 
-       log.Printf("baremetalAutomatedDeployment: runTerraform: terraform successfully applied\n")
+       log.Println("baremetalAutomatedDeployment: runTerraform: terraform successfully applied")
 
        return nil
 }
index 9b5cce5..e0471eb 100644 (file)
@@ -89,8 +89,7 @@ func MergeManifests(content string, siteBuildPath string) string {
 
                err := yaml.Unmarshal([]byte(manifest), &manifestObj)
                if err != nil {
-                       log.Println(fmt.Sprintf("Error parsing manifest: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error parsing manifest: %s\n", err)
                }
                // add to the list of manifests with the generated key
                GVKN := GetGKVN(manifestObj)
@@ -113,14 +112,12 @@ func MergeManifests(content string, siteBuildPath string) string {
                                // read file content and unmarshal it
                                manifestContent, err := ioutil.ReadFile(path)
                                if err != nil {
-                                       log.Println(fmt.Sprintf("Error reading manifest content: %s", err))
-                                       os.Exit(1)
+                                       log.Fatalf("Error reading manifest content: %s\n", err)
                                }
                                var manifestContentObj map[interface{}]interface{}
                                err = yaml.Unmarshal(manifestContent, &manifestContentObj)
                                if err != nil {
-                                       log.Println(fmt.Sprintf("Error parsing manifest: %s", err))
-                                       os.Exit(1)
+                                       log.Fatalf("Error parsing manifest: %s\n", err)
                                }
 
                                GVKN := GetGKVN(manifestContentObj)
@@ -149,24 +146,21 @@ func MergeManifests(content string, siteBuildPath string) string {
 
                                                        kustomizedString, err := yaml.Marshal(kustomizedContentObj)
                                                        if err != nil {
-                                                               log.Fatal(fmt.Sprintf("Error marshaling kustomized content: %s", err))
-                                                               os.Exit(1)
+                                                               log.Fatalf("Error marshaling kustomized content: %s\n", err)
                                                        }
 
                                                        if len(walkedManifests) == 1 {
                                                                // just rewrite with the original name
                                                                err = ioutil.WriteFile(path, kustomizedString, 0644)
                                                                if err != nil {
-                                                                       log.Fatal(fmt.Sprintf("Error writing new manifest content: %s", err))
-                                                                       os.Exit(1)
+                                                                       log.Fatalf("Error writing new manifest content: %s\n", err)
                                                                }
                                                        } else {
                                                                // rewrite with a prefix
                                                                newPath := fmt.Sprintf("%02d_%s", counter, path)
                                                                err = ioutil.WriteFile(newPath, kustomizedString, 0644)
                                                                if err != nil {
-                                                                       log.Fatal(fmt.Sprintf("Error writing new manifest content: %s", err))
-                                                                       os.Exit(1)
+                                                                       log.Fatalf("Error writing new manifest content: %s", err)
                                                                }
                                                                counter = counter + 1
                                                        }
@@ -176,8 +170,7 @@ func MergeManifests(content string, siteBuildPath string) string {
 
                        }
                } else {
-                       log.Println(fmt.Sprintf("Error walking on manifests directory: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error walking on manifests directory: %s\n", err)
                }
                return nil
        })
@@ -189,20 +182,18 @@ func MergeManifests(content string, siteBuildPath string) string {
                if !ok {
                        // the manifest is not there, add it
                        manifestName := fmt.Sprintf("99_%04d_%s.yaml", counter, NameFromGVKN(k))
-                       log.Println(fmt.Sprintf("Blueprint added manifests %s, writing to %s", k, manifestName))
+                       log.Printf("Blueprint added manifests %s, writing to %s\n", k, manifestName)
 
                        newPath := fmt.Sprintf("%s/blueprint/base/00_cluster/manifests/%s", siteBuildPath, manifestName)
 
                        // marshal the file to write
                        kustomizedString, err := yaml.Marshal(v)
                        if err != nil {
-                               log.Fatal(fmt.Sprintf("Error marshing manifest: %s", err))
-                               os.Exit(1)
+                               log.Fatalf("Error marshing manifest: %s\n", err)
                        }
                        err = ioutil.WriteFile(newPath, kustomizedString, 0644)
                        if err != nil {
-                               log.Fatal(fmt.Sprintf("Error writing manifest: %s", err))
-                               os.Exit(1)
+                               log.Fatalf("Error writing manifest: %s\n", err)
                        }
                        counter = counter + 1
 
@@ -213,8 +204,7 @@ func MergeManifests(content string, siteBuildPath string) string {
        os.RemoveAll(fmt.Sprintf("%s/final_manifests", siteBuildPath))
        err := os.Rename(fmt.Sprintf("%s/blueprint/base/00_cluster", siteBuildPath), fmt.Sprintf("%s/final_manifests", siteBuildPath))
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error moving to final manifests folder: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error moving to final manifests folder: %s\n", err)
        } else {
                var builder strings.Builder
 
index f9c6ada..bfca816 100644 (file)
@@ -28,14 +28,13 @@ func New(binaryName string, sourceRepo string, buildPath string) Requirement {
 // download requirement from a tarball or folder
 func (r Requirement) FetchRequirementFolder() {
        // extract the tarball if exists
-       log.Println(fmt.Sprintf("Pulling %s tarball from %s", r.binaryName, r.sourceRepo))
+       log.Printf("Pulling %s tarball from %s\n", r.binaryName, r.sourceRepo)
 
        extractDir := fmt.Sprintf("%s/%s_content", r.buildPath, r.binaryName)
        client := &getter.Client{Src: r.sourceRepo, Dst: extractDir, Mode: getter.ClientModeAny}
        err := client.Get()
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error cloning tarball repository: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error cloning tarball repository: %s\n", err)
        }
 
        // find the binary inside the extracted content
@@ -59,8 +58,7 @@ func (r Requirement) BuildOpenshiftBinary() {
        client := &getter.Client{Src: r.sourceRepo, Dst: extractDir, Mode: getter.ClientModeAny}
        err := client.Get()
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error cloning tarball repository: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error cloning tarball repository: %s\n", err)
        }
 
        // build the openshift binary
@@ -70,7 +68,7 @@ func (r Requirement) BuildOpenshiftBinary() {
        // copy the generated binary to the build directory
        var cpEnvVars []string
        utils.ExecuteCommand("", cpEnvVars, true, true, "cp", fmt.Sprintf("%s/bin/openshift-install", extractDir), r.buildPath)
-       log.Println(fmt.Sprintf("Installer is available on %s/openshift-install", r.buildPath))
+       log.Printf("Installer is available on %s/openshift-install\n", r.buildPath)
 }
 
 // download a requirement from a git repo and build it
@@ -78,19 +76,18 @@ func (r Requirement) FetchRequirementGit() {
        if r.binaryName == "openshift-install" {
                r.BuildOpenshiftBinary()
        } else {
-               log.Fatal(fmt.Sprintf("Build of binary %s is not supported", r.binaryName))
-               os.Exit(1)
+               log.Fatalf("Build of binary %s is not supported\n", r.binaryName)
        }
 }
 
 // downloads an individual requirement
 func (r Requirement) FetchRequirement() {
-       log.Println(fmt.Sprintf("Downloading %s requirement from %s", r.binaryName, r.sourceRepo))
+       log.Printf("Downloading %s requirement from %s\n", r.binaryName, r.sourceRepo)
 
        // first check if the binary already exists
        binaryPath := fmt.Sprintf("%s/%s", r.buildPath, r.binaryName)
        if _, err := os.Stat(binaryPath); err == nil {
-               log.Println(fmt.Sprintf("Using existing %s", binaryPath))
+               log.Printf("Using existing %s\n", binaryPath)
        } else if os.IsNotExist(err) {
                if strings.Contains(r.sourceRepo, ".git") {
                        r.FetchRequirementGit()
index 3a55762..eb461cd 100644 (file)
@@ -53,7 +53,7 @@ func NewWithName(siteName string, buildPath string) Site {
 func (s Site) DownloadSite() {
        if s.siteRepo != "" {
                // Clone the site repository
-               log.Println(fmt.Sprintf("Cloning the site repository from %s", s.siteRepo))
+               log.Printf("Cloning the site repository from %s\n", s.siteRepo)
                siteLayerPath := fmt.Sprintf("%s/%s/site", s.buildPath, s.siteName)
                os.RemoveAll(siteLayerPath)
 
@@ -67,12 +67,11 @@ func (s Site) DownloadSite() {
                        client := &getter.Client{Src: s.siteRepo, Dst: siteLayerPath, Mode: getter.ClientModeAny}
                        err := client.Get()
                        if err != nil {
-                               log.Fatal(fmt.Sprintf("Error cloning site repository: %s", err))
+                               log.Fatalf("Error cloning site repository: %s\n", err)
                        }
                }
        } else {
-               log.Fatal(fmt.Sprintf("Site repository does not exist for the site %s", s.siteName))
-               os.Exit(1)
+               log.Fatalf("Site repository does not exist for the site %s\n", s.siteName)
        }
 
 }
@@ -87,15 +86,13 @@ func (s Site) GetProfileFromSite() (string, string, string) {
                // parse yaml and extract base
                yamlContent, err := ioutil.ReadFile(profileFile)
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error reading profile file: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error reading profile file: %s\n", err)
                }
 
                profileSettings := &map[string][]interface{}{}
                err = yaml.Unmarshal(yamlContent, &profileSettings)
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error parsing profile yaml file: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error parsing profile yaml file: %s\n", err)
                }
                bases := (*profileSettings)["bases"]
                profileRepo := fmt.Sprintf("%s", bases[0])
@@ -120,8 +117,7 @@ func (s Site) GetProfileFromSite() (string, string, string) {
 
                return profileName, profileLayerPath, profileRef
        } else if os.IsNotExist(err) {
-               log.Fatal(fmt.Sprintf("File %s does not exist, exiting", profileFile))
-               os.Exit(1)
+               log.Fatalf("File %s does not exist, exiting\n", profileFile)
        }
 
        return "", "", ""
@@ -130,14 +126,14 @@ func (s Site) GetProfileFromSite() (string, string, string) {
 // using the downloaded site content, fetches (and builds) the specified requirements,
 // and also prepares the host for running scripts for the site's profile type
 func (s Site) FetchRequirements(individualRequirements []string) {
-       log.Println(fmt.Sprintf("Downloading requirements for %s", s.siteName))
+       log.Printf("Downloading requirements for %s\n", s.siteName)
        sitePath := fmt.Sprintf("%s/%s", s.buildPath, s.siteName)
 
        // searches for file containing the profile of the blueprint
        profileName, profileLayerPath, _ := s.GetProfileFromSite()
 
        profileBuildPath := fmt.Sprintf("%s/%s", sitePath, profileName)
-       log.Println(fmt.Sprintf("Downloading profile repo from %s into %s", profileLayerPath, profileBuildPath))
+       log.Printf("Downloading profile repo from %s into %s\n", profileLayerPath, profileBuildPath)
        if strings.HasPrefix(profileLayerPath, "file://") {
                // just do a local copy
                var envVars []string
@@ -148,7 +144,7 @@ func (s Site) FetchRequirements(individualRequirements []string) {
                client := &getter.Client{Src: profileLayerPath, Dst: profileBuildPath, Mode: getter.ClientModeAny}
                err := client.Get()
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error cloning profile repository: %s", err))
+                       log.Fatalf("Error cloning profile repository: %s\n", err)
                }
        }
 
@@ -156,8 +152,7 @@ func (s Site) FetchRequirements(individualRequirements []string) {
        requirementsFile := fmt.Sprintf("%s/requirements.yaml", profileBuildPath)
        file, err := os.Open(requirementsFile)
        if err != nil {
-               log.Fatal("Error reading requirements file")
-               os.Exit(1)
+               log.Fatalln("Error reading requirements file")
        }
        defer file.Close()
 
@@ -189,7 +184,7 @@ func (s Site) FetchRequirements(individualRequirements []string) {
                        }
                        if !foundReq {
                                // skip this iteration
-                               log.Println(fmt.Sprintf("Binary %s not found in list, skipping", binaryName))
+                               log.Printf("Binary %s not found in list, skipping\n", binaryName)
                                continue
                        }
                }
@@ -202,7 +197,6 @@ func (s Site) FetchRequirements(individualRequirements []string) {
 
        if err != nil {
                log.Fatal(err)
-               os.Exit(1)
        }
 
        // remove profile folder
@@ -221,15 +215,13 @@ func (s Site) WriteEnvFile() {
        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)
+               log.Fatalf("Error reading site config file: %s\n", err)
        }
 
        // 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)
+               log.Printf("Error parsing manifest: %s\n", err)
        }
 
        envVars, ok := configFileObj["config"].(map[interface{}]interface{})
@@ -242,8 +234,7 @@ func (s Site) WriteEnvFile() {
        // 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)
+               log.Fatalf("Error writing profile.env file: %s\n", err)
        }
 }
 
@@ -279,7 +270,7 @@ func (s Site) DownloadRepo(sitePath string, profileLayerPath string, profileRef
                }
        }
 
-       log.Println(fmt.Sprintf("Downloading blueprint repo from %s", downloadRepo))
+       log.Printf("Downloading blueprint repo from %s\n", downloadRepo)
        blueprintDir := fmt.Sprintf("%s/blueprint", sitePath)
        os.RemoveAll(blueprintDir)
 
@@ -293,7 +284,7 @@ func (s Site) DownloadRepo(sitePath string, profileLayerPath string, profileRef
                client := &getter.Client{Src: downloadRepo, Dst: blueprintDir, Mode: getter.ClientModeAny}
                err := client.Get()
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error cloning profile repository: %s", err))
+                       log.Fatalf("Error cloning profile repository: %s\n", err)
                }
        }
 
@@ -306,8 +297,7 @@ func (s Site) DownloadRepo(sitePath string, profileLayerPath string, profileRef
                        if info.Name() == "kustomization.yaml" {
                                readKustomization, err := ioutil.ReadFile(path)
                                if err != nil {
-                                       log.Fatal(fmt.Sprintf("Error opening kustomization file: %s", err))
-                                       os.Exit(1)
+                                       log.Fatalf("Error opening kustomization file: %s\n", err)
                                }
 
                                newKustomization := strings.Replace(string(readKustomization), absoluteBlueprintRepo, "../../../", -1)
@@ -317,15 +307,13 @@ func (s Site) DownloadRepo(sitePath string, profileLayerPath string, profileRef
 
                                err = ioutil.WriteFile(path, []byte(newKustomization), 0)
                                if err != nil {
-                                       log.Fatal(fmt.Sprintf("Error writing modified kustomization file: %s", err))
-                                       os.Exit(1)
+                                       log.Fatalf("Error writing modified kustomization file: %s\n", err)
                                }
                                return nil
                        }
 
                } else {
-                       log.Println(fmt.Sprintf("Error walking on site directory: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error walking on site directory: %s\n", err)
                }
 
                return nil
@@ -336,7 +324,7 @@ func (s Site) DownloadRepo(sitePath string, profileLayerPath string, profileRef
 // host preparation finalization scripts for site automation (if any)
 func (s Site) PrepareManifests() {
        sitePath := fmt.Sprintf("%s/%s", s.buildPath, s.siteName)
-       log.Println(fmt.Sprintf("Preparing manifests for %s", s.siteName))
+       log.Printf("Preparing manifests for %s\n", s.siteName)
 
        // do the initial validation of pre-requisites
        utils.ValidateRequirements(s.buildPath, s.siteName)
@@ -356,8 +344,7 @@ func (s Site) PrepareManifests() {
        err := copy.Copy(installConfigDirPath, automationPath)
 
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error copying 00_install-config directory: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error copying 00_install-config directory: %s\n", err)
        }
 
        // generate openshift-install manifests based on phase 00_install-config
@@ -370,20 +357,17 @@ func (s Site) PrepareManifests() {
        if len(out) > 0 {
                err := ioutil.WriteFile(fmt.Sprintf("%s/install-config.yaml", assetsPath), out, 0644)
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error writing final install-config file: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error writing final install-config file: %s\n", err)
                }
 
                // create a copy of final install-config.yaml in any site automation sub-directories
                // in case automation is later needed
                err = ioutil.WriteFile(fmt.Sprintf("%s/install-config.yaml", automationPath), out, 0644)
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error writing final install-config file to automation assets directory: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error writing final install-config file to automation assets directory: %s\n", err)
                }
        } else {
-               log.Fatal("Error, kustomize did not return any content")
-               os.Exit(1)
+               log.Fatalln("Error, kustomize did not return any content")
        }
 
        // now generate the manifests
@@ -392,23 +376,20 @@ func (s Site) PrepareManifests() {
        // iterate over all the generated files and create a kustomization file
        f, err := os.Create(fmt.Sprintf("%s/kustomization.yaml", assetsPath))
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error creating kustomization file: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error creating kustomization file: %s\n", err)
        }
        defer f.Close()
 
        _, err = f.WriteString("resources:\n")
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error writing kustomization file: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error writing kustomization file: %s\n", err)
        }
 
        filePatterns := []string{fmt.Sprintf("%s/manifests/*.yaml", assetsPath), fmt.Sprintf("%s/manifests/*.yml", assetsPath), fmt.Sprintf("%s/openshift/*.yaml", assetsPath)}
        for _, filePattern := range filePatterns {
                files, err := filepath.Glob(filePattern)
                if err != nil {
-                       log.Fatal(fmt.Sprintf("Error reading manifest files: %s", err))
-                       os.Exit(1)
+                       log.Fatalf("Error reading manifest files: %s\n", err)
                }
 
                // iterate over each file, remove the absolute path and write it
@@ -416,8 +397,7 @@ func (s Site) PrepareManifests() {
                        strippedName := strings.TrimPrefix(fileName, fmt.Sprintf("%s/", assetsPath))
                        _, err := f.WriteString(fmt.Sprintf("- %s\n", strippedName))
                        if err != nil {
-                               log.Fatal(fmt.Sprintf("Error writing kustomization file: %s", err))
-                               os.Exit(1)
+                               log.Fatalf("Error writing kustomization file: %s\n", err)
                        }
                }
        }
@@ -435,15 +415,13 @@ func (s Site) PrepareManifests() {
                err = s.finalizeHostForAutomation(profileName)
 
                if err != nil {
-                       log.Fatal(err)
-                       os.Exit(1)
+                       log.Fatalln(err)
                }
 
                // Finally, print manifest merge output
                fmt.Println(resultStr)
        } else {
-               log.Fatal("Error, kustomize did not return any content")
-               os.Exit(1)
+               log.Fatalln("Error, kustomize did not return any content")
        }
 
 }
@@ -455,8 +433,7 @@ func (s Site) ApplyWorkloads(kubeconfigFile string, retryCount int, delay int) {
        // if we have kubeconfig, validate that exists
        if len(kubeconfigFile) > 0 {
                if _, err := os.Stat(kubeconfigFile); err != nil {
-                       log.Fatal(fmt.Sprintf("Error: kubeconfig file %s does not exist", kubeconfigFile))
-                       os.Exit(1)
+                       log.Fatalln("Error: kubeconfig file %s does not exist\n", kubeconfigFile)
                }
        }
        binariesPath := fmt.Sprintf("%s/requirements", siteBuildPath)
@@ -465,21 +442,21 @@ func (s Site) ApplyWorkloads(kubeconfigFile string, retryCount int, delay int) {
        _, profileLayerPath, profileRef := s.GetProfileFromSite()
        s.DownloadRepo(siteBuildPath, profileLayerPath, profileRef)
 
-       log.Println(fmt.Sprintf("Applying workloads from %s/blueprint/sites/site/02_cluster-addons", siteBuildPath))
+       log.Printf("Applying workloads from %s/blueprint/sites/site/02_cluster-addons\n", siteBuildPath)
        out := utils.ApplyKustomize(fmt.Sprintf("%s/kustomize", binariesPath), fmt.Sprintf("%s/blueprint/sites/site/02_cluster-addons", siteBuildPath))
        if string(out) != "" {
                // now we can apply it
                utils.ApplyOc(fmt.Sprintf("%s/oc", binariesPath), out, kubeconfigFile, retryCount, delay)
        } else {
-               log.Println(fmt.Sprintf("No manifests found for %s/blueprint/sites/site/02_cluster-addons", siteBuildPath))
+               log.Printf("No manifests found for %s/blueprint/sites/site/02_cluster-addons\n", siteBuildPath)
        }
-       log.Println(fmt.Sprintf("Applying workloads from %s/blueprint/sites/site/03_services", siteBuildPath))
+       log.Printf("Applying workloads from %s/blueprint/sites/site/03_services\n", siteBuildPath)
        out = utils.ApplyKustomize(fmt.Sprintf("%s/kustomize", binariesPath), fmt.Sprintf("%s/blueprint/sites/site/03_services", siteBuildPath))
        if string(out) != "" {
                // now we can apply it
                utils.ApplyOc(fmt.Sprintf("%s/oc", binariesPath), out, kubeconfigFile, retryCount, delay)
        } else {
-               log.Println(fmt.Sprintf("No manifests found for %s/blueprint/sites/site/03_services", siteBuildPath))
+               log.Printf("No manifests found for %s/blueprint/sites/site/03_services\n", siteBuildPath)
        }
 }
 
@@ -488,8 +465,7 @@ func (s Site) AutomateMastersDeployment() {
        err := s.automateDeployment("masters")
 
        if err != nil {
-               log.Fatal(fmt.Sprintf("Site: AutomateMastersDeployment: Error attempting to run automated deployment: %s", err))
-               os.Exit(1)
+               log.Fatalf("Site: AutomateMastersDeployment: Error attempting to run automated deployment: %s\n", err)
        }
 }
 
@@ -498,8 +474,7 @@ func (s Site) AutomateWorkersDeployment() {
        err := s.automateDeployment("workers")
 
        if err != nil {
-               log.Fatal(fmt.Sprintf("Site: AutomateWorkersDeployment: Error attempting to run automated deployment: %s", err))
-               os.Exit(1)
+               log.Fatalf("Site: AutomateWorkersDeployment: Error attempting to run automated deployment: %s\n", err)
        }
 }
 
@@ -508,16 +483,14 @@ func (s Site) AutomateClusterDestroy() {
        automatedDeployment, err := s.getAutomatedDeployment()
 
        if err != nil {
-               log.Fatal(fmt.Sprintf("Site: AutomateClusterDestroy: Error attempting to acquire automated deploy object: %s", err))
-               os.Exit(1)
+               log.Fatalf("Site: AutomateClusterDestroy: Error attempting to acquire automated deploy object: %s\n", err)
        }
 
        // Run the automated cluster teardown
        err = automatedDeployment.DestroyCluster()
 
        if err != nil {
-               log.Fatal(fmt.Sprintf("Site: AutomateClusterDestroy: Error attempting to run automated cluster destroy: %s", err))
-               os.Exit(1)
+               log.Fatalf("Site: AutomateClusterDestroy: Error attempting to run automated cluster destroy: %s\n", err)
        }
 }
 
index 9e204df..cdf85ed 100644 (file)
@@ -16,13 +16,12 @@ import (
 func ValidateRequirements(buildPath string, siteName string) {
        // check for pull-secret.json
        if _, err := os.Stat(fmt.Sprintf("%s/pull-secret.json", buildPath)); os.IsNotExist(err) {
-               log.Fatal(fmt.Sprintf("Error, no valid pull-secret.json found in %s", buildPath))
-               os.Exit(1)
+               log.Fatalf("Error, no valid pull-secret.json found in %s\n", buildPath)
        }
 
        // check for ssh key , and generate if it does not exist
        if _, err := os.Stat(fmt.Sprintf("%s/id_rsa.pub", buildPath)); os.IsNotExist(err) {
-               log.Println(fmt.Sprintf("No SSH public key (id_rsa.pub) found in %s. Generating keypair.", buildPath))
+               log.Printf("No SSH public key (id_rsa.pub) found in %s. Generating keypair.\n", buildPath)
 
                var envVars []string
                ExecuteCommand("", envVars, true, true, "/bin/bash", "-c", fmt.Sprintf("ssh-keygen -b 2048 -q -N '' -f %s/id_rsa -C user@example.com", buildPath))
@@ -31,8 +30,7 @@ func ValidateRequirements(buildPath string, siteName string) {
        // check if requirements folder exist
        requirementsFolder := fmt.Sprintf("%s/%s/requirements", buildPath, siteName)
        if _, err := os.Stat(requirementsFolder); os.IsNotExist(err) {
-               log.Fatal(fmt.Sprintf("Error, requirements folder not found in %s", requirementsFolder))
-               os.Exit(1)
+               log.Fatalf("Error, requirements folder not found in %s\n", requirementsFolder)
        }
 
 }
@@ -43,7 +41,6 @@ func ApplyKustomize(kustomizeBinary string, kustomizePath string) []byte {
        ex, err := os.Executable()
        if err != nil {
                log.Fatal("Error retrieving the current running path")
-               os.Exit(1)
        }
        exPath := filepath.Dir(ex)
 
@@ -59,14 +56,12 @@ func ApplyOc(ocBinary string, kubectlContent []byte, kubeconfigPath string, retr
        tmpFile, err := ioutil.TempFile(os.TempDir(), "kubectl-")
        if err != nil {
                log.Fatal(fmt.Sprintf("Cannot create temporary file: %s", err))
-               os.Exit(1)
        }
        defer os.Remove(tmpFile.Name())
 
        _, err = tmpFile.Write(kubectlContent)
        if err != nil {
-               log.Fatal(fmt.Sprintf("Error writing kubectl file: %s", err))
-               os.Exit(1)
+               log.Fatalf("Error writing kubectl file: %s\n", err)
        }
 
        var envVars []string
@@ -112,10 +107,9 @@ func ExecuteCommand(directory string, envVars []string, failFatal bool, showOutp
 
        if err != nil {
                if failFatal {
-                       log.Fatal(fmt.Sprintf("Error applying command %s (%s): %s - %s", name, arg, err, errb.String()))
-                       os.Exit(1)
+                       log.Fatalf("Error applying command %s (%s): %s - %s\n", name, arg, err, errb.String())
                } else {
-                       log.Println(fmt.Sprintf("Error applying command %s (%s): %s - %s", name, arg, err, errb.String()))
+                       log.Printf("Error applying command %s (%s): %s - %s\n", name, arg, err, errb.String())
                }
        }
        return outb.Bytes(), errb.Bytes()