Browse Source

Track upstream changes to kubectl command execution

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/5263/head
Brad Davidson 3 years ago committed by Brad Davidson
parent
commit
66e350ea88
  1. 1
      go.mod
  2. 21
      pkg/kubectl/main.go

1
go.mod

@ -102,7 +102,6 @@ require (
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
github.com/rootless-containers/rootlesskit v0.14.5 github.com/rootless-containers/rootlesskit v0.14.5
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/tchap/go-patricia v2.3.0+incompatible // indirect github.com/tchap/go-patricia v2.3.0+incompatible // indirect
github.com/urfave/cli v1.22.4 github.com/urfave/cli v1.22.4

21
pkg/kubectl/main.go

@ -1,7 +1,6 @@
package kubectl package kubectl
import ( import (
goflag "flag"
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
@ -10,10 +9,9 @@ import (
"github.com/k3s-io/k3s/pkg/server" "github.com/k3s-io/k3s/pkg/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/pflag" "k8s.io/component-base/cli"
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/kubectl/pkg/cmd" "k8s.io/kubectl/pkg/cmd"
"k8s.io/kubectl/pkg/cmd/util"
) )
func Main() { func Main() {
@ -42,19 +40,8 @@ func main() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
command := cmd.NewDefaultKubectlCommand() command := cmd.NewDefaultKubectlCommand()
if err := cli.RunNoErrOutput(command); err != nil {
// TODO: once we switch everything over to Cobra commands, we can go back to calling util.CheckErr(err)
// utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
// normalize func and add the go flag set by hand.
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
// utilflag.InitFlags()
logs.InitLogs()
defer logs.FlushLogs()
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
} }
} }

Loading…
Cancel
Save