Skip to content

Commit

Permalink
Add BackupConfiguration Controller (#671)
Browse files Browse the repository at this point in the history
- [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
  • Loading branch information
suaas21 authored and tamalsaha committed Mar 19, 2019
1 parent ef9a4ae commit d4a53e2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions backup_session.go
@@ -0,0 +1,50 @@
package cmds

import (
"github.com/appscode/go/log"
cs "github.com/appscode/stash/client/clientset/versioned"
"github.com/appscode/stash/pkg/backupsession"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"kmodules.xyz/client-go/meta"
)

func NewBackupSession() *cobra.Command {
var (
masterURL string
kubeconfigPath string

opt = backupsession.Options{
Namespace: meta.Namespace(),
}
)

cmd := &cobra.Command{
Use: "backup-session",
Short: "create a BackupSession",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath)
if err != nil {
log.Fatalf("Could not get Kubernetes config: %s", err)
}
kubeClient := kubernetes.NewForConfigOrDie(config)
stashClient := cs.NewForConfigOrDie(config)

ctrl := backupsession.New(kubeClient, stashClient, opt)
err = ctrl.CreateBackupSession()
if err != nil {
log.Fatal(err)
}

},
}

cmd.Flags().StringVar(&masterURL, "master", "", "The address of the Kubernetes API server (overrides any value in kubeconfig)")
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", "", "Path to kubeconfig file with authorization information (the master location is set by the master flag).")
cmd.Flags().StringVar(&opt.Name, "backupsession.name", "", "Set BackupSession Name")
cmd.Flags().StringVar(&opt.Namespace, "backupsession.namespace", opt.Namespace, "Set BackupSession Namespace")

return cmd
}
1 change: 1 addition & 0 deletions root.go
Expand Up @@ -48,6 +48,7 @@ func NewRootCmd() *cobra.Command {
rootCmd.AddCommand(NewCmdScaleDown())
rootCmd.AddCommand(NewCmdSnapshots())
rootCmd.AddCommand(NewCmdForget())
rootCmd.AddCommand(NewBackupSession())

return rootCmd
}

0 comments on commit d4a53e2

Please sign in to comment.