Skip to content

Regional PD Implementation [Removing parameter "zone"] #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2018
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
5 changes: 4 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func init() {
var (
endpoint = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")
driverName = flag.String("drivername", "com.google.csi.gcepd", "name of the driver")
nodeID = flag.String("nodeid", "", "node id")
vendorVersion string
)

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

gceDriver := driver.GetGCEDriver()

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

err = gceDriver.SetupGCEDriver(cloudProvider, mounter, deviceUtils, ms, *driverName, *nodeID, vendorVersion)
err = gceDriver.SetupGCEDriver(cloudProvider, mounter, deviceUtils, ms, *driverName, vendorVersion)
if err != nil {
glog.Fatalf("Failed to initialize GCE CSI Driver: %v", err)
}
Expand Down
5 changes: 0 additions & 5 deletions deploy/kubernetes/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ spec:
args:
- "--v=5"
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(KUBE_NODE_NAME)"
env:
- name: CSI_ENDPOINT
value: unix:/csi/csi.sock
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: GOOGLE_APPLICATION_CREDENTIALS
value: "/etc/cloud-sa/cloud-sa.json"
volumeMounts:
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes/delete-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes"

kubectl delete -f "${KUBEDEPLOY}/node.yaml" --ignore-not-found
kubectl delete -f "${KUBEDEPLOY}/controller.yaml" --ignore-not-found
kubectl delete -f "${KUBEDEPLOY}/zonal-sc.yaml" --ignore-not-found
kubectl delete -f "${KUBEDEPLOY}/regional-sc.yaml" --ignore-not-found
kubectl delete -f "${KUBEDEPLOY}/setup-cluster.yaml" --ignore-not-found
kubectl delete secret cloud-sa --ignore-not-found
1 change: 1 addition & 0 deletions deploy/kubernetes/deploy-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ then
fi

kubectl apply -f "${KUBEDEPLOY}/setup-cluster.yaml"
kubectl apply -f "${KUBEDEPLOY}/zonal-sc.yaml"
kubectl apply -f "${KUBEDEPLOY}/node.yaml"
kubectl apply -f "${KUBEDEPLOY}/controller.yaml"
5 changes: 0 additions & 5 deletions deploy/kubernetes/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ spec:
args:
- "--v=5"
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(KUBE_NODE_NAME)"
env:
- name: CSI_ENDPOINT
value: unix:/csi/csi.sock
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: kubelet-dir
mountPath: /var/lib/kubelet
Expand Down
9 changes: 9 additions & 0 deletions deploy/kubernetes/regional-sc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: csi-gce-pd
provisioner: csi-gce-pd
parameters:
type: pd-standard
replication-type: regional-pd
volumeBindingMode: Immediate
11 changes: 0 additions & 11 deletions deploy/kubernetes/setup-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: csi-gce-pd
provisioner: csi-gce-pd
parameters:
type: pd-standard
volumeBindingMode: Immediate

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down
8 changes: 8 additions & 0 deletions deploy/kubernetes/zonal-sc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: csi-gce-pd
provisioner: csi-gce-pd
parameters:
type: pd-standard
volumeBindingMode: Immediate
4 changes: 2 additions & 2 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package common

const (
// Keys for Storage Class Parameters
ParameterKeyZone = "zone"
ParameterKeyType = "type"
ParameterKeyType = "type"
ParameterKeyReplicationType = "replication-type"

// Keys for Topology. This key will be shared amonst drivers from GCP
TopologyKeyZone = "com.google.topology/zone"
Expand Down
60 changes: 54 additions & 6 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ package common
import (
"fmt"
"strings"

"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)

const (
// Volume ID Expected Format
// "projects/{projectName}/zones/{zoneName}/disks/{diskName}"
// "projects/{projectName}/regions/{regionName}/disks/{diskName}"
volIDToplogyKey = 2
volIDToplogyValue = 3
volIDDiskNameValue = 5
volIDTotalElements = 6

// Node ID Expected Format
// "{zoneName}/{instanceName}"
nodeIDZoneValue = 0
nodeIDNameValue = 1
nodeIDTotalElements = 2
)

func BytesToGb(bytes int64) int64 {
Expand All @@ -31,14 +50,43 @@ func GbToBytes(Gb int64) int64 {
return Gb * 1024 * 1024 * 1024
}

func SplitZoneNameId(id string) (string, string, error) {
func VolumeIDToKey(id string) (*meta.Key, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests?

splitId := strings.Split(id, "/")
if len(splitId) != volIDTotalElements {
return nil, fmt.Errorf("failed to get id components. Expected projects/{project}/zones/{zone}/disks/{name}. Got: %s", id)
}
if splitId[volIDToplogyKey] == "zones" {
return meta.ZonalKey(splitId[volIDDiskNameValue], splitId[volIDToplogyValue]), nil
} else if splitId[volIDToplogyKey] == "regions" {
return meta.RegionalKey(splitId[volIDDiskNameValue], splitId[volIDToplogyValue]), nil
} else {
return nil, fmt.Errorf("could not get id components, expected either zones or regions, got: %v", splitId[volIDToplogyKey])
}
}

func NodeIDToZoneAndName(id string) (string, string, error) {
splitId := strings.Split(id, "/")
if len(splitId) != 2 {
return "", "", fmt.Errorf("Failed to get id components. Expected {zone}/{name}. Got: %s", id)
if len(splitId) != nodeIDTotalElements {
return "", "", fmt.Errorf("failed to get id components. expected {zone}/{name}. Got: %s", id)
}
return splitId[0], splitId[1], nil
return splitId[nodeIDZoneValue], splitId[nodeIDNameValue], nil
}

func CombineVolumeId(zone, name string) string {
return fmt.Sprintf("%s/%s", zone, name)
func GetRegionFromZones(zones []string) (string, error) {
regions := sets.String{}
if len(zones) < 1 {
return "", fmt.Errorf("no zones specified")
}
for _, zone := range zones {
// Zone expected format {locale}-{region}-{zone}
splitZone := strings.Split(zone, "-")
if len(splitZone) != 3 {
return "", fmt.Errorf("zone in unexpected format, expected: {locale}-{region}-{zone}, got: %v", zone)
}
regions.Insert(strings.Join(splitZone[0:2], "-"))
}
if regions.Len() != 1 {
return "", fmt.Errorf("multiple or no regions gotten from zones, got: %v", regions)
}
return regions.UnsortedList()[0], nil
}
Loading