Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We have full documentation on how to get started contributing here:

- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
- [Contributor Cheat Sheet](https://github.com/kubernetes/community/blob/master/contributors/guide/contributor-cheatsheet/README.md) - Common resources for existing developers

## Mentorship

Expand Down
8 changes: 8 additions & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type CSICreds struct {
CreateSnapshotSecret string
DeleteSnapshotSecret string
ControllerValidateVolumeCapabilitiesSecret string
ListSnapshotsSecret string
}

type CSIDriver struct {
Expand Down Expand Up @@ -184,6 +185,7 @@ func setDefaultCreds(creds *CSICreds) {
CreateSnapshotSecret: "secretval7",
DeleteSnapshotSecret: "secretval8",
ControllerValidateVolumeCapabilitiesSecret: "secretval9",
ListSnapshotsSecret: "secretval10",
}
}

Expand Down Expand Up @@ -262,6 +264,8 @@ func isAuthenticated(req interface{}, creds *CSICreds) (bool, error) {
return authenticateDeleteSnapshot(r, creds)
case *csi.ValidateVolumeCapabilitiesRequest:
return authenticateControllerValidateVolumeCapabilities(r, creds)
case *csi.ListSnapshotsRequest:
return authenticateListSnapshots(r, creds)
default:
return true, nil
}
Expand Down Expand Up @@ -303,6 +307,10 @@ func authenticateControllerValidateVolumeCapabilities(req *csi.ValidateVolumeCap
return credsCheck(req.GetSecrets(), creds.ControllerValidateVolumeCapabilitiesSecret)
}

func authenticateListSnapshots(req *csi.ListSnapshotsRequest, creds *CSICreds) (bool, error) {
return credsCheck(req.GetSecrets(), creds.ListSnapshotsSecret)
}

func credsCheck(secrets map[string]string, secretVal string) (bool, error) {
if len(secrets) == 0 {
return false, ErrNoCredentials
Expand Down
114 changes: 76 additions & 38 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
})

It("should return appropriate values (no optional values added)", func() {
snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{})

req := &csi.ListSnapshotsRequest{}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())

Expand Down Expand Up @@ -1145,9 +1150,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated2")

By("listing snapshots")
snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{SnapshotId: snapshotTarget.GetSnapshot().GetSnapshotId()})

req := &csi.ListSnapshotsRequest{SnapshotId: snapshotTarget.GetSnapshot().GetSnapshotId()}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(HaveLen(1))
Expand All @@ -1157,9 +1167,13 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext

It("should return empty when the specified snapshot id does not exist", func() {

snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{SnapshotId: "none-exist-id"})
req := &csi.ListSnapshotsRequest{SnapshotId: "none-exist-id"}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(BeEmpty())
Expand Down Expand Up @@ -1187,9 +1201,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated2")

By("listing snapshots")
snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{SourceVolumeId: snapshotTarget.GetSnapshot().GetSourceVolumeId()})

req := &csi.ListSnapshotsRequest{SourceVolumeId: snapshotTarget.GetSnapshot().GetSourceVolumeId()}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(HaveLen(1))
Expand All @@ -1200,19 +1219,28 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext

It("should return empty when the specified source volume id does not exist", func() {

snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{SourceVolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID()})
req := &csi.ListSnapshotsRequest{SourceVolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID()}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(BeEmpty())
})

It("check the presence of new snapshots in the snapshot list", func() {
// List Snapshots before creating new snapshots.
snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{})

req := &csi.ListSnapshotsRequest{}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())

Expand All @@ -1223,21 +1251,21 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
snapshot, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-3")
verifySnapshotInfo(snapshot.GetSnapshot())

snapshots, err = r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{})
snapshots, err = r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(HaveLen(totalSnapshots + 1))

By("deleting the snapshot")
_, err = r.DeleteSnapshot(context.Background(), &csi.DeleteSnapshotRequest{SnapshotId: snapshot.Snapshot.SnapshotId})
dreq := &csi.DeleteSnapshotRequest{SnapshotId: snapshot.Snapshot.SnapshotId}
if sc.Secrets != nil {
dreq.Secrets = sc.Secrets.DeleteSnapshotSecret
}
_, err = r.DeleteSnapshot(context.Background(), dreq)
Expect(err).NotTo(HaveOccurred())

By("checking if deleted snapshot is omitted")
snapshots, err = r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{})
snapshots, err = r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())
Expect(snapshots.GetEntries()).To(HaveLen(totalSnapshots))
Expand All @@ -1253,10 +1281,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
// is used to verify that all the snapshots have been listed.
currentTotalSnapshots := 0

req := &csi.ListSnapshotsRequest{}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

// Get the number of existing volumes.
snapshots, err := r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{})
snapshots, err := r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())

Expand All @@ -1280,11 +1312,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
}

// Request list snapshots with max entries maxEntries.
snapshots, err = r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{
MaxEntries: int32(maxEntries),
})

req = &csi.ListSnapshotsRequest{MaxEntries: int32(maxEntries)}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err = r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())

Expand All @@ -1293,11 +1328,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
Expect(snapshots.GetEntries()).To(HaveLen(maxEntries))

// Request list snapshots with starting_token and no max entries.
snapshots, err = r.ListSnapshots(
context.Background(),
&csi.ListSnapshotsRequest{
StartingToken: nextToken,
})

req = &csi.ListSnapshotsRequest{StartingToken: nextToken}

if sc.Secrets != nil {
req.Secrets = sc.Secrets.ListSnapshotsSecret
}

snapshots, err = r.ListSnapshots(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(snapshots).NotTo(BeNil())

Expand Down
1 change: 1 addition & 0 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type CSISecrets struct {
CreateSnapshotSecret map[string]string `yaml:"CreateSnapshotSecret"`
DeleteSnapshotSecret map[string]string `yaml:"DeleteSnapshotSecret"`
ControllerExpandVolumeSecret map[string]string `yaml:"ControllerExpandVolumeSecret"`
ListSnapshotsSecret map[string]string `yaml:"ListSnapshotsSecret"`
}

// TestConfig provides the configuration for the sanity tests. It must be
Expand Down