Skip to content

Commit 56ce990

Browse files
committed
Makefile s/gce/gce-pd, added TODO, changed metadata.Zone() call, added
some rudimentary node call locking, changed volume size representations, removed dummy service from statefulset definition.
1 parent 9c3112c commit 56ce990

File tree

6 files changed

+35
-45
lines changed

6 files changed

+35
-45
lines changed

Makefile

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
STAGINGIMAGE=gcr.io/dyzz-csi-staging/csi/gce-driver
15+
STAGINGIMAGE=gcr.io/dyzz-csi-staging/csi/gce-pd-driver
1616
STAGINGVERSION=latest
1717

1818
PRODIMAGE=gcr.io/google-containers/volume-csi/compute-persistent-disk-csi-driver
1919
PRODVERSION=v0.2.0.alpha
20-
all: gce-driver
20+
all: gce-pd-driver
2121

22-
gce-driver:
22+
gce-pd-driver:
2323
mkdir -p bin
24-
go build -o bin/gce-csi-driver ./cmd/
25-
go build -o bin/gce-csi-driver-test ./test/e2e/
24+
go build -o bin/gce-pd-csi-driver ./cmd/
25+
go build -o bin/gce-pd-csi-driver-test ./test/e2e/
2626

27-
build-container: gce-driver
28-
cp bin/gce-csi-driver deploy/docker
27+
build-container: gce-pd-driver
28+
cp bin/gce-pd-csi-driver deploy/docker
2929
docker build -t $(STAGINGIMAGE):$(STAGINGVERSION) deploy/docker
3030

3131
push-container: build-container
3232
gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION)
3333

34-
prod-build-container: gce-driver
35-
cp bin/gce-csi-driver deploy/docker
34+
prod-build-container: gce-pd-driver
35+
cp bin/gce-pd-csi-driver deploy/docker
3636
docker build -t $(PRODIMAGE):$(PRODVERSION) deploy/docker
3737

3838
prod-push-container: prod-build-container
3939
gcloud docker -- push $(PRODIMAGE):$(PRODVERSION)
4040

41-
test-sanity: gce-driver
41+
test-sanity: gce-pd-driver
4242
go test -timeout 30s github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/pkg/test -run ^TestSanity$

deploy/kubernetes/controller.yaml

-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
# The dummy service is required for creating a StatefulSet
2-
kind: Service
3-
apiVersion: v1
4-
metadata:
5-
name: csi-gce-pd
6-
labels:
7-
app: csi-gce-pd
8-
spec:
9-
selector:
10-
app: csi-gce-pd
11-
ports:
12-
- name: dummy
13-
port: 12345
14-
15-
---
16-
171
kind: StatefulSet
182
apiVersion: apps/v1beta1
193
metadata:

pkg/gce-cloud-provider/gce.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"net/http"
2020
"os"
2121
"runtime"
22-
"strings"
2322
"time"
2423

2524
"cloud.google.com/go/compute/metadata"
@@ -80,6 +79,7 @@ func createCloudServiceWithDefaultServiceAccount() (*compute.Service, error) {
8079
if err != nil {
8180
return nil, err
8281
}
82+
// TODO(dyzz) parameterize version number
8383
service.UserAgent = fmt.Sprintf("GCE CSI Driver/%s (%s %s)", "0.2.0", runtime.GOOS, runtime.GOARCH)
8484
return service, nil
8585
}
@@ -114,15 +114,10 @@ func newDefaultOauthClient() (*http.Client, error) {
114114
}
115115

