diff --git a/deploy/docker/Dockerfile b/Dockerfile similarity index 59% rename from deploy/docker/Dockerfile rename to Dockerfile index 7b1b8c8bc..1f020acbf 100644 --- a/deploy/docker/Dockerfile +++ b/Dockerfile @@ -12,10 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM fedora:26 +FROM golang:1.10.1-alpine3.7 as builder +WORKDIR /go/src/github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver +ADD . . +RUN CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o bin/gce-pd-csi-driver ./cmd/ -COPY gce-csi-driver /gce-csi-driver +FROM alpine:3.7 +COPY --from=builder /go/src/github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/bin/gce-pd-csi-driver /gce-pd-csi-driver -RUN yum -y install "*/mkfs.ext4" - -ENTRYPOINT ["/gce-csi-driver"] +ENTRYPOINT ["/gce-pd-csi-driver"] \ No newline at end of file diff --git a/Makefile b/Makefile index 5080db7e0..0b48b893c 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -STAGINGIMAGE=gcr.io/dyzz-csi-staging/csi/gce-pd-driver +STAGINGIMAGE=${GCE_PD_CSI_STAGING_IMAGE} STAGINGVERSION=latest PRODIMAGE=gcr.io/google-containers/volume-csi/compute-persistent-disk-csi-driver @@ -25,18 +25,16 @@ gce-pd-driver: go build -o bin/gce-pd-csi-driver-test ./test/e2e/ build-container: gce-pd-driver - cp bin/gce-pd-csi-driver deploy/docker - docker build -t $(STAGINGIMAGE):$(STAGINGVERSION) deploy/docker + docker build -t $(STAGINGIMAGE):$(STAGINGVERSION) . push-container: build-container gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION) prod-build-container: gce-pd-driver - cp bin/gce-pd-csi-driver deploy/docker - docker build -t $(PRODIMAGE):$(PRODVERSION) deploy/docker + docker build -t $(PRODIMAGE):$(PRODVERSION) prod-push-container: prod-build-container gcloud docker -- push $(PRODIMAGE):$(PRODVERSION) test-sanity: gce-pd-driver - go test -timeout 30s github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/pkg/test -run ^TestSanity$ + go test -timeout 30s github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/pkg/test -run ^TestSanity$ \ No newline at end of file diff --git a/README.md b/README.md index b466d7649..9baaf55f5 100644 --- a/README.md +++ b/README.md @@ -10,5 +10,40 @@ Specification compliant driver used by Container Orchestrators to manage the lifecycle of Google Compute Engine Persistent Disks. ## Installing +### Kubernetes Templates and further information for installing this driver on Kubernetes are -in deploy/kubernetes/ \ No newline at end of file +in [`./deploy/kubernetes/README.md`](deployREADME) + +## Development + +###Manual + +Setup [GCP service account first](deployREADME) (one time step) + +To bring up developed drivers: +``` +$ make push-container +$ ./deploy/kubernetes/deploy-driver.sh +``` + +To bring down drivers: +``` +$ ./deploy/kubernetes/delete-driver.sh +``` + +## Testing +Unit tests in `_test` files in the same package as the functions tested. + +Sanity and E2E tests can be found in `./test/` and more detailed testing +information is in [`./test/README.md`](testREADME) + +## Dependency Management +Use [dep](https://github.com/golang/dep) +``` +$ dep ensure +``` + +To modify dependencies or versions change `./Gopkg.toml` + +[deployREADME]: deploy/kubernetes/README.md +[testREADME]: test/README.md \ No newline at end of file diff --git a/deploy/kubernetes/README.md b/deploy/kubernetes/README.md index a9001a04d..f7b930fdf 100644 --- a/deploy/kubernetes/README.md +++ b/deploy/kubernetes/README.md @@ -1,15 +1,18 @@ -Step 1 (Create Credentials): -Create Service Account Credential JSON on GCP: - - TODO: Add detailed steps on how to do this - - Requires both Compute Owner and Cloud Project Owner permissions -Create Kubernetes secret: - -kubectl create secret generic cloud-sa --from-file=cloud-sa.json -Modify "controller.yaml" to use your secret - -Step 2 (Set up Driver): -kubectl create -f setup.yaml -kubectl create -f node.yaml -kubectl create -f controller.yaml - -Step 3 (Run demo [optional]): -kubectl create -f demo-pod.yaml \ No newline at end of file +1. One-time per project: Create GCP service account for CSI driver + 1. Export environment variables for location for service account private key file and name of the service account + ``` + $ export SA_FILE=~/.../cloud-sa.json + $ export GCEPD_SA_NAME=sample-service-account + ``` + 2. Setup project with script + ``` + $ ./deploy/setup_project.sh + ``` +2. Deploy driver to Kubernetes cluster +``` +$ ./deploy/kubernetes/deploy_driver.sh +``` +3. Create example PVC and Pod +``` +$ kubectl create -f ./examples/demo-pod.yaml +``` \ No newline at end of file diff --git a/deploy/kubernetes/delete-driver.sh b/deploy/kubernetes/delete-driver.sh new file mode 100644 index 000000000..3f65a8522 --- /dev/null +++ b/deploy/kubernetes/delete-driver.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +kubectl delete -f node.yaml +kubectl delete -f controller.yaml diff --git a/deploy/kubernetes/deploy-driver.sh b/deploy/kubernetes/deploy-driver.sh new file mode 100644 index 000000000..02d7abf4b --- /dev/null +++ b/deploy/kubernetes/deploy-driver.sh @@ -0,0 +1,6 @@ +#!/bin/bash +source ./common.sh +kubectl create secret generic cloud-sa --from-file=$SA_FILE +kubectl create -f setup-cluster.yaml +kubectl create -f node.yaml +kubectl create -f controller.yaml \ No newline at end of file diff --git a/deploy/kubernetes/setup.yaml b/deploy/kubernetes/setup-cluster.yaml similarity index 100% rename from deploy/kubernetes/setup.yaml rename to deploy/kubernetes/setup-cluster.yaml diff --git a/deploy/setup-project.sh b/deploy/setup-project.sh new file mode 100644 index 000000000..888e53422 --- /dev/null +++ b/deploy/setup-project.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +IAM_NAME="$GCEPD_SA_NAME@$PROJECT.iam.gserviceaccount.com" +gcloud iam service-accounts create $GCEPD_SA_NAME +gcloud iam service-accounts keys create $SA_FILE --iam-account $IAM_NAME +gcloud projects add-iam-policy-binding $PROJECT --member serviceAccount:$IAM_NAME --role roles/compute.storageAdmin roles/compute.admin diff --git a/test/README.md b/test/README.md new file mode 100644 index 000000000..6ce023a3b --- /dev/null +++ b/test/README.md @@ -0,0 +1,2 @@ +How to run Dev tests: +go run test/remote/run_remote/run_remote.go --logtostderr --v 2 --project test-project --zone us-central1-c --ssh-env gce --delete-instances=false --cleanup=false --results-dir=my_test \ No newline at end of file diff --git a/test/remote/run_remote/README b/test/remote/run_remote/README deleted file mode 100644 index bfbcf1047..000000000 --- a/test/remote/run_remote/README +++ /dev/null @@ -1,2 +0,0 @@ -How to run Dev tests: -go run test/remote/run_remote/run_remote.go --logtostderr --v 2 --project dyzz-test --zone us-central1-c --ssh-env gce --delete-instances=false --cleanup=false --results-dir=my_test \ No newline at end of file