Skip to content

Commit

Permalink
use logrus to replace fmt.Print
Browse files Browse the repository at this point in the history
Signed-off-by: lowang-bh <lhui_wang@163.com>
  • Loading branch information
lowang-bh committed Aug 30, 2023
1 parent a2153f7 commit 9ba019e
Show file tree
Hide file tree
Showing 52 changed files with 141 additions and 97 deletions.
6 changes: 2 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package main

import (
"log"

"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"sigs.k8s.io/kubebuilder/v3/pkg/cli"
Expand Down Expand Up @@ -88,9 +86,9 @@ func main() {
cli.WithCompletion(),
)
if err != nil {
log.Fatal(err)
logrus.Fatal(err)
}
if err := c.Run(); err != nil {
log.Fatal(err)
logrus.Fatal(err)
}
}
8 changes: 4 additions & 4 deletions hack/docs/generate_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package main

import (
"fmt"
log "github.com/sirupsen/logrus"

componentconfig "sigs.k8s.io/kubebuilder/v3/hack/docs/internal/component-config-tutorial"
cronjob "sigs.k8s.io/kubebuilder/v3/hack/docs/internal/cronjob-tutorial"
Expand All @@ -27,12 +27,12 @@ import (
const KubebuilderBinName = "/tmp/kubebuilder/bin/kubebuilder"

func main() {
fmt.Println("Generating documents...")
log.Println("Generating documents...")

fmt.Println("Generating component-config tutorial...")
log.Println("Generating component-config tutorial...")
UpdateComponentConfigTutorial()

fmt.Println("Generating cronjob tutorial...")
log.Println("Generating cronjob tutorial...")
UpdateCronjobTutorial()
// TODO: Generate multiversion-tutorial
}
Expand Down
4 changes: 2 additions & 2 deletions hack/docs/internal/cronjob-tutorial/generate_cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ limitations under the License.
package cronjob

import (
"fmt"
"os"
"os/exec"
"path/filepath"

log "github.com/sirupsen/logrus"
"github.com/spf13/afero"

pluginutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
)
Expand Down Expand Up @@ -97,7 +97,7 @@ func (sp *Sample) GenerateSampleProject() {
}

func (sp *Sample) UpdateTutorial() {
fmt.Println("TODO: update tutorial")
log.Println("TODO: update tutorial")
// 1. update specs
updateSpec(sp)
// 2. update webhook
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/alpha/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package alpha

import (
"log"
log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
"sigs.k8s.io/kubebuilder/v3/pkg/rescaffold"
Expand Down
5 changes: 3 additions & 2 deletions pkg/plugin/util/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ limitations under the License.
package util

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

log "github.com/sirupsen/logrus"
)

// RunCmd prints the provided message and command and then executes it binding stdout and stderr
func RunCmd(msg, cmd string, args ...string) error {
c := exec.Command(cmd, args...) //nolint:gosec
c.Stdout = os.Stdout
c.Stderr = os.Stderr
fmt.Println(msg + ":\n$ " + strings.Join(c.Args, " "))
log.Println(msg + ":\n$ " + strings.Join(c.Args, " "))
return c.Run()
}
4 changes: 3 additions & 1 deletion pkg/plugins/common/kustomize/v1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package scaffolds
import (
"fmt"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
Expand Down Expand Up @@ -60,7 +62,7 @@ func (s *apiScaffolder) InjectFS(fs machinery.Filesystem) {

// Scaffold implements cmdutil.Scaffolder
func (s *apiScaffolder) Scaffold() error {
fmt.Println("Writing kustomize manifests for you to edit...")
log.Println("Writing kustomize manifests for you to edit...")

// Initialize the machinery.Scaffold that will write the files to disk
scaffold := machinery.NewScaffold(s.fs,
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/common/kustomize/v1/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package scaffolds

import (
"fmt"
log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (s *initScaffolder) InjectFS(fs machinery.Filesystem) {

// Scaffold implements cmdutil.Scaffolder
func (s *initScaffolder) Scaffold() error {
fmt.Println("Writing kustomize manifests for you to edit...")
log.Println("Writing kustomize manifests for you to edit...")

// Initialize the machinery.Scaffold that will write the files to disk
scaffold := machinery.NewScaffold(s.fs,
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/common/kustomize/v1/scaffolds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package scaffolds
import (
"fmt"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
Expand Down Expand Up @@ -55,7 +57,7 @@ func (s *webhookScaffolder) InjectFS(fs machinery.Filesystem) { s.fs = fs }

// Scaffold implements cmdutil.Scaffolder
func (s *webhookScaffolder) Scaffold() error {
fmt.Println("Writing kustomize manifests for you to edit...")
log.Println("Writing kustomize manifests for you to edit...")

// Initialize the machinery.Scaffold that will write the files to disk
scaffold := machinery.NewScaffold(s.fs,
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/common/kustomize/v2/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package scaffolds
import (
"fmt"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
Expand Down Expand Up @@ -60,7 +62,7 @@ func (s *apiScaffolder) InjectFS(fs machinery.Filesystem) {

// Scaffold implements cmdutil.Scaffolder
func (s *apiScaffolder) Scaffold() error {
fmt.Println("Writing kustomize manifests for you to edit...")
log.Println("Writing kustomize manifests for you to edit...")

// Initialize the machinery.Scaffold that will write the files to disk
scaffold := machinery.NewScaffold(s.fs,
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/common/kustomize/v2/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package scaffolds

import (
"fmt"
log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (s *initScaffolder) InjectFS(fs machinery.Filesystem) {

// Scaffold implements cmdutil.Scaffolder
func (s *initScaffolder) Scaffold() error {
fmt.Println("Writing kustomize manifests for you to edit...")
log.Println("Writing kustomize manifests for you to edit...")

// Initialize the machinery.Scaffold that will write the files to disk
scaffold := machinery.NewScaffold(s.fs,
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/common/kustomize/v2/scaffolds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package scaffolds
import (
"fmt"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
Expand Down Expand Up @@ -55,7 +57,7 @@ func (s *webhookScaffolder) InjectFS(fs machinery.Filesystem) { s.fs = fs }

// Scaffold implements cmdutil.Scaffolder
func (s *webhookScaffolder) Scaffold() error {
fmt.Println("Writing kustomize manifests for you to edit...")
log.Println("Writing kustomize manifests for you to edit...")

// Initialize the machinery.Scaffold that will write the files to disk
scaffold := machinery.NewScaffold(s.fs,
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/golang/declarative/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"errors"
"fmt"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
Expand Down Expand Up @@ -92,7 +94,7 @@ func (p *createAPISubcommand) InjectResource(res *resource.Resource) error {
}

func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error {
fmt.Println("updating scaffold with declarative pattern...")
log.Println("updating scaffold with declarative pattern...")

scaffolder := scaffolds.NewAPIScaffolder(p.config, *p.resource)
scaffolder.InjectFS(fs)
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/golang/declarative/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
Expand Down Expand Up @@ -51,7 +53,7 @@ func (p *initSubcommand) Scaffold(_ machinery.Filesystem) error {

// updateDockerfile will add channels staging required for declarative plugin
func updateDockerfile(isLegacyLayout bool) error {
fmt.Println("updating Dockerfile to add channels/ directory in the image")
log.Println("updating Dockerfile to add channels/ directory in the image")
dockerfile := filepath.Join("Dockerfile")

controllerPath := "internal/controller/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package templates

import (
"fmt"
"path/filepath"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
)

Expand All @@ -37,7 +38,7 @@ func (f *Channel) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("channels", "stable")
}
fmt.Println(f.Path)
log.Println(f.Path)

f.TemplateBody = channelTemplate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package templates

import (
"fmt"
"path/filepath"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
)

Expand Down Expand Up @@ -56,7 +57,7 @@ func (f *Controller) SetTemplateDefaults() error {

}
f.Path = f.Resource.Replacer().Replace(f.Path)
fmt.Println(f.Path)
log.Println(f.Path)

f.PackageName = "controller"
if f.IsLegacyLayout {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package templates

import (
"fmt"
"path/filepath"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
)

Expand All @@ -39,7 +40,7 @@ func (f *Manifest) SetTemplateDefaults() error {
f.Path = filepath.Join("channels", "packages", "%[kind]", f.ManifestVersion, "manifest.yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)
fmt.Println(f.Path)
log.Println(f.Path)

f.TemplateBody = manifestTemplate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"path/filepath"
"text/template"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
)

Expand Down Expand Up @@ -56,7 +58,7 @@ func (f *Types) SetTemplateDefaults() error {

}
f.Path = f.Resource.Replacer().Replace(f.Path)
fmt.Println(f.Path)
log.Println(f.Path)

f.TemplateBody = typesTemplate

Expand Down
7 changes: 4 additions & 3 deletions pkg/plugins/golang/deploy-image/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
"os"
"strings"

"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
goPlugin "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
log "github.com/sirupsen/logrus"

"github.com/spf13/pflag"
"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
goPlugin "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds"
)

Expand Down Expand Up @@ -204,7 +205,7 @@ func (p *createAPISubcommand) PreScaffold(machinery.Filesystem) error {
}

func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error {
fmt.Println("updating scaffold with deploy-image/v1alpha1 plugin...")
log.Println("updating scaffold with deploy-image/v1alpha1 plugin...")

scaffolder := scaffolds.NewDeployImageScaffolder(p.config,
*p.resource,
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"path/filepath"
"strings"

"sigs.k8s.io/kubebuilder/v3/pkg/plugin"

log "github.com/sirupsen/logrus"
"github.com/spf13/afero"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins"
kustomizev1scaffolds "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1/scaffolds"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (s *apiScaffolder) InjectFS(fs machinery.Filesystem) {

// Scaffold implements cmdutil.Scaffolder
func (s *apiScaffolder) Scaffold() error {
fmt.Println("Writing scaffold for you to edit...")
log.Println("Writing scaffold for you to edit...")

//nolint: staticcheck
isGoV3 := plugin.IsLegacyLayout(s.config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package api

import (
"fmt"
"path/filepath"

log "github.com/sirupsen/logrus"

"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ func (f *Types) SetTemplateDefaults() error {
}

f.Path = f.Resource.Replacer().Replace(f.Path)
fmt.Println(f.Path)
log.Println(f.Path)

f.TemplateBody = typesTemplate

Expand Down
Loading

0 comments on commit 9ba019e

Please sign in to comment.