Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "./kubestr file-restore" command #287

Merged
merged 62 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
36882b5
Adding the kubestr browse pvc command. Handling kubestr browse suppor…
shlokc9 Jul 24, 2024
0927b25
Adding browse snapshot command. Updating browse command to browse pvc…
shlokc9 Jul 24, 2024
c2d3570
chore(deps): bump github/codeql-action in the github-actions group (#…
dependabot[bot] Jul 22, 2024
b6bf82c
chore(deps): bump docker/build-push-action in the docker group (#273)
dependabot[bot] Jul 22, 2024
32cecd0
Merge branch 'kastenhq:master' into browse-pvc-snapshot
shlokc9 Jul 24, 2024
a6ac177
Adding --show-tree flag for browse snapshot & browse pvc commands
shlokc9 Jul 24, 2024
e2aa023
Removing unused snapshot function parameter in cleanup
shlokc9 Jul 25, 2024
1f10988
Adding KubeExecutor Exec helper function to execute tree command
shlokc9 Jul 26, 2024
34744f6
Adding --show-tree logic in pvc_inspector.go
shlokc9 Jul 26, 2024
cbed58b
Adding --show-tree logic in snapshot_inspector.go
shlokc9 Jul 26, 2024
2f8e255
Printing out the tree structure for --show-tree
shlokc9 Jul 27, 2024
9098f94
Updating mock tests for new code changes
shlokc9 Jul 27, 2024
a0c97b9
Updating mount path in container args for creating a browse pod
shlokc9 Jul 29, 2024
16e29c4
Updating the CSITestSuite.TestCreateInspectorApplication for changes …
shlokc9 Jul 29, 2024
8b44243
Adding Deprecated msg to the 'browse' command
shlokc9 Jul 29, 2024
0bb5fd5
Adding mock tests for SnapshotBrowserStepper
shlokc9 Jul 27, 2024
778b71c
Adding fake tests for snapshot_inspector.go
shlokc9 Jul 29, 2024
b17344a
Renamed testcase CSITestSuite.TestCreateInspectorApplication to TestC…
shlokc9 Jul 29, 2024
f848045
Adding snapshot_inspector_steps_test.go
shlokc9 Jul 29, 2024
78d4981
Updating mock tests for new code changes
shlokc9 Jul 27, 2024
74bd34d
Updating the mount paths in CSITestSuite.TestCreateInspectorApplicati…
shlokc9 Jul 29, 2024
4e160b1
Updating Deprecated msg for 'browse' command
shlokc9 Jul 30, 2024
62af178
Making namespace, runAsUser & localport flags persistent
shlokc9 Jul 31, 2024
dc4a65e
Removing namespace, runAsUser & localport flags for browse snapshot b…
shlokc9 Jul 31, 2024
2d419ec
Adding --show-tree flag for browse snapshot & browse pvc commands
shlokc9 Jul 24, 2024
0314b8e
Updating namespace flag usage for better understanding
shlokc9 Jul 31, 2024
f63aebf
Removing storage class flag
shlokc9 Jul 31, 2024
e0f5dcf
Adding --show-tree logic in snapshot_inspector.go
shlokc9 Jul 26, 2024
d7b492c
Updating mock objects for SnapshotBrowserStepper
shlokc9 Aug 1, 2024
938e625
Adding --show-tree flag for browse snapshot & browse pvc commands
shlokc9 Jul 24, 2024
127e473
Removing storage class flag
shlokc9 Jul 31, 2024
e781e2e
Adding --show-tree flag for browse snapshot & browse pvc commands
shlokc9 Jul 24, 2024
ffd10ad
Adding --show-tree logic in snapshot_inspector.go
shlokc9 Jul 26, 2024
0681429
Passing showTree var as function argument
shlokc9 Aug 1, 2024
c3b76da
Making --show-tree a persistent flag
shlokc9 Aug 1, 2024
f11801d
Removing ShowTree dummy condition
shlokc9 Aug 1, 2024
13f4b25
Adding --show-tree flag for browse snapshot & browse pvc commands
shlokc9 Jul 24, 2024
023ec6c
Making --show-tree a persistent flag
shlokc9 Aug 1, 2024
16bbac4
Adding --show-tree flag for browse snapshot & browse pvc commands
shlokc9 Jul 24, 2024
c7faf68
Making --show-tree a persistent flag
shlokc9 Aug 1, 2024
b13bc79
Adding "./kubestr browse snapshot" command (#277)
shlokc9 Aug 2, 2024
1a1a2fd
Adding --show-tree flag to both "./kubestr browse pvc" & "./kubestr b…
shlokc9 Aug 2, 2024
f1c2578
Removing dummy ShowTree arg test
shlokc9 Aug 2, 2024
d22fcc5
Adding --show-tree flag to both "./kubestr browse pvc" & "./kubestr b…
shlokc9 Aug 2, 2024
dcccafe
chore(deps): bump the github-actions group across 1 directory with 2 …
dependabot[bot] Aug 5, 2024
ba09ef9
chore(deps): bump the docker group across 1 directory with 4 updates …
dependabot[bot] Aug 5, 2024
00b738b
chore(deps): bump ossf/scorecard-action from 2.3.3 to 2.4.0 (#281)
dependabot[bot] Aug 5, 2024
94bbfea
K10-23320: Fix function definition for Create and CreateFromSource (#…
saima-s Aug 5, 2024
acb052e
Updating CreatePodArgs to consume PVC args in []string{} format inste…
shlokc9 Aug 7, 2024
dbbb0f9
Removing placeholder test for browse snapshot and browse pvc
shlokc9 Aug 8, 2024
d6d359b
Removing unused snapshotFetchOps from snapshotBrowserSteps
shlokc9 Aug 9, 2024
f94e6e0
Adding File restore command
shlokc9 Aug 9, 2024
a0eb8e8
Adding mock objects and fake tests for file restore command
shlokc9 Aug 9, 2024
d0dc63e
Renaming file_restore_inspector.go
shlokc9 Aug 9, 2024
c206c79
Merge branch 'master' into file-restore
shlokc9 Aug 9, 2024
21aada5
Removing unused SnapshotFetcher interface
shlokc9 Aug 9, 2024
d498389
Adding check for source PVC in Snapshot and supported accessModes in …
shlokc9 Aug 13, 2024
6ba5cd7
Adding --toPVC flag
shlokc9 Aug 13, 2024
a025986
Fixing seg fault occurred because of the invalid error thrown in acce…
shlokc9 Aug 13, 2024
487ad81
Removing check for ReadWriteOnce accessmode
shlokc9 Aug 14, 2024
b3dcb80
Merge branch 'master' into file-restore
shlokc9 Aug 15, 2024
dab6718
Update cmd/rootCmd.go
shlokc9 Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions cmd/rootCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ var (
},
}

fromSnapshot string
toPVC string
path string
restoreFileCmd = &cobra.Command{
Use: "file-restore",
Short: "Restore file(s) from a VolumeSnapshot to it's source PVC",
Long: "Restore file(s) from a given CSI provisioned VolumeSnapshot to a PVC.",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return FileRestore(context.Background(),
fromSnapshot,
toPVC,
namespace,
csiCheckRunAsUser,
browseLocalPort,
path)
},
}

blockMountRunAsUser int64
blockMountCleanup bool
blockMountCleanupOnly bool
Expand Down Expand Up @@ -207,6 +226,15 @@ func init() {

browseCmd.AddCommand(browseSnapshotCmd)

rootCmd.AddCommand(restoreFileCmd)
restoreFileCmd.Flags().StringVarP(&fromSnapshot, "fromSnapshot", "f", "", "The name of a VolumeSnapshot. (Required)")
_ = restoreFileCmd.MarkFlagRequired("fromSnapshot")
restoreFileCmd.Flags().StringVarP(&toPVC, "toPVC", "t", "", "The name of a PersistentVolumeClaim.")
restoreFileCmd.Flags().StringVarP(&namespace, "namespace", "n", fio.DefaultNS, "The namespace of both the given PVC & VS.")
restoreFileCmd.Flags().Int64VarP(&csiCheckRunAsUser, "runAsUser", "u", 0, "Runs the inspector pod as a user (int)")
restoreFileCmd.Flags().IntVarP(&browseLocalPort, "localport", "l", 8080, "The local port to expose the inspector")
restoreFileCmd.Flags().StringVarP(&path, "path", "p", "", "Path of a file or directory that needs to be restored")

rootCmd.AddCommand(blockMountCmd)
blockMountCmd.Flags().StringVarP(&storageClass, "storageclass", "s", "", "The name of a StorageClass. (Required)")
_ = blockMountCmd.MarkFlagRequired("storageclass")
Expand Down Expand Up @@ -430,6 +458,42 @@ func CsiSnapshotBrowse(ctx context.Context,
return err
}

func FileRestore(ctx context.Context,
snapshotName string,
pvcName string,
namespace string,
runAsUser int64,
localPort int,
path string,
) error {
kubecli, err := kubestr.LoadKubeCli()
if err != nil {
fmt.Printf("Failed to load kubeCli (%s)", err.Error())
return err
}
dyncli, err := kubestr.LoadDynCli()
if err != nil {
fmt.Printf("Failed to load dynCli (%s)", err.Error())
return err
}
fileRestoreRunner := &csi.FileRestoreRunner{
KubeCli: kubecli,
DynCli: dyncli,
}
err = fileRestoreRunner.RunFileRestore(ctx, &csitypes.FileRestoreArgs{
SnapshotName: snapshotName,
PVCName: pvcName,
Namespace: namespace,
RunAsUser: runAsUser,
LocalPort: localPort,
Path: path,
})
if err != nil {
fmt.Printf("Failed to run file-restore (%s)\n", err.Error())
}
return err
}

func BlockMountCheck(ctx context.Context, output, outfile string, cleanupOnly bool, checkerArgs block.BlockMountCheckerArgs) error {
kubecli, err := kubestr.LoadKubeCli()
if err != nil {
Expand Down
35 changes: 0 additions & 35 deletions pkg/csi/csi_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,41 +332,6 @@ func (c *applicationCreate) getErrorFromEvents(ctx context.Context, namespace, n
return nil
}

//go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_snapshot_fetcher.go -package=mocks . SnapshotFetcher
type SnapshotFetcher interface {
NewSnapshotter() (kansnapshot.Snapshotter, error)
GetVolumeSnapshot(ctx context.Context, snapshotter kansnapshot.Snapshotter, args *types.FetchSnapshotArgs) (*snapv1.VolumeSnapshot, error)
}

type snapshotFetch struct {
kubeCli kubernetes.Interface
dynCli dynamic.Interface
}

func (f *snapshotFetch) NewSnapshotter() (kansnapshot.Snapshotter, error) {
if f.kubeCli == nil {
return nil, fmt.Errorf("kubeCli not initialized")
}
if f.dynCli == nil {
return nil, fmt.Errorf("dynCli not initialized")
}
return kansnapshot.NewSnapshotter(f.kubeCli, f.dynCli)
}

func (f *snapshotFetch) GetVolumeSnapshot(ctx context.Context, snapshotter kansnapshot.Snapshotter, args *types.FetchSnapshotArgs) (*snapv1.VolumeSnapshot, error) {
if snapshotter == nil || args == nil {
return nil, fmt.Errorf("snapshotter or args are empty")
}
if err := args.Validate(); err != nil {
return nil, err
}
snap, err := snapshotter.Get(ctx, args.SnapshotName, args.Namespace)
if err != nil {
return nil, errors.Wrapf(err, "Failed to get CSI snapshot (%s) in Namespace (%s)", args.SnapshotName, args.Namespace)
}
return snap, nil
}

//go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_snapshot_creator.go -package=mocks . SnapshotCreator
type SnapshotCreator interface {
NewSnapshotter() (kansnapshot.Snapshotter, error)
Expand Down
Loading
Loading