Move files from samos123/pspmigrator into here
This commit is contained in:
57
cmd/root.go
Normal file
57
cmd/root.go
Normal file
@ -0,0 +1,57 @@
|
||||
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())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user