Skip to content

Commit 29bb01d

Browse files
authored
Merge pull request #84 from davidz627/feature/RePDNoParams
Regional PD Implementation [Removing parameter "zone"]
2 parents e3653d9 + 2c284d4 commit 29bb01d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+224737
-525
lines changed

Diff for: Gopkg.lock

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

Diff for: cmd/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func init() {
3535
var (
3636
endpoint = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")
3737
driverName = flag.String("drivername", "com.google.csi.gcepd", "name of the driver")
38-
nodeID = flag.String("nodeid", "", "node id")
3938
vendorVersion string
4039
)
4140

@@ -50,7 +49,7 @@ func handle() {
5049
if vendorVersion == "" {
5150
glog.Fatalf("vendorVersion must be set at compile time")
5251
}
53-
glog.Infof("Driver vendor version %v", vendorVersion)
52+
glog.V(4).Infof("Driver vendor version %v", vendorVersion)
5453

5554
gceDriver := driver.GetGCEDriver()
5655

@@ -68,7 +67,7 @@ func handle() {
6867
glog.Fatalf("Failed to set up metadata service: %v", err)
6968
}
7069

71-
err = gceDriver.SetupGCEDriver(cloudProvider, mounter, deviceUtils, ms, *driverName, *nodeID, vendorVersion)
70+
err = gceDriver.SetupGCEDriver(cloudProvider, mounter, deviceUtils, ms, *driverName, vendorVersion)
7271
if err != nil {
7372
glog.Fatalf("Failed to initialize GCE CSI Driver: %v", err)
7473
}

Diff for: deploy/kubernetes/controller.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ spec:
4646
args:
4747
- "--v=5"
4848
- "--endpoint=$(CSI_ENDPOINT)"
49-
- "--nodeid=$(KUBE_NODE_NAME)"
5049
env:
5150
- name: CSI_ENDPOINT
5251
value: unix:/csi/csi.sock
53-
- name: KUBE_NODE_NAME
54-
valueFrom:
55-
fieldRef:
56-
fieldPath: spec.nodeName
5752
- name: GOOGLE_APPLICATION_CREDENTIALS
5853
value: "/etc/cloud-sa/cloud-sa.json"
5954
volumeMounts:

Diff for: deploy/kubernetes/delete-driver.sh

+2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes"
1111

1212
kubectl delete -f "${KUBEDEPLOY}/node.yaml" --ignore-not-found
1313
kubectl delete -f "${KUBEDEPLOY}/controller.yaml" --ignore-not-found
14+
kubectl delete -f "${KUBEDEPLOY}/zonal-sc.yaml" --ignore-not-found
15+
kubectl delete -f "${KUBEDEPLOY}/regional-sc.yaml" --ignore-not-found
1416
kubectl delete -f "${KUBEDEPLOY}/setup-cluster.yaml" --ignore-not-found
1517
kubectl delete secret cloud-sa --ignore-not-found

Diff for: deploy/kubernetes/deploy-driver.sh

+1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ then
2828
fi
2929

3030
kubectl apply -f "${KUBEDEPLOY}/setup-cluster.yaml"
31+
kubectl apply -f "${KUBEDEPLOY}/zonal-sc.yaml"
3132
kubectl apply -f "${KUBEDEPLOY}/node.yaml"
3233
kubectl apply -f "${KUBEDEPLOY}/controller.yaml"

Diff for: deploy/kubernetes/node.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ spec:
4040
args:
4141
- "--v=5"
4242
- "--endpoint=$(CSI_ENDPOINT)"
43-
- "--nodeid=$(KUBE_NODE_NAME)"
4443
env:
4544
- name: CSI_ENDPOINT
4645
value: unix:/csi/csi.sock
47-
- name: KUBE_NODE_NAME
48-
valueFrom:
49-
fieldRef:
50-
fieldPath: spec.nodeName
5146
volumeMounts:
5247
- name: kubelet-dir
5348
mountPath: /var/lib/kubelet

Diff for: deploy/kubernetes/regional-sc.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: storage.k8s.io/v1beta1
2+
kind: StorageClass
3+
metadata:
4+
name: csi-gce-pd
5+
provisioner: csi-gce-pd
6+
parameters:
7+
type: pd-standard
8+
replication-type: regional-pd
9+
volumeBindingMode: Immediate

Diff for: deploy/kubernetes/setup-cluster.yaml

-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
apiVersion: storage.k8s.io/v1beta1
2-
kind: StorageClass
3-
metadata:
4-
name: csi-gce-pd
5-
provisioner: csi-gce-pd
6-
parameters:
7-
type: pd-standard
8-
volumeBindingMode: Immediate
9-
10-
---
11-
121
kind: ClusterRole
132
apiVersion: rbac.authorization.k8s.io/v1
143
metadata:

Diff for: deploy/kubernetes/zonal-sc.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: storage.k8s.io/v1beta1
2+
kind: StorageClass
3+
metadata:
4+
name: csi-gce-pd
5+
provisioner: csi-gce-pd
6+
parameters:
7+
type: pd-standard
8+
volumeBindingMode: Immediate

Diff for: pkg/common/constants.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package common
1818

1919
const (
2020
// Keys for Storage Class Parameters
21-
ParameterKeyZone = "zone"
22-
ParameterKeyType = "type"
21+
ParameterKeyType = "type"
22+
ParameterKeyReplicationType = "replication-type"
2323

2424
// Keys for Topology. This key will be shared amonst drivers from GCP
2525
TopologyKeyZone = "com.google.topology/zone"

Diff for: pkg/common/utils.go

+54-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ package common
1919
import (
2020
"fmt"
2121
"strings"
22+
23+
"k8s.io/apimachinery/pkg/util/sets"
24+
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
25+
)
26+
27+
const (
28+
// Volume ID Expected Format
29+
// "projects/{projectName}/zones/{zoneName}/disks/{diskName}"
30+
// "projects/{projectName}/regions/{regionName}/disks/{diskName}"
31+
volIDToplogyKey = 2
32+
volIDToplogyValue = 3
33+
volIDDiskNameValue = 5
34+
volIDTotalElements = 6
35+
36+
// Node ID Expected Format
37+
// "{zoneName}/{instanceName}"
38+
nodeIDZoneValue = 0
39+
nodeIDNameValue = 1
40+
nodeIDTotalElements = 2
2241
)
2342

2443
func BytesToGb(bytes int64) int64 {
@@ -31,14 +50,43 @@ func GbToBytes(Gb int64) int64 {
3150
return Gb * 1024 * 1024 * 1024
3251
}
3352

34-
func SplitZoneNameId(id string) (string, string, error) {
53+
func VolumeIDToKey(id string) (*meta.Key, error) {
54+
splitId := strings.Split(id, "/")
55+
if len(splitId) != volIDTotalElements {
56+
return nil, fmt.Errorf("failed to get id components. Expected projects/{project}/zones/{zone}/disks/{name}. Got: %s", id)
57+
}
58+
if splitId[volIDToplogyKey] == "zones" {
59+
return meta.ZonalKey(splitId[volIDDiskNameValue], splitId[volIDToplogyValue]), nil
60+
} else if splitId[volIDToplogyKey] == "regions" {
61+
return meta.RegionalKey(splitId[volIDDiskNameValue], splitId[volIDToplogyValue]), nil
62+
} else {
63+
return nil, fmt.Errorf("could not get id components, expected either zones or regions, got: %v", splitId[volIDToplogyKey])
64+
}
65+
}
66+
67+
func NodeIDToZoneAndName(id string) (string, string, error) {
3568
splitId := strings.Split(id, "/")
36-
if len(splitId) != 2 {
37-
return "", "", fmt.Errorf("Failed to get id components. Expected {zone}/{name}. Got: %s", id)
69+
if len(splitId) != nodeIDTotalElements {
70+
return "", "", fmt.Errorf("failed to get id components. expected {zone}/{name}. Got: %s", id)
3871
}
39-
return splitId[0], splitId[1], nil
72+
return splitId[nodeIDZoneValue], splitId[nodeIDNameValue], nil
4073
}
4174

42-
func CombineVolumeId(zone, name string) string {
43-
return fmt.Sprintf("%s/%s", zone, name)
75+
func GetRegionFromZones(zones []string) (string, error) {
76+
regions := sets.String{}
77+
if len(zones) < 1 {
78+
return "", fmt.Errorf("no zones specified")
79+
}
80+
for _, zone := range zones {
81+
// Zone expected format {locale}-{region}-{zone}
82+
splitZone := strings.Split(zone, "-")
83+
if len(splitZone) != 3 {
84+
return "", fmt.Errorf("zone in unexpected format, expected: {locale}-{region}-{zone}, got: %v", zone)
85+
}
86+
regions.Insert(strings.Join(splitZone[0:2], "-"))
87+
}
88+
if regions.Len() != 1 {
89+
return "", fmt.Errorf("multiple or no regions gotten from zones, got: %v", regions)
90+
}
91+
return regions.UnsortedList()[0], nil
4492
}

0 commit comments

Comments
 (0)