Skip to content

Commit 8b53c4c

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 8b53c4c

File tree

5 files changed

+31
-42
lines changed

5 files changed

+31
-42
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

+9-9
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
}
@@ -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/node.go

+10
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,12 @@ import (
3031
type GCENodeServer struct {
3132
Driver *GCEDriver
3233
Mounter mountmanager.Mounter
34+
mux sync.Mutex
3335
}
3436

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

3842
// Validate Arguments
@@ -108,6 +112,8 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
108112
}
109113

110114
func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
115+
ns.mux.Lock()
116+
defer ns.mux.Unlock()
111117
glog.Infof("NodeUnpublishVolume called with args: %v", req)
112118
// Validate Arguments
113119
targetPath := req.GetTargetPath()
@@ -130,6 +136,8 @@ func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeU
130136
}
131137

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

135143
// Validate Arguments
@@ -218,6 +226,8 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
218226
}
219227

220228
func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
229+
ns.mux.Lock()
230+
defer ns.mux.Unlock()
221231
glog.Infof("NodeUnstageVolume called with req: %#v", req)
222232
// Validate arguments
223233
volumeID := req.GetVolumeId()

0 commit comments

Comments
 (0)