Move files from samos123/pspmigrator into here

This commit is contained in:
Sam Stoelinga
2022-06-24 10:13:51 -07:00
parent 5134cadbb8
commit 2a0d58fcb5
20 changed files with 2131 additions and 11 deletions

57
cmd/root.go Normal file
View 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())
}
}