mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #70443 from juanvallejo/jvallejo/plugin-list-improvements
prevent sorting of PATH dirs for kubectl plugins
This commit is contained in:
commit
59625d8788
@ -9,7 +9,6 @@ go_library(
|
|||||||
"//pkg/kubectl/cmd/util:go_default_library",
|
"//pkg/kubectl/cmd/util:go_default_library",
|
||||||
"//pkg/kubectl/util/i18n:go_default_library",
|
"//pkg/kubectl/util/i18n:go_default_library",
|
||||||
"//pkg/kubectl/util/templates:go_default_library",
|
"//pkg/kubectl/util/templates:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
||||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||||
],
|
],
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -26,7 +27,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
@ -108,11 +108,12 @@ func (o *PluginListOptions) Run() error {
|
|||||||
|
|
||||||
pluginsFound := false
|
pluginsFound := false
|
||||||
isFirstFile := true
|
isFirstFile := true
|
||||||
|
pluginErrors := []error{}
|
||||||
pluginWarnings := 0
|
pluginWarnings := 0
|
||||||
paths := sets.NewString(filepath.SplitList(os.Getenv(path))...)
|
for _, dir := range filepath.SplitList(os.Getenv(path)) {
|
||||||
for _, dir := range paths.List() {
|
|
||||||
files, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
pluginErrors = append(pluginErrors, fmt.Errorf("error: unable to read directory %q in your PATH: %v", dir, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,15 +147,23 @@ func (o *PluginListOptions) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !pluginsFound {
|
if !pluginsFound {
|
||||||
return fmt.Errorf("error: unable to find any kubectl plugins in your PATH")
|
pluginErrors = append(pluginErrors, fmt.Errorf("error: unable to find any kubectl plugins in your PATH"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if pluginWarnings > 0 {
|
if pluginWarnings > 0 {
|
||||||
fmt.Fprintln(o.ErrOut)
|
|
||||||
if pluginWarnings == 1 {
|
if pluginWarnings == 1 {
|
||||||
return fmt.Errorf("one plugin warning was found")
|
pluginErrors = append(pluginErrors, fmt.Errorf("error: one plugin warning was found"))
|
||||||
|
} else {
|
||||||
|
pluginErrors = append(pluginErrors, fmt.Errorf("error: %v plugin warnings were found", pluginWarnings))
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%v plugin warnings were found", pluginWarnings)
|
}
|
||||||
|
if len(pluginErrors) > 0 {
|
||||||
|
fmt.Fprintln(o.ErrOut)
|
||||||
|
errs := bytes.NewBuffer(nil)
|
||||||
|
for _, e := range pluginErrors {
|
||||||
|
fmt.Fprintln(errs, e)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%s", errs.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user