-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update workload controller for new design (#675)
**Requirements:** - [x] Merge stashed/stash#647 to master - [x] Merge stashed/stash#673 to master - [x] Merge stashed/stash#674 to master - [x] Merge stashed/stash#671 to master - [x] Rebase against master **Tasks:** - [x] Update Restore Logic - [x] Update Backup Logic - [x] Update Workload Controllers - [x] Deployment - [x] DaemonSet - [x] ReplicationControler - [x] ReplicaSet - [x] StatefulSet - [x] Fix ConfigMap lock deletion and RBAC stuff deletion logic - [x] Ensure sidecar/init-container according to new design - [x] Ensure Restore init-container injection - [x] Ensure Restore init-container deletion - [x] Ensure Backup sidecar injection - [x] Ensure Backup sidecar deletion - [x] Add new backup command (sagor is working) - [x] Add new restore command - [x] Add controller (possibly in different PR) - [x] PersistentVolumeClaim - [x] AppBinding
- Loading branch information
1 parent
5c173e5
commit cacbc7d
Showing
6 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmds | ||
|
||
import ( | ||
"github.com/appscode/go/log" | ||
cs "github.com/appscode/stash/client/clientset/versioned" | ||
"github.com/appscode/stash/pkg/restic" | ||
"github.com/appscode/stash/pkg/restore" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/util/errors" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"kmodules.xyz/client-go/meta" | ||
) | ||
|
||
func NewCmdRestore() *cobra.Command { | ||
opt := &restore.Options{ | ||
MasterURL: "", | ||
KubeconfigPath: "", | ||
Namespace: meta.Namespace(), | ||
SetupOpt: restic.SetupOptions{ | ||
ScratchDir: "/tmp", | ||
EnableCache: false, | ||
}, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "restore", | ||
Short: "Restore from backup", | ||
DisableAutoGenTag: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// create client | ||
config, err := clientcmd.BuildConfigFromFlags(opt.MasterURL, opt.KubeconfigPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
return err | ||
} | ||
opt.KubeClient = kubernetes.NewForConfigOrDie(config) | ||
opt.StashClient = cs.NewForConfigOrDie(config) | ||
|
||
opt.Metrics.JobName = opt.RestoreSessionName | ||
// run restore | ||
err = restore.Restore(opt) | ||
if err != nil { | ||
// set RestoreSession status "Failed", write event and send prometheus metrics | ||
e2 := restore.HandleRestoreFailure(opt, err) | ||
if e2 != nil { | ||
err = errors.NewAggregate([]error{err, e2}) | ||
} | ||
log.Fatalln(err) | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().StringVar(&opt.MasterURL, "master", opt.MasterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)") | ||
cmd.Flags().StringVar(&opt.KubeconfigPath, "kubeconfig", opt.KubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).") | ||
cmd.Flags().StringVar(&opt.RestoreSessionName, "restore-session", opt.RestoreSessionName, "Name of the RestoreSession CRD.") | ||
cmd.Flags().DurationVar(&opt.BackoffMaxWait, "backoff-max-wait", 0, "Maximum wait for initial response from kube apiserver; 0 disables the timeout") | ||
cmd.Flags().BoolVar(&opt.SetupOpt.EnableCache, "enable-cache", opt.SetupOpt.EnableCache, "Specify weather to enable caching for restic") | ||
cmd.Flags().StringVar(&opt.SetupOpt.SecretDir, "secret-dir", opt.SetupOpt.SecretDir, "Directory where storage secret has been mounted") | ||
|
||
cmd.Flags().BoolVar(&opt.Metrics.Enabled, "metrics-enabled", opt.Metrics.Enabled, "Specify weather to export Prometheus metrics") | ||
cmd.Flags().StringVar(&opt.Metrics.PushgatewayURL, "pushgateway-url", opt.Metrics.PushgatewayURL, "Pushgateway URL where the metrics will be pushed") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters