diff --git a/commands/operator-sdk/cmd/add/api.go b/commands/operator-sdk/cmd/add/api.go index f5f0db379d..01b1af8932 100644 --- a/commands/operator-sdk/cmd/add/api.go +++ b/commands/operator-sdk/cmd/add/api.go @@ -15,13 +15,12 @@ package add import ( - "log" - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate" "github.com/operator-framework/operator-sdk/internal/util/projutil" "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -95,7 +94,7 @@ func apiRun(cmd *cobra.Command, args []string) { // update deploy/role.yaml for the given resource r. if err := scaffold.UpdateRoleForResource(r, absProjectPath); err != nil { - log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): %v", r.APIVersion, r.Kind, err) + log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): (%v)", r.APIVersion, r.Kind, err) } // Run k8s codegen for deepcopy diff --git a/commands/operator-sdk/cmd/add/controller.go b/commands/operator-sdk/cmd/add/controller.go index bc1a3351d8..8f28d39949 100644 --- a/commands/operator-sdk/cmd/add/controller.go +++ b/commands/operator-sdk/cmd/add/controller.go @@ -15,12 +15,11 @@ package add import ( - "log" - "github.com/operator-framework/operator-sdk/internal/util/projutil" "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/commands/operator-sdk/cmd/add/crd.go b/commands/operator-sdk/cmd/add/crd.go index e6980bae40..e433e7fbd9 100644 --- a/commands/operator-sdk/cmd/add/crd.go +++ b/commands/operator-sdk/cmd/add/crd.go @@ -16,7 +16,6 @@ package add import ( "fmt" - "log" "os" "path/filepath" "strings" @@ -25,6 +24,7 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -60,26 +60,26 @@ func crdFunc(cmd *cobra.Command, args []string) { verifyCrdFlags() verifyCrdDeployPath() - fmt.Fprintln(os.Stdout, "Generating custom resource definition (CRD) file") + fmt.Println("Generating custom resource definition (CRD) file") // generate CR/CRD file resource, err := scaffold.NewResource(apiVersion, kind) if err != nil { - log.Fatalf("%v", err) + log.Fatal(err) } + s := scaffold.Scaffold{} err = s.Execute(cfg, &scaffold.Crd{Resource: resource}, &scaffold.Cr{Resource: resource}, ) - if err != nil { log.Fatalf("add scaffold failed: (%v)", err) } // update deploy/role.yaml for the given resource r. if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil { - log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): %v", resource.APIVersion, resource.Kind, err) + log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err) } } @@ -103,7 +103,7 @@ func verifyCrdFlags() { func verifyCrdDeployPath() { wd, err := os.Getwd() if err != nil { - log.Fatalf("failed to determine the full path of the current directory: %v", err) + log.Fatalf("failed to determine the full path of the current directory: (%v)", err) } // check if the deploy sub-directory exist _, err = os.Stat(filepath.Join(wd, scaffold.DeployDir)) diff --git a/commands/operator-sdk/cmd/build.go b/commands/operator-sdk/cmd/build.go index cd638291fc..1617d7591a 100644 --- a/commands/operator-sdk/cmd/build.go +++ b/commands/operator-sdk/cmd/build.go @@ -19,7 +19,6 @@ import ( "errors" "fmt" "io/ioutil" - "log" "os" "os/exec" "path/filepath" @@ -30,6 +29,7 @@ import ( "github.com/operator-framework/operator-sdk/pkg/test" "github.com/ghodss/yaml" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -78,11 +78,11 @@ func verifyDeploymentImage(yamlFile []byte, imageName string) error { yamlMap := make(map[string]interface{}) err := yaml.Unmarshal(yamlSpec, &yamlMap) if err != nil { - log.Fatal("Could not unmarshal yaml namespaced spec") + log.Fatalf("could not unmarshal yaml namespaced spec: (%v)", err) } kind, ok := yamlMap["kind"].(string) if !ok { - log.Fatal("Yaml manifest file contains a 'kind' field that is not a string") + log.Fatal("yaml manifest file contains a 'kind' field that is not a string") } if kind == "Deployment" { // this is ugly and hacky; we should probably make this cleaner @@ -122,13 +122,13 @@ func verifyDeploymentImage(yamlFile []byte, imageName string) error { func verifyTestManifest(image string) { namespacedBytes, err := ioutil.ReadFile(namespacedManBuild) if err != nil { - log.Fatalf("could not read namespaced manifest: %v", err) + log.Fatalf("could not read namespaced manifest: (%v)", err) } err = verifyDeploymentImage(namespacedBytes, image) // the error from verifyDeploymentImage is just a warning, not fatal error if err != nil { - fmt.Printf("%v\n", err) + log.Warn(err) } } @@ -141,7 +141,7 @@ func buildFunc(cmd *cobra.Command, args []string) { goBuildEnv := append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0") wd, err := os.Getwd() if err != nil { - log.Fatalf("could not identify current working directory: %v", err) + log.Fatalf("could not identify current working directory: (%v)", err) } // Don't need to build go code if Ansible Operator @@ -154,7 +154,7 @@ func buildFunc(cmd *cobra.Command, args []string) { buildCmd.Stderr = os.Stderr err = buildCmd.Run() if err != nil { - log.Fatalf("failed to build operator binary: %v", err) + log.Fatalf("failed to build operator binary: (%v)", err) } } @@ -169,9 +169,9 @@ func buildFunc(cmd *cobra.Command, args []string) { err = dbcmd.Run() if err != nil { if enableTests { - log.Fatalf("failed to build intermediate image for %s image: %v", image, err) + log.Fatalf("failed to output intermediate image %s: (%v)", image, err) } else { - log.Fatalf("failed to output build image %s: %v", image, err) + log.Fatalf("failed to output build image %s: (%v)", image, err) } } @@ -183,7 +183,7 @@ func buildFunc(cmd *cobra.Command, args []string) { buildTestCmd.Stderr = os.Stderr err = buildTestCmd.Run() if err != nil { - log.Fatalf("failed to build test binary: %v", err) + log.Fatalf("failed to build test binary: (%v)", err) } // if a user is using an older sdk repo as their library, make sure they have required build files testDockerfile := filepath.Join(scaffold.BuildTestDir, scaffold.DockerfileFile) @@ -204,7 +204,7 @@ func buildFunc(cmd *cobra.Command, args []string) { &scaffold.TestPod{Image: image, TestNamespaceEnv: test.TestNamespaceEnv}, ) if err != nil { - log.Fatalf("build scaffold failed: (%v)", err) + log.Fatalf("test scaffold failed: (%v)", err) } } @@ -213,7 +213,7 @@ func buildFunc(cmd *cobra.Command, args []string) { testDbcmd.Stderr = os.Stderr err = testDbcmd.Run() if err != nil { - log.Fatalf("failed to output build image %s: %v", image, err) + log.Fatalf("failed to output test image %s: (%v)", image, err) } // Check image name of deployments in namespaced manifest verifyTestManifest(image) diff --git a/commands/operator-sdk/cmd/generate/k8s.go b/commands/operator-sdk/cmd/generate/k8s.go index 51ae911277..2c5920dbb2 100644 --- a/commands/operator-sdk/cmd/generate/k8s.go +++ b/commands/operator-sdk/cmd/generate/k8s.go @@ -17,7 +17,6 @@ package generate import ( "fmt" "io/ioutil" - "log" "os" "os/exec" "path/filepath" @@ -25,6 +24,7 @@ import ( "github.com/operator-framework/operator-sdk/internal/util/projutil" "github.com/operator-framework/operator-sdk/pkg/scaffold" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -41,7 +41,7 @@ to comply with kube-API requirements. func k8sFunc(cmd *cobra.Command, args []string) { if len(args) != 0 { - log.Fatalf("k8s command doesn't accept any arguments.") + log.Fatal("k8s command doesn't accept any arguments") } // Only Go projects can generate k8s deepcopy code. @@ -62,7 +62,7 @@ func K8sCodegen() { log.Fatalf("failed to parse group versions: (%v)", err) } - fmt.Fprintf(os.Stdout, "Running code-generation for custom resource group versions: [%s]\n", groupVersions) + log.Printf("Running code-generation for custom resource group versions: [%s]\n", groupVersions) // TODO: Replace generate-groups.sh by building the vendored generators(deepcopy, lister etc) // and running them directly // TODO: remove dependency on boilerplate.go.txt @@ -73,11 +73,13 @@ func K8sCodegen() { apisPkg, groupVersions, } - out, err := exec.Command(genGroupsCmd, args...).CombinedOutput() + cgCmd := exec.Command(genGroupsCmd, args...) + cgCmd.Stdout = os.Stdout + cgCmd.Stderr = os.Stderr + err = cgCmd.Run() if err != nil { log.Fatalf("failed to perform code-generation: (%v)", err) } - fmt.Fprintln(os.Stdout, string(out)) } // getGroupVersions parses the layout of pkg/apis to return the API groups and versions @@ -108,5 +110,9 @@ func parseGroupVersions() (string, error) { } } + if groupVersions == "" { + return "", fmt.Errorf("no groups or versions found in %s", scaffold.ApisDir) + } + return groupVersions, nil } diff --git a/commands/operator-sdk/cmd/new.go b/commands/operator-sdk/cmd/new.go index b699089d77..99cb90370e 100644 --- a/commands/operator-sdk/cmd/new.go +++ b/commands/operator-sdk/cmd/new.go @@ -17,7 +17,6 @@ package cmd import ( "fmt" "io/ioutil" - "log" "os" "os/exec" "path/filepath" @@ -28,6 +27,7 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold/ansible" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -150,13 +150,13 @@ func doAnsibleScaffold() { resource, err := scaffold.NewResource(apiVersion, kind) if err != nil { - log.Fatal("Invalid apiVersion and kind.") + log.Fatalf("invalid apiVersion and kind: (%v)", err) } s := &scaffold.Scaffold{} tmpdir, err := ioutil.TempDir("", "osdk") if err != nil { - log.Fatal("unable to get temp directory") + log.Fatalf("unable to get temp directory: (%v)", err) } galaxyInit := &ansible.GalaxyInit{ @@ -196,7 +196,7 @@ func doAnsibleScaffold() { }, ) if err != nil { - log.Fatalf("new scaffold failed: (%v)", err) + log.Fatalf("new playbook scaffold failed: (%v)", err) } } @@ -210,12 +210,12 @@ func doAnsibleScaffold() { // everything. tmpDirectorySlice := strings.Split(os.TempDir(), "/") if err = os.RemoveAll(filepath.Join(galaxyInit.AbsProjectPath, tmpDirectorySlice[1])); err != nil { - log.Fatalf("failed to remove the galaxy init script") + log.Fatalf("failed to remove the galaxy init script: (%v)", err) } // update deploy/role.yaml for the given resource r. if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil { - log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): %v", resource.APIVersion, resource.Kind, err) + log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err) } } @@ -254,14 +254,14 @@ func execCmd(stdout *os.File, cmd string, args ...string) { dc.Stderr = os.Stderr err := dc.Run() if err != nil { - log.Fatalf("failed to exec %s %#v: %v", cmd, args, err) + log.Fatalf("failed to exec %s %#v: (%v)", cmd, args, err) } } func pullDep() { _, err := exec.LookPath(dep) if err != nil { - log.Fatalf("looking for dep in $PATH: %v", err) + log.Fatalf("looking for dep in $PATH: (%v)", err) } fmt.Fprintln(os.Stdout, "Run dep ensure ...") execCmd(os.Stdout, dep, ensureCmd, "-v") diff --git a/commands/operator-sdk/cmd/test/cluster.go b/commands/operator-sdk/cmd/test/cluster.go index 8abebee850..64535be425 100644 --- a/commands/operator-sdk/cmd/test/cluster.go +++ b/commands/operator-sdk/cmd/test/cluster.go @@ -24,6 +24,7 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/test" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -110,7 +111,7 @@ func testClusterFunc(cmd *cobra.Command, args []string) error { defer func() { err = kubeclient.CoreV1().Pods(tcConfig.namespace).Delete(testPod.Name, &metav1.DeleteOptions{}) if err != nil { - fmt.Printf("Warning: failed to delete test pod") + log.Warn("failed to delete test pod") } }() err = wait.Poll(time.Second*5, time.Second*time.Duration(tcConfig.pendingTimeout), func() (bool, error) { @@ -140,7 +141,7 @@ func testClusterFunc(cmd *cobra.Command, args []string) error { time.Sleep(time.Second * 5) continue } else if testPod.Status.Phase == v1.PodSucceeded { - fmt.Printf("Test Successfully Completed\n") + fmt.Println("Test Successfully Completed") return nil } else if testPod.Status.Phase == v1.PodFailed { req := kubeclient.CoreV1().Pods(tcConfig.namespace).GetLogs(testPod.Name, &v1.PodLogOptions{}) diff --git a/commands/operator-sdk/cmd/test/local.go b/commands/operator-sdk/cmd/test/local.go index 17a8b72a3c..99850168bf 100644 --- a/commands/operator-sdk/cmd/test/local.go +++ b/commands/operator-sdk/cmd/test/local.go @@ -17,7 +17,6 @@ package cmdtest import ( "fmt" "io/ioutil" - "log" "os" "os/exec" "path/filepath" @@ -28,6 +27,7 @@ import ( "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/test" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -60,32 +60,31 @@ func NewTestLocalCmd() *cobra.Command { func testLocalFunc(cmd *cobra.Command, args []string) { if len(args) != 1 { - log.Fatalf("operator-sdk test local requires exactly 1 argument") + log.Fatal("operator-sdk test local requires exactly 1 argument") } // if no namespaced manifest path is given, combine deploy/service_account.yaml, deploy/role.yaml, deploy/role_binding.yaml and deploy/operator.yaml if tlConfig.namespacedManPath == "" { err := os.MkdirAll(deployTestDir, os.FileMode(fileutil.DefaultDirFileMode)) if err != nil { - log.Fatalf("could not create %s: %v", deployTestDir, err) + log.Fatalf("could not create %s: (%v)", deployTestDir, err) } tlConfig.namespacedManPath = filepath.Join(deployTestDir, "namespace-manifests.yaml") - saFile := filepath.Join(scaffold.DeployDir, scaffold.ServiceAccountYamlFile) - sa, err := ioutil.ReadFile(saFile) + sa, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.ServiceAccountYamlFile)) if err != nil { - log.Printf("WARN: could not find the manifest %s: %v", saFile, err) + log.Warnf("could not find the serviceaccount manifest: (%v)", err) } role, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.RoleYamlFile)) if err != nil { - log.Printf("WARN: could not find role manifest: %v", err) + log.Warnf("could not find role manifest: (%v)", err) } roleBinding, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.RoleBindingYamlFile)) if err != nil { - log.Printf("WARN: could not find role_binding manifest: %v", err) + log.Warnf("could not find role_binding manifest: (%v)", err) } operator, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.OperatorYamlFile)) if err != nil { - log.Fatalf("could not find operator manifest: %v", err) + log.Fatalf("could not find operator manifest: (%v)", err) } combined := []byte{} combined = combineManifests(combined, sa) @@ -94,31 +93,31 @@ func testLocalFunc(cmd *cobra.Command, args []string) { combined = append(combined, operator...) err = ioutil.WriteFile(tlConfig.namespacedManPath, combined, os.FileMode(fileutil.DefaultFileMode)) if err != nil { - log.Fatalf("could not create temporary namespaced manifest file: %v", err) + log.Fatalf("could not create temporary namespaced manifest file: (%v)", err) } defer func() { err := os.Remove(tlConfig.namespacedManPath) if err != nil { - log.Fatalf("could not delete temporary namespace manifest file") + log.Fatalf("could not delete temporary namespace manifest file: (%v)", err) } }() } if tlConfig.globalManPath == "" { err := os.MkdirAll(deployTestDir, os.FileMode(fileutil.DefaultDirFileMode)) if err != nil { - log.Fatalf("could not create %s: %v", deployTestDir, err) + log.Fatalf("could not create %s: (%v)", deployTestDir, err) } tlConfig.globalManPath = filepath.Join(deployTestDir, "global-manifests.yaml") files, err := ioutil.ReadDir(scaffold.CrdsDir) if err != nil { - log.Fatalf("could not read deploy directory: %v", err) + log.Fatalf("could not read deploy directory: (%v)", err) } var combined []byte for _, file := range files { if strings.HasSuffix(file.Name(), "crd.yaml") { fileBytes, err := ioutil.ReadFile(filepath.Join(scaffold.CrdsDir, file.Name())) if err != nil { - log.Fatalf("could not read file %s: %v", filepath.Join(scaffold.CrdsDir, file.Name()), err) + log.Fatalf("could not read file %s: (%v)", filepath.Join(scaffold.CrdsDir, file.Name()), err) } if combined == nil { combined = []byte{} @@ -130,12 +129,12 @@ func testLocalFunc(cmd *cobra.Command, args []string) { } err = ioutil.WriteFile(tlConfig.globalManPath, combined, os.FileMode(fileutil.DefaultFileMode)) if err != nil { - log.Fatalf("could not create temporary global manifest file: %v", err) + log.Fatalf("could not create temporary global manifest file: (%v)", err) } defer func() { err := os.Remove(tlConfig.globalManPath) if err != nil { - log.Fatalf("could not delete global namespace manifest file") + log.Fatalf("could not delete global namespace manifest file: (%v)", err) } }() } @@ -159,7 +158,7 @@ func testLocalFunc(cmd *cobra.Command, args []string) { dc.Stderr = os.Stderr err := dc.Run() if err != nil { - log.Fatalf("failed to exec `go %s`: %v", strings.Join(testArgs, " "), err) + log.Fatalf("failed to exec `go %s`: (%v)", strings.Join(testArgs, " "), err) } } diff --git a/commands/operator-sdk/cmd/up/local.go b/commands/operator-sdk/cmd/up/local.go index 58cffa380e..6c850542d7 100644 --- a/commands/operator-sdk/cmd/up/local.go +++ b/commands/operator-sdk/cmd/up/local.go @@ -16,7 +16,6 @@ package up import ( "fmt" - "log" "os" "os/exec" "os/signal" @@ -35,7 +34,7 @@ import ( ansibleScaffold "github.com/operator-framework/operator-sdk/pkg/scaffold/ansible" sdkVersion "github.com/operator-framework/operator-sdk/version" - "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -91,14 +90,14 @@ func mustKubeConfig() { if len(kubeConfig) == 0 { usr, err := user.Current() if err != nil { - log.Fatalf("failed to determine user's home dir: %v", err) + log.Fatalf("failed to determine user's home dir: (%v)", err) } kubeConfig = filepath.Join(usr.HomeDir, defaultConfigPath) } _, err := os.Stat(kubeConfig) if err != nil && os.IsNotExist(err) { - log.Fatalf("failed to find the kubeconfig file (%v): %v", kubeConfig, err) + log.Fatalf("failed to find the kubeconfig file (%v): (%v)", kubeConfig, err) } } @@ -119,16 +118,17 @@ func upLocal() { <-c err := dc.Process.Kill() if err != nil { - log.Fatalf("failed to terminate the operator: %v", err) + log.Fatalf("failed to terminate the operator: (%v)", err) } os.Exit(0) }() dc.Stdout = os.Stdout dc.Stderr = os.Stderr - dc.Env = append(os.Environ(), fmt.Sprintf("%v=%v", k8sutil.KubeConfigEnvVar, kubeConfig), fmt.Sprintf("%v=%v", k8sutil.WatchNamespaceEnvVar, namespace)) + dc.Env = append(os.Environ(), fmt.Sprintf("%v=%v", k8sutil.KubeConfigEnvVar, kubeConfig)) + dc.Env = append(dc.Env, fmt.Sprintf("%v=%v", k8sutil.WatchNamespaceEnvVar, namespace)) err := dc.Run() if err != nil { - log.Fatalf("failed to run operator locally: %v", err) + log.Fatalf("failed to run operator locally: (%v)", err) } } @@ -144,7 +144,7 @@ func upLocalAnsible() { } printVersion() - logrus.Infof("watching namespace: %s", namespace) + log.Infof("watching namespace: %s", namespace) done := make(chan error) // start the proxy @@ -154,7 +154,7 @@ func upLocalAnsible() { KubeConfig: mgr.GetConfig(), }) if err != nil { - logrus.Fatalf("error starting proxy: %v", err) + log.Fatalf("error starting proxy: (%v)", err) } // start the operator @@ -162,15 +162,14 @@ func upLocalAnsible() { // wait for either to finish err = <-done - if err == nil { - logrus.Info("Exiting") - } else { - logrus.Fatal(err.Error()) + if err != nil { + log.Fatal(err) } + log.Info("Ansible operator started succesfully. Exiting.") } func printVersion() { - logrus.Infof("Go Version: %s", runtime.Version()) - logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH) - logrus.Infof("operator-sdk Version: %v", sdkVersion.Version) + log.Infof("Go Version: %s", runtime.Version()) + log.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH) + log.Infof("operator-sdk Version: %v", sdkVersion.Version) } diff --git a/internal/util/fileutil/file_util.go b/internal/util/fileutil/file_util.go index 995edc210f..de2b36fb75 100644 --- a/internal/util/fileutil/file_util.go +++ b/internal/util/fileutil/file_util.go @@ -19,11 +19,11 @@ package fileutil import ( "fmt" "io" - "log" "os" "path/filepath" "sync" + log "github.com/sirupsen/logrus" "github.com/spf13/afero" ) diff --git a/internal/util/projutil/project_util.go b/internal/util/projutil/project_util.go index 377ddead6f..68a5490ac3 100644 --- a/internal/util/projutil/project_util.go +++ b/internal/util/projutil/project_util.go @@ -15,11 +15,11 @@ package projutil import ( - "log" "os" "path/filepath" "strings" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -50,7 +50,7 @@ func MustInProjectRoot() { // we are at the project root. _, err := os.Stat(buildDockerfile) if err != nil && os.IsNotExist(err) { - log.Fatalf("must run command in project root dir: %v", err) + log.Fatalf("must run command in project root dir: (%v)", err) } } diff --git a/pkg/scaffold/role.go b/pkg/scaffold/role.go index 7f76f566ad..1cf9166761 100644 --- a/pkg/scaffold/role.go +++ b/pkg/scaffold/role.go @@ -19,12 +19,12 @@ import ( "errors" "fmt" "io/ioutil" - "log" "path/filepath" "github.com/operator-framework/operator-sdk/internal/util/fileutil" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + log "github.com/sirupsen/logrus" yaml "gopkg.in/yaml.v2" rbacv1 "k8s.io/api/rbac/v1" cgoscheme "k8s.io/client-go/kubernetes/scheme" @@ -70,7 +70,7 @@ func UpdateRoleForResource(r *Resource, absProjectPath string) error { // check if the resource already exists for _, resource := range pr.Resources { if resource == r.Resource { - log.Printf("deploy/role.yaml RBAC rules already up to date for the resource (%v, %v)", r.APIVersion, r.Kind) + log.Infof("deploy/role.yaml RBAC rules already up to date for the resource (%v, %v)", r.APIVersion, r.Kind) return nil } } @@ -112,7 +112,7 @@ func UpdateRoleForResource(r *Resource, absProjectPath string) error { // check if the resource already exists for _, resource := range pr.Resources { if resource == r.Resource { - log.Printf("deploy/role.yaml RBAC rules already up to date for the resource (%v, %v)", r.APIVersion, r.Kind) + log.Infof("deploy/role.yaml RBAC rules already up to date for the resource (%v, %v)", r.APIVersion, r.Kind) return nil } } diff --git a/pkg/scaffold/scaffold.go b/pkg/scaffold/scaffold.go index 18de34a82d..8bc4a25f50 100644 --- a/pkg/scaffold/scaffold.go +++ b/pkg/scaffold/scaffold.go @@ -20,7 +20,6 @@ import ( "bytes" "fmt" "io" - "log" "os" "path/filepath" "strings" @@ -28,6 +27,8 @@ import ( "github.com/operator-framework/operator-sdk/internal/util/fileutil" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + + log "github.com/sirupsen/logrus" "golang.org/x/tools/imports" ) @@ -161,7 +162,7 @@ func (s *Scaffold) doTemplate(i input.Input, e input.File, absPath string) error } _, err = f.Write(b) - fmt.Printf("Create %s\n", i.Path) + log.Infoln("Create", i.Path) return err } diff --git a/pkg/scaffold/test_setup.go b/pkg/scaffold/test_setup.go index 06c91e14d6..d2fc160b70 100644 --- a/pkg/scaffold/test_setup.go +++ b/pkg/scaffold/test_setup.go @@ -17,11 +17,12 @@ package scaffold import ( "bytes" "io" - "log" "os" "path/filepath" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" + + log "github.com/sirupsen/logrus" ) const ( @@ -43,7 +44,7 @@ var ( func mustGetImportPath() string { wd, err := os.Getwd() if err != nil { - log.Fatal("mustGetImportPath: ", err) + log.Fatalf("mustGetImportPath: (%v)", err) } return filepath.Join(wd, appRepo) } diff --git a/pkg/test/context.go b/pkg/test/context.go index 51c3dd411c..016486f123 100644 --- a/pkg/test/context.go +++ b/pkg/test/context.go @@ -15,11 +15,12 @@ package test import ( - "log" "strconv" "strings" "testing" "time" + + log "github.com/sirupsen/logrus" ) type TestCtx struct { @@ -69,7 +70,7 @@ func (ctx *TestCtx) Cleanup() { for i := len(ctx.cleanupFns) - 1; i >= 0; i-- { err := ctx.cleanupFns[i]() if err != nil { - ctx.t.Errorf("a cleanup function failed with error: %v\n", err) + ctx.t.Errorf("a cleanup function failed with error: (%v)\n", err) } } } @@ -82,7 +83,7 @@ func (ctx *TestCtx) CleanupNoT() { err := ctx.cleanupFns[i]() if err != nil { failed = true - log.Printf("a cleanup function failed with error: %v\n", err) + log.Errorf("a cleanup function failed with error: (%v)", err) } } if failed { diff --git a/pkg/test/main_entry.go b/pkg/test/main_entry.go index 25c75b5d63..16f01c7493 100644 --- a/pkg/test/main_entry.go +++ b/pkg/test/main_entry.go @@ -17,9 +17,10 @@ package test import ( "flag" "io/ioutil" - "log" "os" "testing" + + log "github.com/sirupsen/logrus" ) const ( diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 77c6cfe7e1..143a1d6102 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -18,11 +18,11 @@ import ( goctx "context" "flag" "fmt" - "log" "os" "sync" "time" + log "github.com/sirupsen/logrus" extscheme "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/scheme" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" diff --git a/test/e2e/framework/main_entry.go b/test/e2e/framework/main_entry.go index e409894154..d962757d26 100644 --- a/test/e2e/framework/main_entry.go +++ b/test/e2e/framework/main_entry.go @@ -15,14 +15,15 @@ package framework import ( - "log" "os" "testing" + + log "github.com/sirupsen/logrus" ) func MainEntry(m *testing.M) { if err := setup(); err != nil { - log.Fatalf("failed to set up framework: %v", err) + log.Fatalf("failed to set up framework: (%v)", err) } os.Exit(m.Run())