Skip to content

Commit

Permalink
chore: converted fmt.Print* to log.Logger() (jenkins-x#4240)
Browse files Browse the repository at this point in the history
Signed-off-by: Gareth Evans <gareth@bryncynfelin.co.uk>
  • Loading branch information
garethjevans authored and jenkins-x-bot committed Jun 12, 2019
1 parent 8d16c58 commit f4eaaee
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 40 deletions.
3 changes: 2 additions & 1 deletion pkg/cloud/iks/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
b64 "encoding/base64"
"encoding/json"
"fmt"
"github.com/jenkins-x/jx/pkg/log"
gohttp "net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -166,7 +167,7 @@ func (a *registry) AddToken(accountID string, description string, permanent bool

response, err := a.Client.Post(fmt.Sprintf("/api/v1/tokens?%s", v.Encode()), nil, &queryResp, m)
if err != nil {
fmt.Println(err)
log.Logger().Errorf("error - %s", err)
if response.StatusCode == 401 {
return "", bmxerror.New(ErrCodeNotAuthorized,
"You are not authorized to view the requested resource, or your IBM Cloud bearer token is invalid. Correct the request and try again.")
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/oke/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package oke
import (
"encoding/json"
"fmt"
"github.com/jenkins-x/jx/pkg/log"
"os/exec"
"sort"
"strings"
Expand All @@ -15,7 +16,7 @@ func GetOptionValues() ([]string, []string, []string, string, error) {
}
var dat map[string]interface{}
if err := json.Unmarshal(jsonString, &dat); err != nil {
fmt.Println("error")
log.Logger().Errorf("error - %s", err)
return nil, nil, nil, "", err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/git_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *GitCollector) CollectFiles(patterns []string, outputPath string, basedi
}
err = gitClient.CommitDir(ghPagesDir, fmt.Sprintf("Publishing files for path %s", outputPath))
if err != nil {
fmt.Println(err)
log.Logger().Errorf("%s", err)
return urls, err
}
err = gitClient.Push(ghPagesDir)
Expand Down
2 changes: 1 addition & 1 deletion pkg/gits/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ func (p *GitHubProvider) ListCommits(owner, repo string, opt *ListCommitsArgumen
}
githubCommits, _, err := p.Client.Repositories.ListCommits(p.Context, owner, repo, githubOpt)
if err != nil {
fmt.Println(err)
log.Logger().Errorf("%s", err)
return nil, fmt.Errorf("Could not find commits for repository %s/%s", owner, repo)
}
var commits []*GitCommit
Expand Down
2 changes: 1 addition & 1 deletion pkg/jx/cmd/create_cluster_iks.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (o *CreateClusterIKSOptions) createClusterIKS() error {
}

log.Logger().Infof("Creating cluster named %s", clusterName)
// fmt.Println(clusterInfo)
// log.Logger().Infof(clusterInfo)
createResponse, err := clusters.Create(clusterInfo, target)
if err != nil {
return err
Expand Down
22 changes: 11 additions & 11 deletions pkg/jx/cmd/create_cluster_oke.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {

survey.AskOne(prompt, &endpoint, nil, surveyOpts)
}
fmt.Printf("Endpoint is %s\n", endpoint)
log.Logger().Infof("Endpoint is %s\n", endpoint)
os.Setenv("ENDPOINT", endpoint)

if o.Flags.ClusterName == "" {
Expand Down Expand Up @@ -265,7 +265,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {
nodePoolSubnetIdsTemp := "[" + strings.Join(nodePoolSubnetIdsArray, ",") + "]"
err = ioutil.WriteFile("/tmp/oke_pool_config.json", []byte(nodePoolSubnetIdsTemp), 0644)
if err != nil {
fmt.Printf("error write file to /tmp file %v", err)
log.Logger().Infof("error write file to /tmp file %v", err)
}

args := []string{"ce", "cluster", "create",
Expand Down Expand Up @@ -299,7 +299,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {

err := ioutil.WriteFile("/tmp/oke_cluster_config.json", []byte(serviceLbSubnetIdsTemp), 0644)
if err != nil {
fmt.Printf("error write file to /tmp file %v", err)
log.Logger().Infof("error write file to /tmp file %v", err)
}

args = append(args, "--service-lb-subnet-ids", "file:///tmp/oke_cluster_config.json")
Expand Down Expand Up @@ -346,20 +346,20 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {
args = append(args, "--wait-interval-seconds", clusterWaitIntervalSeconds)
}

fmt.Printf("Args are: %s\n", args)
log.Logger().Infof("Args are: %s\n", args)
log.Logger().Info("Creating cluster...")
output, err := o.GetCommandOutput("", "oci", args...)
if err != nil {
return err
}

fmt.Printf("Create cluster output: %s\n", output)
log.Logger().Infof("Create cluster output: %s\n", output)

if strings.Contains(output, "identifier") {
subClusterInfo := strings.Split(output, "identifier")
clusterIdRaw := strings.Split(subClusterInfo[1], "}")
clusterId := strings.TrimSpace(strings.Replace(clusterIdRaw[0][4:], "\"", "", -1))
fmt.Printf("Cluster id: %s\n", clusterId)
log.Logger().Infof("Cluster id: %s\n", clusterId)

//setup the kube context
log.Logger().Info("Setup kube context ...")
Expand Down Expand Up @@ -395,7 +395,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {
initialNodeLabelsJson := "[" + initialNodeLabels + "]"
err := ioutil.WriteFile("/tmp/oke_pool_labels_config.json", []byte(initialNodeLabelsJson), 0644)
if err != nil {
fmt.Printf("error write file to /tmp file %v", err)
log.Logger().Infof("error write file to /tmp file %v", err)
}
poolArgs = poolArgs + " --initial-node-labels=file:///tmp/oke_pool_labels_config.json"
}
Expand All @@ -419,7 +419,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {
poolArgsArray = append(poolArgsArray, sshPubKey)
}

fmt.Printf("Pool creation args are: %s\n", poolArgsArray)
log.Logger().Infof("Pool creation args are: %s\n", poolArgsArray)
poolCreationOutput, err := o.GetCommandOutput("", "oci", poolArgsArray...)
if err != nil {
return err
Expand All @@ -430,7 +430,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {
subPoolInfo := strings.Split(poolCreationOutput, "identifier")
poolIdRaw := strings.Split(subPoolInfo[1], "}")
poolId := strings.TrimSpace(strings.Replace(poolIdRaw[0][4:], "\"", "", -1))
fmt.Printf("Node Pool id: %s\n", poolId)
log.Logger().Infof("Node Pool id: %s\n", poolId)

//get node pool status until they are active
nodeQuantity, err := strconv.Atoi(quantityPerSubnet)
Expand All @@ -445,7 +445,7 @@ func (o *CreateClusterOKEOptions) createClusterOKE() error {

if isTillerEnabled {
//need to wait for tiller pod is running
fmt.Printf("Wait for tiller pod is running\n")
log.Logger().Infof("Wait for tiller pod is running\n")
err = o.waitForTillerComeUp()
if err != nil {
return fmt.Errorf("Failed to wait for Tiller to be ready: %s\n", err)
Expand Down Expand Up @@ -483,7 +483,7 @@ func (o *CreateClusterOKEOptions) waitForNodeToComeUp(nodeQuantity int, poolId s
}

count := len(status.FindAllStringIndex(poolStatusOutput, -1))
fmt.Printf("Now only %d nodes are ready\n", count)
log.Logger().Infof("Now only %d nodes are ready\n", count)
if count == nodeQuantity {
break
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/jx/cmd/create_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (options *CreateTerraformOptions) CreateOrganisationFolderStructure(dir str
}

func (options *CreateTerraformOptions) createClusters(dir string, clusterDefinitions []Cluster) error {
fmt.Printf("Creating/Updating %v clusters\n", util.ColorInfo(len(clusterDefinitions)))
log.Logger().Infof("Creating/Updating %v clusters\n", util.ColorInfo(len(clusterDefinitions)))
for _, c := range clusterDefinitions {
switch v := c.(type) {
case *GKECluster:
Expand Down
3 changes: 1 addition & 2 deletions pkg/jx/cmd/delete_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"errors"
"fmt"
"os"
"os/exec"

Expand Down Expand Up @@ -88,6 +87,6 @@ func (o *deleteEksOptions) Run() error {
if err != nil {
return nil
}
fmt.Print(string(output))
log.Logger().Infof(string(output))
return nil
}
9 changes: 4 additions & 5 deletions pkg/jx/cmd/get_eks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"os"
"os/exec"

Expand Down Expand Up @@ -93,7 +92,7 @@ func (o *GetEksOptions) Run() error {
if err != nil {
return nil
}
fmt.Print(string(output))
log.Logger().Infof(string(output))
return nil
} else {
cluster := o.Args[0]
Expand All @@ -117,14 +116,14 @@ func (o *GetEksOptions) Run() error {
}

if o.Output == "" {
fmt.Println("NAME")
fmt.Println(cluster)
log.Logger().Infof("NAME")
log.Logger().Infof(cluster)
} else if o.Output == "yaml" {
reservations, err := yaml.Marshal(instances.Reservations)
if err != nil {
return err
}
fmt.Println(string(reservations))
log.Logger().Infof(string(reservations))
} else {
return errors.New("Invalid output format.")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/jx/cmd/get_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/jenkins-x/jx/pkg/log"

"github.com/jenkins-x/jx/pkg/jx/cmd/helper"

Expand Down Expand Up @@ -91,7 +92,7 @@ func (o *GetPreviewOptions) CurrentPreviewUrl() error {
}
for _, env := range envList.Items {
if env.Spec.Kind == v1.EnvironmentKindTypePreview && env.Name == name {
fmt.Printf("%s", env.Spec.PreviewGitSpec.ApplicationURL)
log.Logger().Infof("%s", env.Spec.PreviewGitSpec.ApplicationURL)
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/jx/cmd/opts/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (o *CommonOptions) InstallChartOrGitOps(isGitOps bool, gitOpsDir string, gi
chartUntarDir, _ := ioutil.TempDir("", chart+uuid.NewUUID().String())
err := o.Helm().FetchChart(chart, version, true, chartUntarDir, repo, "", "")
if err != nil {
fmt.Println(err)
log.Logger().Errorf("unable to fetch chart - %s", err)
}

// Maybe modify the gitOpsEnvDir to after a fetch
Expand Down
5 changes: 2 additions & 3 deletions pkg/jx/cmd/step/git/step_git_fork_and_clone.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package git

import (
"fmt"
"os"

"github.com/jenkins-x/jx/pkg/jx/cmd/helper"

"github.com/jenkins-x/jx/pkg/log"

errors "github.com/pkg/errors"
"github.com/pkg/errors"

"github.com/jenkins-x/jx/pkg/gits"
"github.com/jenkins-x/jx/pkg/jx/cmd/opts"
Expand Down Expand Up @@ -92,7 +91,7 @@ func (o *StepGitForkAndCloneOptions) Run() error {
o.OutDir = dir
if o.PrintOutDir {
// Output the directory so it can be used in a script
fmt.Print(dir)
log.Logger().Infof(dir)
}
if gitInfo.Fork {
log.Logger().Infof("Forked %s and pulled it into %s checking out %s", gitURL, dir, baseRef)
Expand Down
5 changes: 3 additions & 2 deletions pkg/jx/cmd/step/verify/step_verify_pod_ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/jenkins-x/jx/pkg/jx/cmd/helper"
"github.com/jenkins-x/jx/pkg/log"
"os"
"os/exec"

Expand Down Expand Up @@ -70,15 +71,15 @@ func (o *StepVerifyPodReadyOptions) Run() error {
return errors.Wrapf(err, "failed to list the PODs in namespace '%s'", ns)
}

fmt.Println("Checking pod statuses")
log.Logger().Infof("Checking pod statuses")

table := o.CreateTable()
table.AddRow("POD", "STATUS")

var f *os.File

if o.Debug {
fmt.Println("Creating verify-pod.log file")
log.Logger().Infof("Creating verify-pod.log file")
f, err = os.Create("verify-pod.log")
if err != nil {
return errors.Wrap(err, "error creating log file")
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ func (k *PipelineActivityKey) addBatchBuildData(activitiesClient typev1.Pipeline
if i.Spec.Build != "" && selectedPipeline.Spec.Build != "" {
ib, err := strconv.Atoi(i.Spec.Build)
if err != nil {
fmt.Println(err)
log.Logger().Errorf("%s", err)
}
cb, err := strconv.Atoi(selectedPipeline.Spec.Build)
if err != nil {
fmt.Println(err)
log.Logger().Errorf("%s", err)
}
if ib > cb {
selectedPipeline = i
Expand Down
15 changes: 8 additions & 7 deletions pkg/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package terraform
import (
"fmt"
"github.com/blang/semver"
"github.com/jenkins-x/jx/pkg/log"
"github.com/pkg/errors"
"io/ioutil"
"os"
Expand All @@ -13,10 +14,10 @@ import (
)

func Init(terraformDir string, serviceAccountPath string) error {
fmt.Println("Initialising Terraform")
log.Logger().Infof("Initialising Terraform")

if _, err := os.Stat(".terraform"); !os.IsNotExist(err) {
fmt.Println("Discovered local .terraform directory, removing...")
log.Logger().Infof("Discovered local .terraform directory, removing...")
err = os.RemoveAll(".terraform")
if err != nil {
return errors.Wrap(err, "unable to remove local .terraform directory")
Expand All @@ -36,7 +37,7 @@ func Init(terraformDir string, serviceAccountPath string) error {
}

func Plan(terraformDir string, terraformVars string, serviceAccountPath string) (string, error) {
fmt.Println("Showing Terraform Plan")
log.Logger().Infof("Showing Terraform Plan")
cmd := util.Command{
Name: "terraform",
Args: []string{"plan",
Expand All @@ -53,7 +54,7 @@ func Plan(terraformDir string, terraformVars string, serviceAccountPath string)
}

func Apply(terraformDir string, terraformVars string, serviceAccountPath string, stdout io.Writer, stderr io.Writer) error {
fmt.Println("Applying Terraform")
log.Logger().Infof("Applying Terraform")
cmd := util.Command{
Name: "terraform",
Args: []string{"apply", "-auto-approve",
Expand Down Expand Up @@ -123,7 +124,7 @@ func ReadValueFromFile(path string, key string) (string, error) {

// CheckVersion checks the installed version of terraform to sure it is greater than 0.11.0
func CheckVersion() error {
fmt.Println("Checking Terraform Version...")
log.Logger().Infof("Checking Terraform Version...")
cmd := util.Command{
Name: "terraform",
Args: []string{"-version"},
Expand All @@ -135,7 +136,7 @@ func CheckVersion() error {

version, err := extractVersionFromTerraformOutput(output)

fmt.Printf("Determined terraform version as %s\n", util.ColorInfo(version))
log.Logger().Infof("Determined terraform version as %s", util.ColorInfo(version))

if err != nil {
return err
Expand All @@ -148,7 +149,7 @@ func CheckVersion() error {
return errors.New("terraform version appears to be too old, please install a newer version '>= 0.11.0'")
}

fmt.Printf("Terraform version appears to be valid\n")
log.Logger().Infof("Terraform version appears to be valid")

return nil
}
Expand Down

0 comments on commit f4eaaee

Please sign in to comment.