Files
pspmigrator/cmd/root.go
2022-06-24 10:13:51 -07:00

58 lines
1.4 KiB
Go

package cmd
import (
"path/filepath"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
_ "k8s.io/client-go/plugin/pkg/client/auth"
//
// Or uncomment to load specific auth plugins
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
_ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
)
var RootCmd = &cobra.Command{
Use: "pspmigrator",
Short: "pspmigrator is a tool to help migrate from PSP to PSA",
}
var (
clientset *kubernetes.Clientset
err error
Namespace string
)
func init() {
initMutating()
RootCmd.AddCommand(MutatingCmd)
RootCmd.AddCommand(MigrateCmd)
var kubeconfig string
if home := homedir.HomeDir(); home != "" {
RootCmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k",
filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
RootCmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k", "", "absolute path to the kubeconfig file")
}
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
config.WarningHandler = rest.NoWarnings{}
if err != nil {
panic(err.Error())
}
// create the clientset
clientset, err = kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
}