116116
func getProjectAndZoneFromMetadata() (string, string, error) {
117-
result, err := metadata.Get("instance/zone")
117+
zone, err := metadata.Zone()
118118
if err != nil {
119119
return "", "", err
120120
}
121-
parts := strings.Split(result, "/")
122-
if len(parts) != 4 {
123-
return "", "", fmt.Errorf("unexpected response: %s", result)
124-
}
125-
zone := parts[3]
126121
projectID, err := metadata.ProjectID()
127122
if err != nil {
128123
return "", "", err

pkg/gce-csi-driver/controller.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ type GCEControllerServer struct {
3838
}
3939

4040
const (
41-
// MaxVolumeSize is the maximum standard and ssd size of 64TB
42-
MaxVolumeSize int64 = 64000000000000
43-
DefaultVolumeSize int64 = 5000000000
44-
MinimumDiskSizeInGb = 5
41+
// MaxVolumeSizeInBytes is the maximum standard and ssd size of 64TB
42+
MaxVolumeSizeInBytes int64 = 64 * 1024 * 1024 * 1024 * 1024
43+
MinimumVolumeSizeInBytes int64 = 5 * 1024 * 1024 * 1024
44+
MinimumDiskSizeInGb = 5
4545

4646
DiskTypeSSD = "pd-ssd"
4747
DiskTypeStandard = "pd-standard"
4848
diskTypeDefault = DiskTypeStandard
4949

50-
diskTypePersistent = "PERSISTENT"
50+
attachableDiskTypePersistent = "PERSISTENT"
5151
)
5252

5353
func getRequestCapacity(capRange *csi.CapacityRange) (capBytes int64) {
5454
// TODO: Take another look at these casts/caps. Make sure this func is correct
5555
if capRange == nil {
56-
capBytes = DefaultVolumeSize
56+
capBytes = MinimumVolumeSizeInBytes
5757
return
5858
}
5959

@@ -63,8 +63,8 @@ func getRequestCapacity(capRange *csi.CapacityRange) (capBytes int64) {
6363
capBytes = tcap
6464
}
6565
// Too small, default
66-
if capBytes < DefaultVolumeSize {
67-
capBytes = DefaultVolumeSize
66+
if capBytes < MinimumVolumeSizeInBytes {
67+
capBytes = MinimumVolumeSizeInBytes
6868
}
6969
return
7070
}
@@ -185,7 +185,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
185185

186186
func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
187187
// TODO: Only allow deletion of volumes that were created by the driver
188-
// Assuming ID is of form {project}/{zone}/{id}
188+
// Assuming ID is of form {zone}/{id}
189189
glog.Infof("DeleteVolume called with request %v", *req)
190190

191191
// Validate arguments
@@ -282,7 +282,7 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
282282
Kind: disk.Kind,
283283
Mode: readWrite,
284284
Source: source,
285-
Type: diskTypePersistent,
285+
Type: attachableDiskTypePersistent,
286286
}
287287

288288
glog.Infof("Attaching disk %#v to instance %v", attachedDiskV1, nodeID)

pkg/gce-csi-driver/controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestCreateVolumeArguments(t *testing.T) {
9393
Parameters: stdParams,
9494
},
9595
expVol: &csi.Volume{
96-
CapacityBytes: DefaultVolumeSize,
96+
CapacityBytes: MinimumVolumeSizeInBytes,
9797
Id: project + "/" + zone + "/" + "test-vol",
9898
Attributes: nil,
9999
},
@@ -177,7 +177,7 @@ func TestCreateVolumeArguments(t *testing.T) {
177177
Parameters: stdParams,
178178
},
179179
expVol: &csi.Volume{
180-
CapacityBytes: DefaultVolumeSize,
180+
CapacityBytes: MinimumVolumeSizeInBytes,
181181
Id: project + "/" + zone + "/" + "test-vol",
182182
Attributes: nil,
183183
},

pkg/gce-csi-driver/node.go

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package gceGCEDriver
1717
import (
1818
"fmt"
1919
"os"
20+
"sync"
2021

2122
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
2223
"github.com/golang/glog"
@@ -30,9 +31,13 @@ import (
3031
type GCENodeServer struct {
3132
Driver *GCEDriver
3233
Mounter mountmanager.Mounter
34+
// TODO: Only lock mutually exclusive calls and make locking more fine grained
35+
mux sync.Mutex
3336
}
3437

3538
func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
39+
ns.mux.Lock()
40+
defer ns.mux.Unlock()
3641
glog.Infof("NodePublishVolume called with req: %#v", req)
3742

3843
// Validate Arguments
@@ -108,6 +113,8 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
108113
}
109114

110115
func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
116+
ns.mux.Lock()
117+
defer ns.mux.Unlock()
111118
glog.Infof("NodeUnpublishVolume called with args: %v", req)
112119
// Validate Arguments
113120
targetPath := req.GetTargetPath()
@@ -130,6 +137,8 @@ func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeU
130137
}
131138

132139
func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
140+
ns.mux.Lock()
141+
defer ns.mux.Unlock()
133142
glog.Infof("NodeStageVolume called with req: %#v", req)
134143

135144
// Validate Arguments
@@ -218,6 +227,8 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
218227
}
219228

220229
func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
230+
ns.mux.Lock()
231+
defer ns.mux.Unlock()
221232
glog.Infof("NodeUnstageVolume called with req: %#v", req)
222233
// Validate arguments
223234
volumeID := req.GetVolumeId()

0 commit comments

Comments
 (0)