2019-01-01 08:23:01 +00:00
|
|
|
package kubectl
|
|
|
|
|
|
|
|
import (
|
|
|
|
goflag "flag"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2019-01-09 16:54:15 +00:00
|
|
|
"github.com/rancher/k3s/pkg/server"
|
2019-01-01 08:23:01 +00:00
|
|
|
"github.com/spf13/pflag"
|
2019-04-08 17:53:52 +00:00
|
|
|
utilflag "k8s.io/component-base/cli/flag"
|
|
|
|
"k8s.io/component-base/logs"
|
2019-01-01 08:23:01 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Main() {
|
|
|
|
kubenv := os.Getenv("KUBECONFIG")
|
|
|
|
if kubenv == "" {
|
2019-02-19 17:46:35 +00:00
|
|
|
config, err := server.HomeKubeConfig(false)
|
2019-01-01 08:23:01 +00:00
|
|
|
if _, serr := os.Stat(config); err == nil && serr == nil {
|
|
|
|
os.Setenv("KUBECONFIG", config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
|
|
|
command := cmd.NewDefaultKubectlCommand()
|
|
|
|
|
|
|
|
// TODO: once we switch everything over to Cobra commands, we can go back to calling
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|