From 01d0e6d9a43defaa5a1647048fe631024e110e7f Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Tue, 1 Aug 2017 09:47:20 +0000 Subject: [PATCH] RBD provisioner use provisioner name as identitiy if not specified, and support `PROVISIONER_NAME` envionment variable. In production, provisioner should not use random identity on start. Because, provisioner Pod may crash or be recreated on different nodes, if a provisioner generates random identity string each time, then it will cannot manage old PVs it provisioned before. In this commit, I change the default behavior to use `provision.ProvisionerName` constant as default identity instead of random UUID string. --- ceph/rbd/cmd/rbd-provisioner/main.go | 26 ++++++++++++++++++++------ ceph/rbd/deployment.yaml | 3 +++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ceph/rbd/cmd/rbd-provisioner/main.go b/ceph/rbd/cmd/rbd-provisioner/main.go index c96ae85dc82..082aa13ad75 100644 --- a/ceph/rbd/cmd/rbd-provisioner/main.go +++ b/ceph/rbd/cmd/rbd-provisioner/main.go @@ -18,11 +18,11 @@ package main import ( "flag" + "os" "github.com/golang/glog" "github.com/kubernetes-incubator/external-storage/ceph/rbd/pkg/provision" "github.com/kubernetes-incubator/external-storage/lib/controller" - "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -35,6 +35,10 @@ var ( id = flag.String("id", "", "Unique provisioner identity") ) +const ( + provisionerNameKey = "PROVISIONER_NAME" +) + func main() { flag.Parse() flag.Set("logtostderr", "true") @@ -46,10 +50,6 @@ func main() { } else { config, err = rest.InClusterConfig() } - prID := string(uuid.NewUUID()) - if *id != "" { - prID = *id - } if err != nil { glog.Fatalf("Failed to create config: %v", err) } @@ -58,6 +58,20 @@ func main() { glog.Fatalf("Failed to create client: %v", err) } + prName := provision.ProvisionerName + prNameFromEnv := os.Getenv(provisionerNameKey) + if prNameFromEnv != "" { + prName = prNameFromEnv + } + + // By default, we use provision name as provisioner identity. + // User may specify their own identity with `-id` flag to distinguish each + // others, if they deploy more than one RBD provisioners under same provisioner name. + prID := prName + if *id != "" { + prID = *id + } + // The controller needs to know what the server version is because out-of-tree // provisioners aren't officially supported until 1.5 serverVersion, err := clientset.Discovery().ServerVersion() @@ -74,7 +88,7 @@ func main() { // PVs pc := controller.NewProvisionController( clientset, - provision.ProvisionerName, + prName, rbdProvisioner, serverVersion.GitVersion, ) diff --git a/ceph/rbd/deployment.yaml b/ceph/rbd/deployment.yaml index 07a5707db37..f323725c8dc 100644 --- a/ceph/rbd/deployment.yaml +++ b/ceph/rbd/deployment.yaml @@ -14,3 +14,6 @@ spec: containers: - name: rbd-provisioner image: "quay.io/external_storage/rbd-provisioner:latest" + env: + - name: PROVISIONER_NAME + value: ceph.com/rbd