-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show repository snapshot list (#417)
* Implement Get,List,Delete method for snapshots * Added test for snapshots * Added doc for snapshot * Remove unused snapshot handler.
- Loading branch information
Showing
4 changed files
with
115 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cmds | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/appscode/kutil/meta" | ||
cs "github.com/appscode/stash/client/clientset/versioned/typed/stash/v1alpha1" | ||
"github.com/appscode/stash/pkg/registry/snapshot" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func NewCmdForget() *cobra.Command { | ||
var ( | ||
masterURL string | ||
kubeconfigPath string | ||
repositoryName string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "forget [snapshotID ...]", | ||
Short: "Delete snapshots from a restic repository", | ||
DisableAutoGenTag: true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath) | ||
if err != nil { | ||
fmt.Errorf(err.Error()) | ||
} | ||
|
||
stashClient := cs.NewForConfigOrDie(config) | ||
|
||
if repositoryName == "" { | ||
fmt.Errorf("repository name not found") | ||
return | ||
} | ||
repo, err := stashClient.Repositories(meta.Namespace()).Get(repositoryName, metav1.GetOptions{}) | ||
if err != nil { | ||
fmt.Errorf(err.Error()) | ||
return | ||
} | ||
|
||
r := snapshot.NewREST(config) | ||
err = r.ForgetSnapshots(repo, args) | ||
if err != nil { | ||
fmt.Errorf(err.Error()) | ||
} | ||
}, | ||
} | ||
cmd.Flags().StringVar(&masterURL, "master", masterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)") | ||
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).") | ||
cmd.Flags().StringVar(&repositoryName, "repo-name", repositoryName, "Name of the Repository CRD.") | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cmds | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/appscode/kutil/meta" | ||
cs "github.com/appscode/stash/client/clientset/versioned/typed/stash/v1alpha1" | ||
"github.com/appscode/stash/pkg/registry/snapshot" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func NewCmdSnapshots() *cobra.Command { | ||
var ( | ||
masterURL string | ||
kubeconfigPath string | ||
repositoryName string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "snapshots [snapshotID ...]", | ||
Short: "Get snapshots of restic repo", | ||
DisableAutoGenTag: true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath) | ||
if err != nil { | ||
fmt.Errorf(err.Error()) | ||
} | ||
|
||
stashClient := cs.NewForConfigOrDie(config) | ||
|
||
if repositoryName == "" { | ||
fmt.Errorf("repository name not found") | ||
return | ||
} | ||
repo, err := stashClient.Repositories(meta.Namespace()).Get(repositoryName, metav1.GetOptions{}) | ||
if err != nil { | ||
fmt.Errorf(err.Error()) | ||
return | ||
} | ||
|
||
r := snapshot.NewREST(config) | ||
snapshots, err := r.GetSnapshots(repo, args) | ||
if err != nil { | ||
fmt.Errorf(err.Error()) | ||
} | ||
jsonSnaps, err := json.MarshalIndent(snapshots, "", " ") | ||
fmt.Println(string(jsonSnaps)) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&masterURL, "master", masterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)") | ||
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).") | ||
cmd.Flags().StringVar(&repositoryName, "repo-name", repositoryName, "Name of the Repository CRD.") | ||
|
||
return cmd | ||
} |
This file was deleted.
Oops, something went wrong.