Skip to content

Commit d4a53e2

Browse files
suaas21tamalsaha
authored andcommitted
Add BackupConfiguration Controller (#671)
- [x] Add `BackupConfiguration` Controller - [x] Ensure Sidecar and CronJob - [x] Ensure RBAC for CronJob - [x] Create a CronJob which will create `BackupInstance` crd - [x] Rename BackupInstance to BackupSession Fixes: stashed/stash#649
1 parent ef9a4ae commit d4a53e2

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

backup_session.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func NewRootCmd() *cobra.Command {
4848
rootCmd.AddCommand(NewCmdScaleDown())
4949
rootCmd.AddCommand(NewCmdSnapshots())
5050
rootCmd.AddCommand(NewCmdForget())
51+
rootCmd.AddCommand(NewBackupSession())
5152

5253
return rootCmd
5354
}

0 commit comments

Comments
 (0)