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>
// 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]
}
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()
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())
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)
}
// 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]
}
// 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]
}
// 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]
}
// 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]
}
// 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]
}
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",
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
- os.Exit(1)
}
}
-
-func init() {
-}
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
}
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
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
}
args: []string{"start"},
})
- log.Printf("baremetalAutomatedDeployment: runContainers: starting bastion containers...\n")
+ log.Println("baremetalAutomatedDeployment: runContainers: starting bastion containers...")
err := bad.runScripts(automationRepoPath, scripts)
return err
}
- log.Printf("baremetalAutomatedDeployment: runContainers: bastion containers successfully started\n")
+ log.Println("baremetalAutomatedDeployment: runContainers: bastion containers successfully started")
return nil
}
})
}
- log.Printf("baremetalAutomatedDeployment: runConfigGenerationScripts: generating configuration...\n")
+ log.Println("baremetalAutomatedDeployment: runConfigGenerationScripts: generating configuration...")
err := bad.runScripts(automationRepoPath, scripts)
return err
}
- log.Printf("baremetalAutomatedDeployment: runConfigGenerationScripts: configuration successfully generated\n")
+ log.Println("baremetalAutomatedDeployment: runConfigGenerationScripts: configuration successfully generated")
return nil
}
return err
}
- log.Printf("baremetalAutomatedDeployment: DeployWorkers: worker(s) deploy initiated...\n")
+ log.Println("baremetalAutomatedDeployment: DeployWorkers: worker(s) deploy initiated...")
return nil
}
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
}
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))
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
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
}
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)
// 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)
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
}
}
} 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
})
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
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
// 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
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
// 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
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()
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)
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)
}
}
// 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])
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 "", "", ""
// 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
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)
}
}
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()
}
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
}
}
if err != nil {
log.Fatal(err)
- os.Exit(1)
}
// remove profile folder
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{})
// 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)
}
}
}
}
- 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)
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)
}
}
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)
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
// 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)
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
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
// 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
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)
}
}
}
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")
}
}
// 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)
_, 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)
}
}
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)
}
}
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)
}
}
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)
}
}
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))
// 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)
}
}
ex, err := os.Executable()
if err != nil {
log.Fatal("Error retrieving the current running path")
- os.Exit(1)
}
exPath := filepath.Dir(ex)
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
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()