Skip to content

Commit d69f3b2

Browse files
committed
Bump CSI Sanity to latest version and implement the IDGenerator interface for better VolumeID errors
1 parent 3e9b71b commit d69f3b2

File tree

12 files changed

+361
-89
lines changed

12 files changed

+361
-89
lines changed

Gopkg.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
[[constraint]]
4949
name = "github.com/kubernetes-csi/csi-test"
50-
version = "v2.0.1"
50+
version = "2.2.0"
5151

5252
[[constraint]]
5353
branch = "master"

pkg/common/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,7 @@ func GetDeviceName(volKey *meta.Key) (string, error) {
144144
func CreateNodeID(project, zone, name string) string {
145145
return fmt.Sprintf(nodeIDFmt, project, zone, name)
146146
}
147+
148+
func CreateZonalVolumeID(project, zone, name string) string {
149+
return fmt.Sprintf(volIDZonalFmt, project, zone, name)
150+
}

pkg/gce-cloud-provider/compute/fake-gce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (cloud *FakeCloudProvider) ResizeDisk(ctx context.Context, volKey *meta.Key
375375

376376
disk.setSizeGb(common.BytesToGb(requestBytes))
377377

378-
return requestBytes, nil
378+
return common.BytesToGb(requestBytes), nil
379379

380380
}
381381

pkg/gce-pd-csi-driver/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
224224

225225
volKey, err := common.VolumeIDToKey(volumeID)
226226
if err != nil {
227+
// Cannot find volume associated with this ID because VolumeID is not in
228+
// correct format, this is a success according to the Spec
227229
klog.Warningf("Treating volume as deleted because volume id %s is invalid: %v", volumeID, err)
228230
return &csi.DeleteVolumeResponse{}, nil
229231
}

test/sanity/sanity_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import (
2020
"path"
2121
"testing"
2222

23+
"github.com/google/uuid"
24+
2325
sanity "github.com/kubernetes-csi/csi-test/pkg/sanity"
2426
compute "google.golang.org/api/compute/v1"
27+
common "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
2528
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
2629
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
2730
driver "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-pd-csi-driver"
@@ -82,6 +85,37 @@ func TestSanity(t *testing.T) {
8285
TargetPath: mountPath,
8386
StagingPath: stagePath,
8487
Address: endpoint,
88+
IDGen: newPDIDGenerator(project, zone),
8589
}
8690
sanity.Test(t, config)
8791
}
92+
93+
type pdIDGenerator struct {
94+
project string
95+
zone string
96+
}
97+
98+
var _ sanity.IDGenerator = &pdIDGenerator{}
99+
100+
func newPDIDGenerator(project, zone string) *pdIDGenerator {
101+
return &pdIDGenerator{
102+
project: project,
103+
zone: zone,
104+
}
105+
}
106+
107+
func (p pdIDGenerator) GenerateUniqueValidVolumeID() string {
108+
return common.CreateZonalVolumeID(p.project, p.zone, uuid.New().String()[:10])
109+
}
110+
111+
func (p pdIDGenerator) GenerateInvalidVolumeID() string {
112+
return "fake-volid"
113+
}
114+
115+
func (p pdIDGenerator) GenerateUniqueValidNodeID() string {
116+
return common.CreateNodeID(p.project, p.zone, uuid.New().String()[:10])
117+
}
118+
119+
func (p pdIDGenerator) GenerateInvalidNodeID() string {
120+
return "fake-nodeid"
121+
}

vendor/github.com/kubernetes-csi/csi-test/pkg/sanity/cleanup.go

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)