diff --git a/cmd/generate-plugin-overview/go.mod b/cmd/generate-plugin-overview/go.mod index aa94c8f1..5afa8bef 100644 --- a/cmd/generate-plugin-overview/go.mod +++ b/cmd/generate-plugin-overview/go.mod @@ -4,5 +4,5 @@ go 1.12 require ( github.com/pkg/errors v0.8.1 // indirect - sigs.k8s.io/krew v0.2.2-0.20190724210953-8867a94acd6d + sigs.k8s.io/krew v0.3.2 ) diff --git a/cmd/generate-plugin-overview/go.sum b/cmd/generate-plugin-overview/go.sum index b03fed2a..3e954193 100644 --- a/cmd/generate-plugin-overview/go.sum +++ b/cmd/generate-plugin-overview/go.sum @@ -9,6 +9,7 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZ github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= @@ -46,7 +47,9 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= @@ -85,6 +88,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -116,6 +120,8 @@ k8s.io/klog v0.3.3/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/kube-openapi v0.0.0-20190709113604-33be087ad058/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4= sigs.k8s.io/krew v0.2.2-0.20190724210953-8867a94acd6d h1:ftkzey0SeGithDvmwEsUnlDwV1PKn8i+rNEfabj1W8w= sigs.k8s.io/krew v0.2.2-0.20190724210953-8867a94acd6d/go.mod h1:wsheYhp5znrUApov8QcNjBCwXu85fIGjRJvjSkE8pI8= +sigs.k8s.io/krew v0.3.2 h1:FKBD9xy9GtO5A8FeVk/cbgG6vzPbUg4SwUziZj/TGoU= +sigs.k8s.io/krew v0.3.2/go.mod h1:G0cvdJtBb0gHBQZtCBumtllvhU6H+ggDr2oLznaLglc= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/cmd/krew/cmd/install.go b/cmd/krew/cmd/install.go index 66b13936..3b1513a0 100644 --- a/cmd/krew/cmd/install.go +++ b/cmd/krew/cmd/install.go @@ -19,9 +19,9 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" + "k8s.io/klog" "sigs.k8s.io/krew/cmd/krew/cmd/internal" "sigs.k8s.io/krew/pkg/index" @@ -110,7 +110,7 @@ Remarks: } for _, plugin := range install { - glog.V(2).Infof("Will install plugin: %s\n", plugin.Name) + klog.V(2).Infof("Will install plugin: %s\n", plugin.Name) } var failed []string @@ -121,11 +121,11 @@ Remarks: ArchiveFileOverride: *archiveFileOverride, }) if err == installation.ErrIsAlreadyInstalled { - glog.Warningf("Skipping plugin %q, it is already installed", plugin.Name) + klog.Warningf("Skipping plugin %q, it is already installed", plugin.Name) continue } if err != nil { - glog.Warningf("failed to install plugin %q: %v", plugin.Name, err) + klog.Warningf("failed to install plugin %q: %v", plugin.Name, err) if returnErr == nil { returnErr = err } @@ -145,11 +145,11 @@ Remarks: }, PreRunE: func(cmd *cobra.Command, args []string) error { if *manifest != "" { - glog.V(4).Infof("--manifest specified, not ensuring plugin index") + klog.V(4).Infof("--manifest specified, not ensuring plugin index") return nil } if *noUpdateIndex { - glog.V(4).Infof("--no-update-index specified, skipping updating local copy of plugin index") + klog.V(4).Infof("--no-update-index specified, skipping updating local copy of plugin index") return nil } return ensureIndexUpdated(cmd, args) diff --git a/cmd/krew/cmd/root.go b/cmd/krew/cmd/root.go index 75f213d7..2164eac4 100644 --- a/cmd/krew/cmd/root.go +++ b/cmd/krew/cmd/root.go @@ -19,11 +19,11 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/mattn/go-isatty" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/environment" @@ -52,17 +52,20 @@ You can invoke krew through kubectl: "kubectl krew [command]..."`, // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := rootCmd.Execute(); err != nil { - if glog.V(1) { - glog.Fatalf("%+v", err) // with stack trace + if klog.V(1) { + klog.Fatalf("%+v", err) // with stack trace } else { - glog.Fatal(err) // just error message + klog.Fatal(err) // just error message } } } func init() { + klog.InitFlags(nil) + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) _ = flag.CommandLine.Parse([]string{}) // convince pkg/flag we parsed the flags + flag.CommandLine.VisitAll(func(f *flag.Flag) { if f.Name != "v" { // hide all glog flags except for -v pflag.Lookup(f.Name).Hidden = true @@ -79,7 +82,7 @@ func init() { paths.InstallPath(), paths.BinPath(), paths.InstallReceiptsPath()); err != nil { - glog.Fatal(err) + klog.Fatal(err) } } @@ -95,11 +98,11 @@ func preRun(cmd *cobra.Command, _ []string) error { } if installation.IsWindows() { - glog.V(4).Infof("detected windows, will check for old krew installations to clean up") + klog.V(4).Infof("detected windows, will check for old krew installations to clean up") err := cleanupStaleKrewInstallations() if err != nil { - glog.Warningf("Failed to clean up old installations of krew (on windows).") - glog.Warningf("You may need to clean them up manually. Error: %v", err) + klog.Warningf("Failed to clean up old installations of krew (on windows).") + klog.Warningf("You may need to clean them up manually. Error: %v", err) } } return nil @@ -108,14 +111,14 @@ func preRun(cmd *cobra.Command, _ []string) error { func cleanupStaleKrewInstallations() error { r, err := receipt.Load(paths.PluginInstallReceiptPath(constants.KrewPluginName)) if os.IsNotExist(err) { - glog.V(1).Infof("could not find krew's own plugin receipt, skipping cleanup of stale krew installations") + klog.V(1).Infof("could not find krew's own plugin receipt, skipping cleanup of stale krew installations") return nil } else if err != nil { return errors.Wrap(err, "cannot load krew's own plugin receipt") } v := r.Spec.Version - glog.V(1).Infof("Clean up krew stale installations, current=%s", v) + klog.V(1).Infof("Clean up krew stale installations, current=%s", v) return installation.CleanupStaleKrewInstallations(paths.PluginInstallPath(constants.KrewPluginName), v) } @@ -130,7 +133,7 @@ func checkIndex(_ *cobra.Command, _ []string) error { func ensureDirs(paths ...string) error { for _, p := range paths { - glog.V(4).Infof("Ensure creating dir: %q", p) + klog.V(4).Infof("Ensure creating dir: %q", p) if err := os.MkdirAll(p, 0755); err != nil { return errors.Wrapf(err, "failed to ensure create directory %q", p) } diff --git a/cmd/krew/cmd/uninstall.go b/cmd/krew/cmd/uninstall.go index 0acf2185..d2fb2096 100644 --- a/cmd/krew/cmd/uninstall.go +++ b/cmd/krew/cmd/uninstall.go @@ -18,9 +18,9 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/installation" ) @@ -38,7 +38,7 @@ Remarks: Failure to uninstall a plugin will result in an error and exit immediately.`, RunE: func(cmd *cobra.Command, args []string) error { for _, name := range args { - glog.V(4).Infof("Going to uninstall plugin %s\n", name) + klog.V(4).Infof("Going to uninstall plugin %s\n", name) if err := installation.Uninstall(paths, name); err != nil { return errors.Wrapf(err, "failed to uninstall plugin %s", name) } diff --git a/cmd/krew/cmd/update.go b/cmd/krew/cmd/update.go index 30ee3a89..0965de5b 100644 --- a/cmd/krew/cmd/update.go +++ b/cmd/krew/cmd/update.go @@ -18,9 +18,9 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/gitutil" @@ -42,7 +42,7 @@ Remarks: } func ensureIndexUpdated(_ *cobra.Command, _ []string) error { - glog.V(1).Infof("Updating the local copy of plugin index (%s)", paths.IndexPath()) + klog.V(1).Infof("Updating the local copy of plugin index (%s)", paths.IndexPath()) if err := gitutil.EnsureUpdated(constants.IndexURI, paths.IndexPath()); err != nil { return errors.Wrap(err, "failed to update the local index") } diff --git a/cmd/krew/cmd/upgrade.go b/cmd/krew/cmd/upgrade.go index 85e0ba10..231acc09 100644 --- a/cmd/krew/cmd/upgrade.go +++ b/cmd/krew/cmd/upgrade.go @@ -18,9 +18,9 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" + "k8s.io/klog" "sigs.k8s.io/krew/cmd/krew/cmd/internal" "sigs.k8s.io/krew/pkg/index/indexscanner" @@ -62,7 +62,7 @@ kubectl krew upgrade foo bar"`, return errors.Wrapf(err, "failed to load the plugin manifest for plugin %s", name) } - glog.V(2).Infof("Upgrading plugin: %s\n", plugin.Name) + klog.V(2).Infof("Upgrading plugin: %s\n", plugin.Name) err = installation.Upgrade(paths, plugin) if ignoreUpgraded && err == installation.ErrIsAlreadyUpgraded { fmt.Fprintf(os.Stderr, "Skipping plugin %s, it is already on the newest version\n", plugin.Name) @@ -78,7 +78,7 @@ kubectl krew upgrade foo bar"`, }, PreRunE: func(cmd *cobra.Command, args []string) error { if *noUpdateIndex { - glog.V(4).Infof("--no-update-index specified, skipping updating local copy of plugin index") + klog.V(4).Infof("--no-update-index specified, skipping updating local copy of plugin index") return nil } return ensureIndexUpdated(cmd, args) diff --git a/cmd/krew/main.go b/cmd/krew/main.go index 666fce35..15e2ca8b 100644 --- a/cmd/krew/main.go +++ b/cmd/krew/main.go @@ -15,12 +15,12 @@ package main import ( - "github.com/golang/glog" + "k8s.io/klog" "sigs.k8s.io/krew/cmd/krew/cmd" ) func main() { cmd.Execute() - defer glog.Flush() + defer klog.Flush() } diff --git a/cmd/validate-krew-manifest/main.go b/cmd/validate-krew-manifest/main.go index 0f580cd6..e6ee048d 100644 --- a/cmd/validate-krew-manifest/main.go +++ b/cmd/validate-krew-manifest/main.go @@ -25,10 +25,10 @@ import ( "path/filepath" "strings" - "github.com/golang/glog" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/index" @@ -40,29 +40,29 @@ var flManifest string func init() { flag.StringVar(&flManifest, "manifest", "", "path to plugin manifest file") - if err := flag.Set("logtostderr", "true"); err != nil { - fmt.Printf("can't set log to stderr %+v", err) - os.Exit(1) - } } func main() { // TODO(ahmetb) iterate over glog flags and hide them (not sure if possible without using pflag) + klog.InitFlags(nil) + if err := flag.Set("logtostderr", "true"); err != nil { + fmt.Printf("can't set log to stderr %+v", err) + os.Exit(1) + } flag.Parse() - - defer glog.Flush() + defer klog.Flush() if flManifest == "" { - glog.Fatal("-manifest must be specified") + klog.Fatal("-manifest must be specified") } if err := validateManifestFile(flManifest); err != nil { - glog.Fatalf("%v", err) // with stack trace + klog.Fatalf("%v", err) // with stack trace } } func validateManifestFile(path string) error { - glog.V(4).Infof("reading file %s", path) + klog.V(4).Infof("reading file %s", path) p, err := indexscanner.ReadPluginFile(path) if err != nil { return errors.Wrap(err, "failed to read plugin file") @@ -73,13 +73,13 @@ func validateManifestFile(path string) error { return fmt.Errorf("expected manifest extension %q but found %q", constants.ManifestExtension, manifestExtension) } pluginNameFromFileName := strings.TrimSuffix(filename, manifestExtension) - glog.V(4).Infof("inferred plugin name as %s", pluginNameFromFileName) + klog.V(4).Infof("inferred plugin name as %s", pluginNameFromFileName) // validate plugin manifest if err := validation.ValidatePlugin(pluginNameFromFileName, p); err != nil { return errors.Wrap(err, "plugin validation error") } - glog.Infof("structural validation OK") + klog.Infof("structural validation OK") // make sure each platform matches a supported platform for i, p := range p.Spec.Platforms { @@ -87,21 +87,21 @@ func validateManifestFile(path string) error { return errors.Errorf("spec.platform[%d]'s selector (%v) doesn't match any supported platforms", i, p.Selector) } } - glog.Infof("all spec.platform[] items are used") + klog.Infof("all spec.platform[] items are used") // validate no supported is matching multiple platform specs if err := isOverlappingPlatformSelectors(p.Spec.Platforms); err != nil { return errors.Wrap(err, "overlapping platform selectors found") } - glog.Infof("no overlapping spec.platform[].selector") + klog.Infof("no overlapping spec.platform[].selector") // exercise "install" for all platforms for i, p := range p.Spec.Platforms { - glog.Infof("installing spec.platform[%d]", i) + klog.Infof("installing spec.platform[%d]", i) if err := installPlatformSpec(path, p); err != nil { return errors.Wrapf(err, "spec.platforms[%d] failed to install", i) } - glog.Infof("installed spec.platforms[%d]", i) + klog.Infof("installed spec.platforms[%d]", i) } log.Printf("all %d spec.platforms installed fine", len(p.Spec.Platforms)) return nil @@ -141,7 +141,7 @@ func installPlatformSpec(manifestFile string, p index.Platform) error { } defer func() { if err := os.RemoveAll(tmpDir); err != nil { - glog.Warningf("failed to remove temp dir: %s", tmpDir) + klog.Warningf("failed to remove temp dir: %s", tmpDir) } }() @@ -152,7 +152,7 @@ func installPlatformSpec(manifestFile string, p index.Platform) error { "KREW_OS=" + goos, "KREW_ARCH=" + goarch, } - glog.V(2).Infof("installing plugin with: %+v", cmd.Env) + klog.V(2).Infof("installing plugin with: %+v", cmd.Env) cmd.Env = append(cmd.Env, "PATH="+os.Getenv("PATH")) b, err := cmd.CombinedOutput() @@ -167,10 +167,10 @@ func installPlatformSpec(manifestFile string, p index.Platform) error { func findAnyMatchingPlatform(selector *metav1.LabelSelector) (string, string) { for _, p := range allPlatforms() { if selectorMatchesOSArch(selector, p[0], p[1]) { - glog.V(4).Infof("%s MATCHED <%s,%s>", selector, p[0], p[1]) + klog.V(4).Infof("%s MATCHED <%s,%s>", selector, p[0], p[1]) return p[0], p[1] } - glog.V(4).Infof("%s didn't match <%s,%s>", selector, p[0], p[1]) + klog.V(4).Infof("%s didn't match <%s,%s>", selector, p[0], p[1]) } return "", "" } @@ -179,7 +179,7 @@ func selectorMatchesOSArch(selector *metav1.LabelSelector, os, arch string) bool sel, err := metav1.LabelSelectorAsSelector(selector) if err != nil { // this should've been caught by validation.ValidatePlatform() earlier - glog.Warningf("Failed to convert label selector: %+v", selector) + klog.Warningf("Failed to convert label selector: %+v", selector) return false } return sel.Matches(labels.Set{ diff --git a/go.mod b/go.mod index 8e4bf722..7d9d5b91 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.12 require ( github.com/fatih/color v1.7.0 github.com/gogo/protobuf v1.2.1 // indirect - github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/google/go-cmp v0.3.0 github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect @@ -20,6 +19,6 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect k8s.io/apimachinery v0.0.0-20190717022731-0bb8574e0887 k8s.io/client-go v7.0.0+incompatible - k8s.io/klog v0.3.3 // indirect + k8s.io/klog v1.0.0 sigs.k8s.io/yaml v1.1.0 ) diff --git a/go.sum b/go.sum index 3362c142..d9202bac 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= @@ -22,8 +23,6 @@ github.com/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM= github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -127,8 +126,8 @@ k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8 k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.1 h1:RVgyDHY/kFKtLqh67NvEWIgkMneNoIrdkN0CxDSQc68= k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= -k8s.io/klog v0.3.3 h1:niceAagH1tzskmaie/icWd7ci1wbG7Bf2c6YGcQv+3c= -k8s.io/klog v0.3.3/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= +k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/kube-openapi v0.0.0-20190709113604-33be087ad058/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= diff --git a/hack/verify-code-patterns.sh b/hack/verify-code-patterns.sh index 48bd54b1..5d77e913 100755 --- a/hack/verify-code-patterns.sh +++ b/hack/verify-code-patterns.sh @@ -36,10 +36,10 @@ if [[ -n "$out" ]]; then exit 1 fi -# Do not use glog in test code +# Do not use glog/klog in test code out="$(grep --include '*_test.go' --exclude-dir 'vendor/' -EIrn '[kg]log\.' || true)" if [[ -n "$out" ]]; then - echo >&2 "You used glog in tests, use 't.Logf' instead:" + echo >&2 "You used glog or klog in tests, use 't.Logf' instead:" echo >&2 "$out" exit 1 fi diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index c63cb109..3ea5c262 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -26,8 +26,8 @@ import ( "path/filepath" "strings" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" ) // download gets a file from the internet in memory and writes it content @@ -39,19 +39,19 @@ func download(url string, verifier Verifier, fetcher Fetcher) (io.ReaderAt, int6 } defer body.Close() - glog.V(3).Infof("Reading archive file into memory") + klog.V(3).Infof("Reading archive file into memory") data, err := ioutil.ReadAll(io.TeeReader(body, verifier)) if err != nil { return nil, 0, errors.Wrap(err, "could not read archive") } - glog.V(2).Infof("Read %d bytes from archive into memory", len(data)) + klog.V(2).Infof("Read %d bytes from archive into memory", len(data)) return bytes.NewReader(data), int64(len(data)), verifier.Verify() } // extractZIP extracts a zip file into the target directory. func extractZIP(targetDir string, read io.ReaderAt, size int64) error { - glog.V(4).Infof("Extracting zip archive to %q", targetDir) + klog.V(4).Infof("Extracting zip archive to %q", targetDir) zipReader, err := zip.NewReader(read, size) if err != nil { return err @@ -97,7 +97,7 @@ func extractZIP(targetDir string, read io.ReaderAt, size int64) error { // extractTARGZ extracts a gzipped tar file into the target directory. func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error { - glog.V(4).Infof("tar: extracting to %q", targetDir) + klog.V(4).Infof("tar: extracting to %q", targetDir) in := io.NewSectionReader(at, 0, size) gzr, err := gzip.NewReader(in) @@ -115,10 +115,10 @@ func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error { if err != nil { return errors.Wrap(err, "tar extraction error") } - glog.V(4).Infof("tar: processing %q (type=%d, mode=%s)", hdr.Name, hdr.Typeflag, os.FileMode(hdr.Mode)) + klog.V(4).Infof("tar: processing %q (type=%d, mode=%s)", hdr.Name, hdr.Typeflag, os.FileMode(hdr.Mode)) // see https://golang.org/cl/78355 for handling pax_global_header if hdr.Name == "pax_global_header" { - glog.V(4).Infof("tar: skipping pax_global_header file") + klog.V(4).Infof("tar: skipping pax_global_header file") continue } @@ -134,7 +134,7 @@ func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error { } case tar.TypeReg: dir := filepath.Dir(path) - glog.V(4).Infof("tar: ensuring parent dirs exist for regular file, dir=%s", dir) + klog.V(4).Infof("tar: ensuring parent dirs exist for regular file, dir=%s", dir) if err := os.MkdirAll(dir, 0755); err != nil { return errors.Wrap(err, "failed to create directory for tar") } @@ -151,9 +151,9 @@ func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error { default: return errors.Errorf("unable to handle file type %d for %q in tar", hdr.Typeflag, hdr.Name) } - glog.V(4).Infof("tar: processed %q", hdr.Name) + klog.V(4).Infof("tar: processed %q", hdr.Name) } - glog.V(4).Infof("tar extraction to %s complete", targetDir) + klog.V(4).Infof("tar extraction to %s complete", targetDir) return nil } @@ -176,7 +176,7 @@ func detectMIMEType(at io.ReaderAt) (string, error) { return "", errors.Wrap(err, "failed to read first 512 bytes") } if n < 512 { - glog.V(5).Infof("Did only read %d of 512 bytes to determine the file type", n) + klog.V(5).Infof("Did only read %d of 512 bytes to determine the file type", n) } // Cut off mime extra info beginning with ';' i.e: @@ -200,7 +200,7 @@ func extractArchive(dst string, at io.ReaderAt, size int64) error { if err != nil { return errors.Wrap(err, "failed to determine content type") } - glog.V(4).Infof("detected %q file type", t) + klog.V(4).Infof("detected %q file type", t) exf, ok := defaultExtractors[t] if !ok { return errors.Errorf("mime type %q for archive file is not a supported archive format", t) diff --git a/pkg/download/fetch.go b/pkg/download/fetch.go index 6aea40d2..07362b75 100644 --- a/pkg/download/fetch.go +++ b/pkg/download/fetch.go @@ -19,8 +19,8 @@ import ( "net/http" "os" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" ) // Fetcher is used to get files from a URI. @@ -36,7 +36,7 @@ type HTTPFetcher struct{} // Get gets the file and returns an stream to read the file. func (HTTPFetcher) Get(uri string) (io.ReadCloser, error) { - glog.V(2).Infof("Fetching %q", uri) + klog.V(2).Infof("Fetching %q", uri) resp, err := http.Get(uri) if err != nil { return nil, errors.Wrapf(err, "failed to download %q", uri) @@ -49,7 +49,7 @@ var _ Fetcher = fileFetcher{} type fileFetcher struct{ f string } func (f fileFetcher) Get(_ string) (io.ReadCloser, error) { - glog.V(2).Infof("Reading %q", f.f) + klog.V(2).Infof("Reading %q", f.f) file, err := os.Open(f.f) return file, errors.Wrapf(err, "failed to open archive file %q for reading", f.f) } diff --git a/pkg/download/verifier.go b/pkg/download/verifier.go index 1e8fb5a9..8db95a3a 100644 --- a/pkg/download/verifier.go +++ b/pkg/download/verifier.go @@ -21,8 +21,8 @@ import ( "hash" "io" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" ) // Verifier can check a reader against it's correctness. @@ -48,7 +48,7 @@ func NewSha256Verifier(hash string) Verifier { } func (v sha256Verifier) Verify() error { - glog.V(1).Infof("Compare sha256 (%s) signed version", hex.EncodeToString(v.wantedHash)) + klog.V(1).Infof("Compare sha256 (%s) signed version", hex.EncodeToString(v.wantedHash)) if bytes.Equal(v.wantedHash, v.Sum(nil)) { return nil } diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index 65acd4c0..e376e628 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -18,9 +18,9 @@ import ( "os" "path/filepath" - "github.com/golang/glog" "github.com/pkg/errors" "k8s.io/client-go/util/homedir" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" ) @@ -38,7 +38,7 @@ func MustGetKrewPaths() Paths { base := filepath.Join(homedir.HomeDir(), ".krew") if fromEnv := os.Getenv("KREW_ROOT"); fromEnv != "" { base = fromEnv - glog.V(4).Infof("using environment override KREW_ROOT=%s", fromEnv) + klog.V(4).Infof("using environment override KREW_ROOT=%s", fromEnv) } base, err := filepath.Abs(base) if err != nil { diff --git a/pkg/gitutil/git.go b/pkg/gitutil/git.go index 49714adc..6a496dc8 100644 --- a/pkg/gitutil/git.go +++ b/pkg/gitutil/git.go @@ -22,8 +22,8 @@ import ( "path/filepath" "strings" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" ) // EnsureCloned will clone into the destination path, otherwise will return no error. @@ -70,12 +70,12 @@ func EnsureUpdated(uri, destinationPath string) error { } func exec(pwd string, args ...string) error { - glog.V(4).Infof("Going to run git %s", strings.Join(args, " ")) + klog.V(4).Infof("Going to run git %s", strings.Join(args, " ")) cmd := osexec.Command("git", args...) cmd.Dir = pwd buf := bytes.Buffer{} var w io.Writer = &buf - if glog.V(2) { + if klog.V(2) { w = io.MultiWriter(w, os.Stderr) } cmd.Stdout, cmd.Stderr = w, w diff --git a/pkg/index/indexscanner/scanner.go b/pkg/index/indexscanner/scanner.go index 1816d7fd..b6cef65a 100644 --- a/pkg/index/indexscanner/scanner.go +++ b/pkg/index/indexscanner/scanner.go @@ -21,8 +21,8 @@ import ( "path/filepath" "strings" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/yaml" "sigs.k8s.io/krew/pkg/constants" @@ -53,12 +53,12 @@ func LoadPluginListFromFS(indexDir string) ([]index.Plugin, error) { if err != nil { // Index loading shouldn't fail because of one plugin. // Show error instead. - glog.Errorf("failed to load file %q, err: %v", pluginName, err) + klog.Errorf("failed to load file %q, err: %v", pluginName, err) continue } list = append(list, p) } - glog.V(4).Infof("Found %d plugins in dir %s", len(list), indexDir) + klog.V(4).Infof("Found %d plugins in dir %s", len(list), indexDir) return list, nil } @@ -69,7 +69,7 @@ func LoadPluginFileFromFS(pluginsDir, pluginName string) (index.Plugin, error) { return index.Plugin{}, errors.Errorf("plugin name %q not allowed", pluginName) } - glog.V(4).Infof("Reading plugin %q", pluginName) + klog.V(4).Infof("Reading plugin %q", pluginName) pluginsDir, err := filepath.EvalSymlinks(pluginsDir) if err != nil { return index.Plugin{}, err diff --git a/pkg/info/info.go b/pkg/info/info.go index 6f3cd603..73a72329 100644 --- a/pkg/info/info.go +++ b/pkg/info/info.go @@ -17,8 +17,8 @@ package info import ( "os" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/environment" "sigs.k8s.io/krew/pkg/index" @@ -31,7 +31,7 @@ func LoadManifestFromReceiptOrIndex(p environment.Paths, name string) (index.Plu receipt, err := indexscanner.LoadPluginFileFromFS(p.InstallReceiptsPath(), name) if err == nil { - glog.V(3).Infof("Found plugin manifest for %q in the receipts dir", name) + klog.V(3).Infof("Found plugin manifest for %q in the receipts dir", name) return receipt, nil } @@ -39,6 +39,6 @@ func LoadManifestFromReceiptOrIndex(p environment.Paths, name string) (index.Plu return index.Plugin{}, errors.Wrapf(err, "loading plugin %q from receipts dir", name) } - glog.V(3).Infof("Plugin manifest for %q not found in the receipts dir", name) + klog.V(3).Infof("Plugin manifest for %q not found in the receipts dir", name) return indexscanner.LoadPluginFileFromFS(p.IndexPluginsPath(), name) } diff --git a/pkg/installation/install.go b/pkg/installation/install.go index 7afe7fc6..ef0bb4f4 100644 --- a/pkg/installation/install.go +++ b/pkg/installation/install.go @@ -21,8 +21,8 @@ import ( "runtime" "strings" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/download" @@ -56,7 +56,7 @@ var ( // Install will download and install a plugin. The operation tries // to not get the plugin dir in a bad state if it fails during the process. func Install(p environment.Paths, plugin index.Plugin, opts InstallOpts) error { - glog.V(2).Infof("Looking for installed versions") + klog.V(2).Infof("Looking for installed versions") _, err := receipt.Load(p.PluginInstallReceiptPath(plugin.Name)) if err == nil { return ErrIsAlreadyInstalled @@ -75,7 +75,7 @@ func Install(p environment.Paths, plugin index.Plugin, opts InstallOpts) error { // The actual install should be the last action so that a failure during receipt // saving does not result in an installed plugin without receipt. - glog.V(3).Infof("Install plugin %s at version=%s", plugin.Name, plugin.Spec.Version) + klog.V(3).Infof("Install plugin %s at version=%s", plugin.Name, plugin.Spec.Version) if err := install(installOperation{ pluginName: plugin.Name, platform: candidate, @@ -86,21 +86,21 @@ func Install(p environment.Paths, plugin index.Plugin, opts InstallOpts) error { }, opts); err != nil { return errors.Wrap(err, "install failed") } - glog.V(3).Infof("Storing install receipt for plugin %s", plugin.Name) + klog.V(3).Infof("Storing install receipt for plugin %s", plugin.Name) err = receipt.Store(plugin, p.PluginInstallReceiptPath(plugin.Name)) return errors.Wrap(err, "installation receipt could not be stored, uninstall may fail") } func install(op installOperation, opts InstallOpts) error { // Download and extract - glog.V(3).Infof("Creating download staging directory %q", op.downloadStagingDir) + klog.V(3).Infof("Creating download staging directory %q", op.downloadStagingDir) if err := os.MkdirAll(op.downloadStagingDir, 0755); err != nil { return errors.Wrapf(err, "could not create staging dir %q", op.downloadStagingDir) } defer func() { - glog.V(3).Infof("Deleting the download staging directory %s", op.downloadStagingDir) + klog.V(3).Infof("Deleting the download staging directory %s", op.downloadStagingDir) if err := os.RemoveAll(op.downloadStagingDir); err != nil { - glog.Warningf("failed to clean up download staging directory: %s", err) + klog.Warningf("failed to clean up download staging directory: %s", err) } }() if err := downloadAndExtract(op.downloadStagingDir, op.platform.URI, op.platform.Sha256, opts.ArchiveFileOverride); err != nil { @@ -131,7 +131,7 @@ func install(op installOperation, opts InstallOpts) error { func applyDefaults(platform *index.Platform) { if platform.Files == nil { platform.Files = []index.FileOperation{{From: "*", To: "."}} - glog.V(4).Infof("file operation not specified, assuming %v", platform.Files) + klog.V(4).Infof("file operation not specified, assuming %v", platform.Files) } } @@ -152,13 +152,13 @@ func downloadAndExtract(extractDir, uri, sha256sum, overrideFile string) error { // Uninstall will uninstall a plugin. func Uninstall(p environment.Paths, name string) error { if name == constants.KrewPluginName { - glog.Errorf("Removing krew through krew is not supported.") + klog.Errorf("Removing krew through krew is not supported.") if !IsWindows() { // assume POSIX-like - glog.Errorf("If you’d like to uninstall krew altogether, run:\n\trm -rf -- %q", p.BasePath()) + klog.Errorf("If you’d like to uninstall krew altogether, run:\n\trm -rf -- %q", p.BasePath()) } return errors.New("self-uninstall not allowed") } - glog.V(3).Infof("Finding installed version to delete") + klog.V(3).Infof("Finding installed version to delete") if _, err := receipt.Load(p.PluginInstallReceiptPath(name)); err != nil { if os.IsNotExist(err) { @@ -167,21 +167,21 @@ func Uninstall(p environment.Paths, name string) error { return errors.Wrapf(err, "failed to look up install receipt for plugin %q", name) } - glog.V(1).Infof("Deleting plugin %s", name) + klog.V(1).Infof("Deleting plugin %s", name) symlinkPath := filepath.Join(p.BinPath(), pluginNameToBin(name, IsWindows())) - glog.V(3).Infof("Unlink %q", symlinkPath) + klog.V(3).Infof("Unlink %q", symlinkPath) if err := removeLink(symlinkPath); err != nil { return errors.Wrap(err, "could not uninstall symlink of plugin") } pluginInstallPath := p.PluginInstallPath(name) - glog.V(3).Infof("Deleting path %q", pluginInstallPath) + klog.V(3).Infof("Deleting path %q", pluginInstallPath) if err := os.RemoveAll(pluginInstallPath); err != nil { return errors.Wrapf(err, "could not remove plugin directory %q", pluginInstallPath) } pluginReceiptPath := p.PluginInstallReceiptPath(name) - glog.V(3).Infof("Deleting plugin receipt %q", pluginReceiptPath) + klog.V(3).Infof("Deleting plugin receipt %q", pluginReceiptPath) err := os.Remove(pluginReceiptPath) return errors.Wrapf(err, "could not remove plugin receipt %q", pluginReceiptPath) } @@ -197,11 +197,11 @@ func createOrUpdateLink(binDir string, binary string, plugin string) error { } // Create new - glog.V(2).Infof("Creating symlink to %q at %q", binary, dst) + klog.V(2).Infof("Creating symlink to %q at %q", binary, dst) if err := os.Symlink(binary, dst); err != nil { return errors.Wrapf(err, "failed to create a symlink from %q to %q", binary, dst) } - glog.V(2).Infof("Created symlink at %q", dst) + klog.V(2).Infof("Created symlink at %q", dst) return nil } @@ -210,7 +210,7 @@ func createOrUpdateLink(binDir string, binary string, plugin string) error { func removeLink(path string) error { fi, err := os.Lstat(path) if os.IsNotExist(err) { - glog.V(3).Infof("No file found at %q", path) + klog.V(3).Infof("No file found at %q", path) return nil } else if err != nil { return errors.Wrapf(err, "failed to read the symlink in %q", path) @@ -222,7 +222,7 @@ func removeLink(path string) error { if err := os.Remove(path); err != nil { return errors.Wrapf(err, "failed to remove the symlink in %q", path) } - glog.V(3).Infof("Removed symlink from %q", path) + klog.V(3).Infof("Removed symlink from %q", path) return nil } @@ -252,16 +252,16 @@ func CleanupStaleKrewInstallations(dir string, currentVersion string) error { if err != nil { return errors.Wrap(err, "failed to read krew store directory") } - glog.V(2).Infof("Found %d entries in krew store directory", len(ls)) + klog.V(2).Infof("Found %d entries in krew store directory", len(ls)) for _, d := range ls { - glog.V(2).Infof("Found a krew installation: %s (%s)", d.Name(), d.Mode()) + klog.V(2).Infof("Found a krew installation: %s (%s)", d.Name(), d.Mode()) if d.IsDir() && d.Name() != currentVersion { - glog.V(1).Infof("Deleting stale krew install directory: %s", d.Name()) + klog.V(1).Infof("Deleting stale krew install directory: %s", d.Name()) p := filepath.Join(dir, d.Name()) if err := os.RemoveAll(p); err != nil { return errors.Wrapf(err, "failed to remove stale krew version at path '%s'", p) } - glog.V(1).Infof("Stale installation directory removed") + klog.V(1).Infof("Stale installation directory removed") } } return nil diff --git a/pkg/installation/move.go b/pkg/installation/move.go index fe08237c..8f8ab604 100644 --- a/pkg/installation/move.go +++ b/pkg/installation/move.go @@ -21,8 +21,8 @@ import ( "path/filepath" "syscall" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/index" "sigs.k8s.io/krew/pkg/pathutil" @@ -41,15 +41,15 @@ func findMoveTargets(fromDir, toDir string, fo index.FileOperation) ([]move, err return nil, errors.Wrap(err, "could not get the relative path for the move src") } - glog.V(4).Infof("Trying to move single file directly from=%q to=%q with file operation=%#v", fromDir, toDir, fo) + klog.V(4).Infof("Trying to move single file directly from=%q to=%q with file operation=%#v", fromDir, toDir, fo) if m, ok, err := getDirectMove(fromDir, toDir, fo); err != nil { return nil, errors.Wrap(err, "failed to detect single move operation") } else if ok { - glog.V(3).Infof("Detected single move from file operation=%#v", fo) + klog.V(3).Infof("Detected single move from file operation=%#v", fo) return []move{m}, nil } - glog.V(4).Infoln("Wasn't a single file, proceeding with Glob move") + klog.V(4).Infoln("Wasn't a single file, proceeding with Glob move") newDir, err := filepath.Abs(filepath.Join(filepath.FromSlash(toDir), filepath.FromSlash(fo.To))) if err != nil { return nil, errors.Wrap(err, "could not get the relative path for the move dst") @@ -122,14 +122,14 @@ func isMoveAllowed(fromBase, toBase string, m move) bool { } func moveFiles(fromDir, toDir string, fo index.FileOperation) error { - glog.V(4).Infof("Finding move targets from %q to %q with file operation=%#v", fromDir, toDir, fo) + klog.V(4).Infof("Finding move targets from %q to %q with file operation=%#v", fromDir, toDir, fo) moves, err := findMoveTargets(fromDir, toDir, fo) if err != nil { return errors.Wrap(err, "could not find move targets") } for _, m := range moves { - glog.V(2).Infof("Move file from %q to %q", m.from, m.to) + klog.V(2).Infof("Move file from %q to %q", m.from, m.to) if err := os.MkdirAll(filepath.Dir(m.to), 0755); err != nil { return errors.Wrapf(err, "failed to create move path %q", filepath.Dir(m.to)) } @@ -138,7 +138,7 @@ func moveFiles(fromDir, toDir string, fo index.FileOperation) error { return errors.Wrapf(err, "could not rename/copy file from %q to %q", m.from, m.to) } } - glog.V(4).Infoln("Move operations are complete") + klog.V(4).Infoln("Move operations are complete") return nil } @@ -153,13 +153,13 @@ func moveAllFiles(fromDir, toDir string, fos []index.FileOperation) error { // moveToInstallDir moves plugins from srcDir to dstDir (created in this method) with given FileOperation. func moveToInstallDir(srcDir, installDir string, fos []index.FileOperation) error { - glog.V(4).Infof("Creating plugin installation directory %q", installDir) + klog.V(4).Infof("Creating plugin installation directory %q", installDir) if err := os.MkdirAll(installDir, 0755); err != nil { return errors.Wrapf(err, "error creating installation directory at %q", installDir) } tmp, err := ioutil.TempDir("", "krew-temp-move") - glog.V(4).Infof("Creating temp plugin move operations dir %q", tmp) + klog.V(4).Infof("Creating temp plugin move operations dir %q", tmp) if err != nil { return errors.Wrap(err, "failed to find a temporary director") } @@ -169,10 +169,10 @@ func moveToInstallDir(srcDir, installDir string, fos []index.FileOperation) erro return errors.Wrap(err, "failed to move files") } - glog.V(2).Infof("Move directory %q to %q", tmp, installDir) + klog.V(2).Infof("Move directory %q to %q", tmp, installDir) if err = renameOrCopy(tmp, installDir); err != nil { defer func() { - glog.V(3).Info("Cleaning up installation directory due to error during copying files") + klog.V(3).Info("Cleaning up installation directory due to error during copying files") os.Remove(installDir) }() return errors.Wrapf(err, "could not rename/copy directory %q to %q", tmp, installDir) @@ -189,17 +189,17 @@ func renameOrCopy(from, to string) error { return errors.Wrapf(err, "error checking move target dir %q", to) } if fi != nil && fi.IsDir() { - glog.V(4).Infof("There's already a directory at move target %q. deleting.", to) + klog.V(4).Infof("There's already a directory at move target %q. deleting.", to) if err := os.RemoveAll(to); err != nil { return errors.Wrapf(err, "error cleaning up dir %q", to) } - glog.V(4).Infof("Move target directory %q cleaned up", to) + klog.V(4).Infof("Move target directory %q cleaned up", to) } err = os.Rename(from, to) // Fallback for invalid cross-device link (errno:18). if isCrossDeviceRenameErr(err) { - glog.V(2).Infof("Cross-device link error while copying, fallback to manual copy") + klog.V(2).Infof("Cross-device link error while copying, fallback to manual copy") return errors.Wrap(copyTree(from, to), "failed to copy directory tree as a fallback") } return err @@ -213,10 +213,10 @@ func copyTree(from, to string) (err error) { } newPath, _ := pathutil.ReplaceBase(path, from, to) if info.IsDir() { - glog.V(4).Infof("Creating new dir %q", newPath) + klog.V(4).Infof("Creating new dir %q", newPath) err = os.MkdirAll(newPath, info.Mode()) } else { - glog.V(4).Infof("Copying file %q", newPath) + klog.V(4).Infof("Copying file %q", newPath) err = copyFile(path, newPath, info.Mode()) } return err diff --git a/pkg/installation/platform.go b/pkg/installation/platform.go index 16401422..68754456 100644 --- a/pkg/installation/platform.go +++ b/pkg/installation/platform.go @@ -18,10 +18,10 @@ import ( "os" "runtime" - "github.com/golang/glog" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/index" ) @@ -40,7 +40,7 @@ func matchPlatform(platforms []index.Platform, os, arch string) (index.Platform, "os": os, "arch": arch, } - glog.V(2).Infof("Matching platform for labels(%v)", envLabels) + klog.V(2).Infof("Matching platform for labels(%v)", envLabels) for i, platform := range platforms { sel, err := metav1.LabelSelectorAsSelector(platform.Selector) @@ -48,7 +48,7 @@ func matchPlatform(platforms []index.Platform, os, arch string) (index.Platform, return index.Platform{}, false, errors.Wrap(err, "failed to compile label selector") } if sel.Matches(envLabels) { - glog.V(2).Infof("Found matching platform with index (%d)", i) + klog.V(2).Infof("Found matching platform with index (%d)", i) return platform, true, nil } } diff --git a/pkg/installation/upgrade.go b/pkg/installation/upgrade.go index d39e6bf5..e9250819 100644 --- a/pkg/installation/upgrade.go +++ b/pkg/installation/upgrade.go @@ -18,8 +18,8 @@ import ( "os" "path/filepath" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/environment" @@ -56,22 +56,22 @@ func Upgrade(p environment.Paths, plugin index.Plugin) error { if err != nil { return errors.Wrapf(err, "failed to parse candidate version spec (%q)", newVersion) } - glog.V(2).Infof("Comparing versions: current=%s target=%s", curv, newv) + klog.V(2).Infof("Comparing versions: current=%s target=%s", curv, newv) // See if it's a newer version if !semver.Less(curv, newv) { - glog.V(3).Infof("Plugin does not need upgrade (%s ≥ %s)", curv, newv) + klog.V(3).Infof("Plugin does not need upgrade (%s ≥ %s)", curv, newv) return ErrIsAlreadyUpgraded } - glog.V(1).Infof("Plugin needs upgrade (%s < %s)", curv, newv) + klog.V(1).Infof("Plugin needs upgrade (%s < %s)", curv, newv) - glog.V(2).Infof("Upgrading install receipt for plugin %s", plugin.Name) + klog.V(2).Infof("Upgrading install receipt for plugin %s", plugin.Name) if err = receipt.Store(plugin, p.PluginInstallReceiptPath(plugin.Name)); err != nil { return errors.Wrap(err, "installation receipt could not be stored, uninstall may fail") } // Re-Install - glog.V(1).Infof("Installing new version %s", newVersion) + klog.V(1).Infof("Installing new version %s", newVersion) if err := install(installOperation{ pluginName: plugin.Name, platform: candidate, @@ -83,7 +83,7 @@ func Upgrade(p environment.Paths, plugin index.Plugin) error { } // Clean old installations - glog.V(2).Infof("Starting old version cleanup") + klog.V(2).Infof("Starting old version cleanup") return cleanupInstallation(p, plugin, curVersion) } @@ -94,10 +94,10 @@ func Upgrade(p environment.Paths, plugin index.Plugin) error { // the directory. func cleanupInstallation(p environment.Paths, plugin index.Plugin, oldVersion string) error { if plugin.Name == constants.KrewPluginName && IsWindows() { - glog.V(1).Infof("not removing old version of krew during upgrade on windows (should be cleaned up on the next run)") + klog.V(1).Infof("not removing old version of krew during upgrade on windows (should be cleaned up on the next run)") return nil } - glog.V(1).Infof("Remove old plugin installation under %q", p.PluginVersionInstallPath(plugin.Name, oldVersion)) + klog.V(1).Infof("Remove old plugin installation under %q", p.PluginVersionInstallPath(plugin.Name, oldVersion)) return os.RemoveAll(p.PluginVersionInstallPath(plugin.Name, oldVersion)) } diff --git a/pkg/installation/util.go b/pkg/installation/util.go index 4410e95f..4758a93d 100644 --- a/pkg/installation/util.go +++ b/pkg/installation/util.go @@ -17,8 +17,8 @@ package installation import ( "path/filepath" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/installation/receipt" @@ -35,14 +35,14 @@ func ListInstalledPlugins(receiptsDir string) (map[string]string, error) { if err != nil { return nil, errors.Wrapf(err, "failed to grab receipts directory (%s) for manifests", receiptsDir) } - glog.V(4).Infof("Found %d install receipts in %s", len(matches), receiptsDir) + klog.V(4).Infof("Found %d install receipts in %s", len(matches), receiptsDir) installed := make(map[string]string) for _, m := range matches { r, err := receipt.Load(m) if err != nil { return nil, errors.Wrapf(err, "failed to parse plugin install receipt %s", m) } - glog.V(4).Infof("parsed receipt for %s: version=%s", r.GetObjectMeta().GetName(), r.Spec.Version) + klog.V(4).Infof("parsed receipt for %s: version=%s", r.GetObjectMeta().GetName(), r.Spec.Version) installed[r.GetObjectMeta().GetName()] = r.Spec.Version } return installed, nil diff --git a/pkg/receiptsmigration/migration.go b/pkg/receiptsmigration/migration.go index b29fbdac..da9fb8f2 100644 --- a/pkg/receiptsmigration/migration.go +++ b/pkg/receiptsmigration/migration.go @@ -24,8 +24,8 @@ import ( "runtime" "strings" - "github.com/golang/glog" "github.com/pkg/errors" + "k8s.io/klog" "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/environment" @@ -63,7 +63,7 @@ func Migrate(newPaths environment.Paths) error { return err } if isMigrated { - glog.Infoln("Already migrated") + klog.Infoln("Already migrated") return nil } @@ -73,7 +73,7 @@ func Migrate(newPaths environment.Paths) error { return errors.Wrapf(err, "failed to build list of plugins") } - glog.Infoln("These plugins will be reinstalled: ", installed) + klog.Infoln("These plugins will be reinstalled: ", installed) // krew must be skipped by the normal migration logic if err := copyKrewManifest(newPaths.IndexPluginsPath(), newPaths.InstallReceiptsPath()); err != nil { @@ -83,12 +83,12 @@ func Migrate(newPaths environment.Paths) error { // point of no return: keep on going when encountering errors for _, plugin := range installed { if err := uninstall(oldPaths, plugin); err != nil { - glog.Infof("Uninstalling of %s failed, skipping reinstall", plugin) + klog.Infof("Uninstalling of %s failed, skipping reinstall", plugin) continue } if err := reinstall(plugin); err != nil { - glog.Infof("Reinstalling %s failed", plugin) + klog.Infof("Reinstalling %s failed", plugin) } } @@ -128,7 +128,7 @@ func getPluginsToReinstall(oldPaths oldenvironment.Paths, newPaths environment.P continue } if !isAvailableInIndex(newPaths, plugin) { - glog.Infof("Skipping plugin %s, because it is missing in the index", plugin) + klog.Infof("Skipping plugin %s, because it is missing in the index", plugin) continue } renewable = append(renewable, plugin) @@ -148,26 +148,26 @@ func uninstall(p oldenvironment.Paths, name string) error { if name == krewPluginName { return errors.Errorf("removing krew is not allowed through krew. Please run:\n\t rm -r %s", p.BasePath()) } - glog.Infof("Uninstalling %s", name) + klog.Infof("Uninstalling %s", name) symlinkPath := filepath.Join(p.BinPath(), pluginNameToBin(name, isWindows())) - glog.V(3).Infof("Unlink %q", symlinkPath) + klog.V(3).Infof("Unlink %q", symlinkPath) if err := removeLink(symlinkPath); err != nil { return errors.Wrap(err, "could not uninstall symlink of plugin") } pluginInstallPath := p.PluginInstallPath(name) - glog.V(3).Infof("Deleting path %q", pluginInstallPath) + klog.V(3).Infof("Deleting path %q", pluginInstallPath) return errors.Wrapf(os.RemoveAll(pluginInstallPath), "could not remove plugin directory %q", pluginInstallPath) } // reinstall shells out to `krew` to install the given plugin. func reinstall(plugin string) error { - glog.Infoln("Re-installing", plugin) + klog.Infoln("Re-installing", plugin) cmd := exec.Command("kubectl", "krew", "install", plugin) output, err := cmd.CombinedOutput() if err != nil { - glog.Info(string(output)) + klog.Info(string(output)) } return err } @@ -177,7 +177,7 @@ func reinstall(plugin string) error { func removeLink(path string) error { fi, err := os.Lstat(path) if os.IsNotExist(err) { - glog.V(3).Infof("No file found at %q", path) + klog.V(3).Infof("No file found at %q", path) return nil } else if err != nil { return errors.Wrapf(err, "failed to read the symlink in %q", path) @@ -189,7 +189,7 @@ func removeLink(path string) error { if err := os.Remove(path); err != nil { return errors.Wrapf(err, "failed to remove the symlink in %q", path) } - glog.V(3).Infof("Removed symlink from %q", path) + klog.V(3).Infof("Removed symlink from %q", path) return nil } diff --git a/pkg/receiptsmigration/oldenvironment/environment.go b/pkg/receiptsmigration/oldenvironment/environment.go index 79527b70..b33803f2 100644 --- a/pkg/receiptsmigration/oldenvironment/environment.go +++ b/pkg/receiptsmigration/oldenvironment/environment.go @@ -20,9 +20,9 @@ import ( "os" "path/filepath" - "github.com/golang/glog" "github.com/pkg/errors" "k8s.io/client-go/util/homedir" + "k8s.io/klog" ) // Paths contains all important environment paths @@ -38,7 +38,7 @@ func MustGetKrewPaths() Paths { base := filepath.Join(homedir.HomeDir(), ".krew") if fromEnv := os.Getenv("KREW_ROOT"); fromEnv != "" { base = fromEnv - glog.V(4).Infof("using environment override KREW_ROOT=%s", fromEnv) + klog.V(4).Infof("using environment override KREW_ROOT=%s", fromEnv) } base, err := filepath.Abs(base) if err != nil {