Skip to content

Commit cac62af

Browse files
author
Shlok Chaudhari
committed
Removing storage class flag
1 parent bc2aa21 commit cac62af

6 files changed

+132
-226
lines changed

cmd/rootCmd.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ var (
118118
RunE: func(cmd *cobra.Command, args []string) error {
119119
return CsiSnapshotBrowse(context.Background(), args[0],
120120
namespace,
121-
storageClass,
122121
csiCheckRunAsUser,
123122
browseLocalPort,
124123
)
@@ -202,8 +201,6 @@ func init() {
202201
_ = browsePvcCmd.MarkFlagRequired("volumesnapshotclass")
203202

204203
browseCmd.AddCommand(browseSnapshotCmd)
205-
browseSnapshotCmd.Flags().StringVarP(&storageClass, "storageclass", "s", "", "The name of a StorageClass. (Required)")
206-
_ = browseSnapshotCmd.MarkFlagRequired("storageclass")
207204

208205
rootCmd.AddCommand(blockMountCmd)
209206
blockMountCmd.Flags().StringVarP(&storageClass, "storageclass", "s", "", "The name of a StorageClass. (Required)")
@@ -395,7 +392,6 @@ func CsiPvcBrowse(ctx context.Context,
395392
func CsiSnapshotBrowse(ctx context.Context,
396393
snapshotName string,
397394
namespace string,
398-
storageClass string,
399395
runAsUser int64,
400396
localPort int,
401397
) error {
@@ -414,11 +410,10 @@ func CsiSnapshotBrowse(ctx context.Context,
414410
DynCli: dyncli,
415411
}
416412
err = browseRunner.RunSnapshotBrowse(ctx, &csitypes.SnapshotBrowseArgs{
417-
SnapshotName: snapshotName,
418-
Namespace: namespace,
419-
StorageClassName: storageClass,
420-
RunAsUser: runAsUser,
421-
LocalPort: localPort,
413+
SnapshotName: snapshotName,
414+
Namespace: namespace,
415+
RunAsUser: runAsUser,
416+
LocalPort: localPort,
422417
})
423418
if err != nil {
424419
fmt.Printf("Failed to run Snapshot browser (%s)\n", err.Error())

pkg/csi/mocks/mock_snapshot_browser_stepper.go

+5-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/csi/snapshot_inspector.go

+20-33
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,12 @@ func (r *SnapshotBrowseRunner) RunSnapshotBrowseHelper(ctx context.Context, args
6262
return fmt.Errorf("cli uninitialized")
6363
}
6464

65-
sc, err := r.browserSteps.ValidateArgs(ctx, args)
66-
if err != nil {
67-
return errors.Wrap(err, "Failed to validate arguments.")
68-
}
69-
7065
fmt.Println("Fetching the snapshot.")
71-
r.snapshot, err = r.browserSteps.FetchVS(ctx, args)
66+
vs, sc, err := r.browserSteps.ValidateArgs(ctx, args)
7267
if err != nil {
73-
return errors.Wrap(err, "Failed to fetch VolumeSnapshot.")
68+
return errors.Wrap(err, "Failed to validate arguments.")
7469
}
70+
r.snapshot = vs
7571

7672
fmt.Println("Creating the file browser application.")
7773
r.pod, r.pvc, err = r.browserSteps.CreateInspectorApplication(ctx, args, r.snapshot, sc)
@@ -90,8 +86,7 @@ func (r *SnapshotBrowseRunner) RunSnapshotBrowseHelper(ctx context.Context, args
9086

9187
//go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_snapshot_browser_stepper.go -package=mocks . SnapshotBrowserStepper
9288
type SnapshotBrowserStepper interface {
93-
ValidateArgs(ctx context.Context, args *types.SnapshotBrowseArgs) (*sv1.StorageClass, error)
94-
FetchVS(ctx context.Context, args *types.SnapshotBrowseArgs) (*snapv1.VolumeSnapshot, error)
89+
ValidateArgs(ctx context.Context, args *types.SnapshotBrowseArgs) (*snapv1.VolumeSnapshot, *sv1.StorageClass, error)
9590
CreateInspectorApplication(ctx context.Context, args *types.SnapshotBrowseArgs, snapshot *snapv1.VolumeSnapshot, storageClass *sv1.StorageClass) (*v1.Pod, *v1.PersistentVolumeClaim, error)
9691
PortForwardAPod(ctx context.Context, pod *v1.Pod, localPort int) error
9792
Cleanup(ctx context.Context, pvc *v1.PersistentVolumeClaim, pod *v1.Pod)
@@ -107,47 +102,39 @@ type snapshotBrowserSteps struct {
107102
SnapshotGroupVersion *metav1.GroupVersionForDiscovery
108103
}
109104

110-
func (s *snapshotBrowserSteps) ValidateArgs(ctx context.Context, args *types.SnapshotBrowseArgs) (*sv1.StorageClass, error) {
105+
func (s *snapshotBrowserSteps) ValidateArgs(ctx context.Context, args *types.SnapshotBrowseArgs) (*snapv1.VolumeSnapshot, *sv1.StorageClass, error) {
111106
if err := args.Validate(); err != nil {
112-
return nil, errors.Wrap(err, "Failed to validate input arguments")
107+
return nil, nil, errors.Wrap(err, "Failed to validate input arguments")
113108
}
114109
if err := s.validateOps.ValidateNamespace(ctx, args.Namespace); err != nil {
115-
return nil, errors.Wrap(err, "Failed to validate Namespace")
116-
}
117-
sc, err := s.validateOps.ValidateStorageClass(ctx, args.StorageClassName)
118-
if err != nil {
119-
return nil, errors.Wrap(err, "Failed to validate SC")
110+
return nil, nil, errors.Wrap(err, "Failed to validate Namespace")
120111
}
121112
groupVersion, err := s.versionFetchOps.GetCSISnapshotGroupVersion()
122113
if err != nil {
123-
return nil, errors.Wrap(err, "Failed to fetch groupVersion")
114+
return nil, nil, errors.Wrap(err, "Failed to fetch groupVersion")
124115
}
125116
s.SnapshotGroupVersion = groupVersion
126117
snapshot, err := s.validateOps.ValidateVolumeSnapshot(ctx, args.SnapshotName, args.Namespace, groupVersion)
127118
if err != nil {
128-
return nil, errors.Wrap(err, "Failed to validate VolumeSnapshot")
119+
return nil, nil, errors.Wrap(err, "Failed to validate VolumeSnapshot")
129120
}
130-
uVSC, err := s.validateOps.ValidateVolumeSnapshotClass(ctx, *snapshot.Spec.VolumeSnapshotClassName, groupVersion)
121+
pvc, err := s.validateOps.ValidatePVC(ctx, *snapshot.Spec.Source.PersistentVolumeClaimName, args.Namespace)
131122
if err != nil {
132-
return nil, errors.Wrap(err, "Failed to validate VolumeSnapshotClass")
123+
return nil, nil, errors.Wrap(err, "Failed to validate source PVC")
133124
}
134-
vscDriver := getDriverNameFromUVSC(*uVSC, groupVersion.GroupVersion)
135-
if sc.Provisioner != vscDriver {
136-
return nil, fmt.Errorf("StorageClass provisioner (%s) and VolumeSnapshotClass driver (%s) are different.", sc.Provisioner, vscDriver)
125+
sc, err := s.validateOps.ValidateStorageClass(ctx, *pvc.Spec.StorageClassName)
126+
if err != nil {
127+
return nil, nil, errors.Wrap(err, "Failed to validate SC")
137128
}
138-
return sc, nil
139-
}
140-
141-
func (s *snapshotBrowserSteps) FetchVS(ctx context.Context, args *types.SnapshotBrowseArgs) (*snapv1.VolumeSnapshot, error) {
142-
snapshotter, err := s.snapshotFetchOps.NewSnapshotter()
129+
uVSC, err := s.validateOps.ValidateVolumeSnapshotClass(ctx, *snapshot.Spec.VolumeSnapshotClassName, groupVersion)
143130
if err != nil {
144-
return nil, errors.Wrap(err, "Failed to load snapshotter")
131+
return nil, nil, errors.Wrap(err, "Failed to validate VolumeSnapshotClass")
145132
}
146-
snapArgs := &types.FetchSnapshotArgs{
147-
Namespace: args.Namespace,
148-
SnapshotName: args.SnapshotName,
133+
vscDriver := getDriverNameFromUVSC(*uVSC, groupVersion.GroupVersion)
134+
if sc.Provisioner != vscDriver {
135+
return nil, nil, fmt.Errorf("StorageClass provisioner (%s) and VolumeSnapshotClass driver (%s) are different.", sc.Provisioner, vscDriver)
149136
}
150-
return s.snapshotFetchOps.GetVolumeSnapshot(ctx, snapshotter, snapArgs)
137+
return snapshot, sc, nil
151138
}
152139

153140
func (s *snapshotBrowserSteps) CreateInspectorApplication(ctx context.Context, args *types.SnapshotBrowseArgs, snapshot *snapv1.VolumeSnapshot, storageClass *sv1.StorageClass) (*v1.Pod, *v1.PersistentVolumeClaim, error) {

0 commit comments

Comments
 (0)