|
| 1 | +package cmds |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/appscode/go/log" |
| 5 | + cs "github.com/appscode/stash/client/clientset/versioned" |
| 6 | + "github.com/appscode/stash/pkg/backupsession" |
| 7 | + "github.com/spf13/cobra" |
| 8 | + "k8s.io/client-go/kubernetes" |
| 9 | + "k8s.io/client-go/tools/clientcmd" |
| 10 | + "kmodules.xyz/client-go/meta" |
| 11 | +) |
| 12 | + |
| 13 | +func NewBackupSession() *cobra.Command { |
| 14 | + var ( |
| 15 | + masterURL string |
| 16 | + kubeconfigPath string |
| 17 | + |
| 18 | + opt = backupsession.Options{ |
| 19 | + Namespace: meta.Namespace(), |
| 20 | + } |
| 21 | + ) |
| 22 | + |
| 23 | + cmd := &cobra.Command{ |
| 24 | + Use: "backup-session", |
| 25 | + Short: "create a BackupSession", |
| 26 | + DisableAutoGenTag: true, |
| 27 | + Run: func(cmd *cobra.Command, args []string) { |
| 28 | + config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath) |
| 29 | + if err != nil { |
| 30 | + log.Fatalf("Could not get Kubernetes config: %s", err) |
| 31 | + } |
| 32 | + kubeClient := kubernetes.NewForConfigOrDie(config) |
| 33 | + stashClient := cs.NewForConfigOrDie(config) |
| 34 | + |
| 35 | + ctrl := backupsession.New(kubeClient, stashClient, opt) |
| 36 | + err = ctrl.CreateBackupSession() |
| 37 | + if err != nil { |
| 38 | + log.Fatal(err) |
| 39 | + } |
| 40 | + |
| 41 | + }, |
| 42 | + } |
| 43 | + |
| 44 | + cmd.Flags().StringVar(&masterURL, "master", "", "The address of the Kubernetes API server (overrides any value in kubeconfig)") |
| 45 | + cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", "", "Path to kubeconfig file with authorization information (the master location is set by the master flag).") |
| 46 | + cmd.Flags().StringVar(&opt.Name, "backupsession.name", "", "Set BackupSession Name") |
| 47 | + cmd.Flags().StringVar(&opt.Namespace, "backupsession.namespace", opt.Namespace, "Set BackupSession Namespace") |
| 48 | + |
| 49 | + return cmd |
| 50 | +} |
0 commit comments