Skip to content
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

feat: support alternative driver name #911

Merged
merged 1 commit into from
Jul 2, 2021
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
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ PKG = sigs.k8s.io/azuredisk-csi-driver
GIT_COMMIT ?= $(shell git rev-parse HEAD)
REGISTRY ?= andyzhangx
REGISTRY_NAME ?= $(shell echo $(REGISTRY) | sed "s/.azurecr.io//g")
DRIVER_NAME = disk.csi.azure.com
IMAGE_NAME ?= azuredisk-csi
ifndef BUILD_V2
PLUGIN_NAME = azurediskplugin
Expand All @@ -39,9 +38,8 @@ IMAGE_TAG ?= $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_VERSION)
IMAGE_TAG_LATEST = $(REGISTRY)/$(IMAGE_NAME):latest
REV = $(shell git describe --long --tags --dirty)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
TOPOLOGY_KEY = topology.$(DRIVER_NAME)/zone
ENABLE_TOPOLOGY ?= false
LDFLAGS ?= "-X ${PKG}/pkg/azuredisk.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/azuredisk.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/azuredisk.buildDate=${BUILD_DATE} -X ${PKG}/pkg/azuredisk.DriverName=${DRIVER_NAME} -X ${PKG}/pkg/azuredisk.topologyKey=${TOPOLOGY_KEY} -extldflags "-static"" ${GOTAGS}
LDFLAGS ?= "-X ${PKG}/pkg/azuredisk.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/azuredisk.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/azuredisk.buildDate=${BUILD_DATE} -extldflags "-static"" ${GOTAGS}
E2E_HELM_OPTIONS ?= --set image.azuredisk.repository=$(REGISTRY)/$(IMAGE_NAME) --set image.azuredisk.tag=$(IMAGE_VERSION) --set image.azuredisk.pullPolicy=Always
E2E_HELM_OPTIONS += ${EXTRA_HELM_OPTIONS}
GINKGO_FLAGS = -ginkgo.v
Expand Down
1 change: 1 addition & 0 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following table lists the configurable parameters of the latest Azure Disk C

| Parameter | Description | Default |
| ------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
| `driver.name` | alternative driver name | `disk.csi.azure.com` |
| `feature.enableFSGroupPolicy` | enable `fsGroupPolicy` on a k8s 1.20+ cluster | `false` |
| `image.azuredisk.repository` | azuredisk-csi-driver docker image | mcr.microsoft.com/k8s/csi/azuredisk-csi |
| `image.azuredisk.tag` | azuredisk-csi-driver docker image tag | latest |
Expand Down
Binary file modified charts/latest/azuredisk-csi-driver-v1.5.0.tgz
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ spec:
- "--endpoint=$(CSI_ENDPOINT)"
- "--metrics-address=0.0.0.0:{{ .Values.controller.metricsPort }}"
- "--disable-avset-nodes={{ .Values.controller.disableAvailabilitySetNodes }}"
- "--drivername={{ .Values.driver.name }}"
ports:
- containerPort: 29602
name: healthz
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
name: disk.csi.azure.com
name: {{ .Values.driver.name }}
spec:
attachRequired: true
podInfoOnMount: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ spec:
args:
- "--v=2"
- "--csi-address=$(CSI_ENDPOINT)"
- "--kubelet-registration-path=C:\\var\\lib\\kubelet\\plugins\\disk.csi.azure.com\\csi.sock"
- "--kubelet-registration-path=C:\\var\\lib\\kubelet\\plugins\\{{ .Values.driver.name }}\\csi.sock"
lifecycle:
preStop:
exec:
command: ["cmd", "/c", "del /f C:\\registration\\disk.csi.azure.com-reg.sock C:\\csi\\disk.csi.azure.com\\csi.sock"]
command: ["cmd", "/c", "del /f C:\\registration\\{{ .Values.driver.name }}-reg.sock C:\\csi\\{{ .Values.driver.name }}\\csi.sock"]
env:
- name: CSI_ENDPOINT
value: unix://C:\\csi\\csi.sock
Expand Down Expand Up @@ -93,6 +93,7 @@ spec:
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(KUBE_NODE_NAME)"
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
- "--drivername={{ .Values.driver.name }}"
ports:
- containerPort: 29603
name: healthz
Expand Down Expand Up @@ -170,7 +171,7 @@ spec:
type: Directory
- name: plugin-dir
hostPath:
path: {{ .Values.windows.kubelet }}\plugins\disk.csi.azure.com\
path: {{ .Values.windows.kubelet }}\plugins\{{ .Values.driver.name }}\
type: DirectoryOrCreate
- name: azure-config
hostPath:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ spec:
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "rm -rf /registration/disk.csi.azure.com-reg.sock /csi/csi.sock"]
command: ["/bin/sh", "-c", "rm -rf /registration/{{ .Values.driver.name }}-reg.sock /csi/csi.sock"]
env:
- name: ADDRESS
value: /csi/csi.sock
- name: DRIVER_REG_SOCK_PATH
value: {{ .Values.linux.kubelet }}/plugins/disk.csi.azure.com/csi.sock
value: {{ .Values.linux.kubelet }}/plugins/{{ .Values.driver.name }}/csi.sock
volumeMounts:
- name: socket-dir
mountPath: /csi
Expand All @@ -91,6 +91,7 @@ spec:
- "--nodeid=$(KUBE_NODE_NAME)"
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
- "--enable-perf-optimization={{ .Values.linux.enablePerfOptimization }}"
- "--drivername={{ .Values.driver.name }}"
ports:
- containerPort: 29603
name: healthz
Expand Down Expand Up @@ -166,7 +167,7 @@ spec:
memory: 20Mi
volumes:
- hostPath:
path: {{ .Values.linux.kubelet }}/plugins/disk.csi.azure.com
path: {{ .Values.linux.kubelet }}/plugins/{{ .Values.driver.name }}
type: DirectoryOrCreate
name: socket-dir
- hostPath:
Expand Down
3 changes: 3 additions & 0 deletions charts/latest/azuredisk-csi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ snapshot:
feature:
enableFSGroupPolicy: false

driver:
name: disk.csi.azure.com

linux:
enabled: true
kubelet: /var/lib/kubelet
Expand Down
14 changes: 8 additions & 6 deletions pkg/azuredisk/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ import (

const (
// DriverName driver name
DriverName = "disk.csi.azure.com"
azurePublicCloud = "AZUREPUBLICCLOUD"
azureStackCloud = "AZURESTACKCLOUD"
DefaultDriverName = "disk.csi.azure.com"
azurePublicCloud = "AZUREPUBLICCLOUD"
azureStackCloud = "AZURESTACKCLOUD"

errDiskNotFound = "not found"
// default IOPS Caps & Throughput Cap (MBps) per https://docs.microsoft.com/en-us/azure/virtual-machines/linux/disks-ultra-ssd
Expand Down Expand Up @@ -141,13 +141,15 @@ type Driver struct {

// newDriverV1 Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
func newDriverV1(nodeID string, enablePerfOptimization bool) *Driver {
func newDriverV1(nodeID, driverName string, enablePerfOptimization bool) *Driver {
driver := Driver{}
driver.Name = DriverName
driver.Name = driverName
driver.Version = driverVersion
driver.NodeID = nodeID
driver.volumeLocks = volumehelper.NewVolumeLocks()

topologyKey = fmt.Sprintf("topology.%s/zone", driver.Name)

cache, err := azcache.NewTimedcache(5*time.Minute, func(key string) (interface{}, error) {
return nil, nil
})
Expand All @@ -161,7 +163,7 @@ func newDriverV1(nodeID string, enablePerfOptimization bool) *Driver {

// Run driver initialization
func (d *Driver) Run(endpoint, kubeconfig string, disableAVSetNodes, testingMock bool) {
versionMeta, err := GetVersionYAML()
versionMeta, err := GetVersionYAML(d.Name)
if err != nil {
klog.Fatalf("%v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/azuredisk/azuredisk_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ package azuredisk

// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
func NewDriver(nodeID string, enablePerfOptimization bool) CSIDriver {
return newDriverV1(nodeID, enablePerfOptimization)
func NewDriver(nodeID, driverName string, enablePerfOptimization bool) CSIDriver {
return newDriverV1(nodeID, driverName, enablePerfOptimization)
}
15 changes: 9 additions & 6 deletions pkg/azuredisk/azuredisk_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package azuredisk
import (
"context"
"flag"
"fmt"
"reflect"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-12-01/compute"
Expand All @@ -47,34 +48,36 @@ type DriverV2 struct {
}

// NewDriver creates a Driver or DriverV2 object depending on the --temp-use-driver-v2 flag.
func NewDriver(nodeID string, enablePerfOptimization bool) CSIDriver {
func NewDriver(nodeID, driverName string, enablePerfOptimization bool) CSIDriver {
var d CSIDriver

if !*useDriverV2 {
d = newDriverV1(nodeID, enablePerfOptimization)
d = newDriverV1(nodeID, driverName, enablePerfOptimization)
} else {
d = newDriverV2(nodeID, enablePerfOptimization)
d = newDriverV2(nodeID, driverName, enablePerfOptimization)
}

return d
}

// newDriverV2 Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
func newDriverV2(nodeID string, enablePerfOptimization bool) *DriverV2 {
func newDriverV2(nodeID, driverName string, enablePerfOptimization bool) *DriverV2 {
klog.Warning("Using DriverV2")
driver := DriverV2{}
driver.Name = DriverName
driver.Name = driverName
driver.Version = driverVersion
driver.NodeID = nodeID
driver.volumeLocks = volumehelper.NewVolumeLocks()
driver.perfOptimizationEnabled = enablePerfOptimization

topologyKey = fmt.Sprintf("topology.%s/zone", driver.Name)
return &driver
}

// Run driver initialization
func (d *DriverV2) Run(endpoint, kubeconfig string, disableAVSetNodes, testingMock bool) {
versionMeta, err := GetVersionYAML()
versionMeta, err := GetVersionYAML(d.Name)
if err != nil {
klog.Fatalf("%v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (d *Driver) listVolumesInCluster(ctx context.Context, start, maxEntries int
rgMap := make(map[string]bool)
volSet := make(map[string]bool)
for _, pv := range pvList.Items {
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == DriverName {
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == d.Name {
diskURI := pv.Spec.CSI.VolumeHandle
if err := isValidDiskURI(diskURI); err != nil {
klog.Warningf("invalid disk uri (%s) with error(%v)", diskURI, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/controllerserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (d *DriverV2) listVolumesInCluster(ctx context.Context, start, maxEntries i
rgMap := make(map[string]bool)
volSet := make(map[string]bool)
for _, pv := range pvList.Items {
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == DriverName {
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == d.Name {
diskURI := pv.Spec.CSI.VolumeHandle
if err := isValidDiskURI(diskURI); err != nil {
klog.Warningf("invalid disk uri (%s) with error(%v)", diskURI, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/fake_azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

const (
fakeDriverName = "fake.disk.csi.azure.com"
fakeDriverName = "disk.csi.azure.com"
fakeNodeID = "fakeNodeID"
fakeDriverVersion = "fakeDriverVersion"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/identityserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

const (
fakeCSIDriverName = "fake"
fakeCSIDriverName = "disk.csi.azure.com"
vendorVersion = "0.3.0"
)

Expand Down
8 changes: 4 additions & 4 deletions pkg/azuredisk/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type VersionInfo struct {
}

// GetVersion returns the version information of the driver
func GetVersion() VersionInfo {
func GetVersion(driverName string) VersionInfo {
return VersionInfo{
DriverName: DriverName,
DriverName: driverName,
DriverVersion: driverVersion,
GitCommit: gitCommit,
BuildDate: buildDate,
Expand All @@ -60,8 +60,8 @@ func GetVersion() VersionInfo {

// GetVersionYAML returns the version information of the driver
// in YAML format
func GetVersionYAML() (string, error) {
info := GetVersion()
func GetVersionYAML(driverName string) (string, error) {
info := GetVersion(driverName)
marshalled, err := yaml.Marshal(&info)
if err != nil {
return "", err
Expand Down
8 changes: 4 additions & 4 deletions pkg/azuredisk/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
)

func TestGetVersion(t *testing.T) {
version := GetVersion()
version := GetVersion(DefaultDriverName)

expected := VersionInfo{
DriverName: DriverName,
DriverName: DefaultDriverName,
DriverVersion: "N/A",
GitCommit: "N/A",
BuildDate: "N/A",
Expand All @@ -47,12 +47,12 @@ func TestGetVersion(t *testing.T) {
}

func TestGetVersionYAML(t *testing.T) {
resp, err := GetVersionYAML()
resp, err := GetVersionYAML("")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

versionInfo := GetVersion()
versionInfo := GetVersion("")
marshalled, _ := yaml.Marshal(&versionInfo)

expected := strings.TrimSpace(string(marshalled))
Expand Down
5 changes: 3 additions & 2 deletions pkg/azurediskplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ var (
version = flag.Bool("version", false, "Print the version and exit.")
metricsAddress = flag.String("metrics-address", "0.0.0.0:29604", "export the metrics")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
driverName = flag.String("drivername", azuredisk.DefaultDriverName, "name of the driver")
disableAVSetNodes = flag.Bool("disable-avset-nodes", true, "disable DisableAvailabilitySetNodes in cloud config for controller")
enablePerfOptimization = flag.Bool("enable-perf-optimization", false, "boolean flag to enable disk perf optimization")
)

func main() {
flag.Parse()
if *version {
info, err := azuredisk.GetVersionYAML()
info, err := azuredisk.GetVersionYAML(*driverName)
if err != nil {
klog.Fatalln(err)
}
Expand All @@ -67,7 +68,7 @@ func main() {
}

func handle() {
driver := azuredisk.NewDriver(*nodeID, *enablePerfOptimization)
driver := azuredisk.NewDriver(*nodeID, *driverName, *enablePerfOptimization)
if driver == nil {
klog.Fatalln("Failed to initialize azuredisk CSI Driver")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi-common/fake_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package csicommon

const (
fakeCSIDriverName = "fake"
fakeCSIDriverName = "disk.csi.azure.com"
fakeNodeID = "fakeNodeID"
)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/driver/azuredisk_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func normalizeProvisioner(provisioner string) string {
func InitAzureDiskDriver() PVTestDriver {
driverName := os.Getenv(AzureDriverNameVar)
if driverName == "" {
driverName = azuredisk.DriverName
driverName = azuredisk.DefaultDriverName
}

klog.Infof("Using azure disk driver: %s", driverName)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ func (t *dynamicProvisioningTestSuite) normalizeVolume(volume testsuites.VolumeD
case "kubernetes.io/azure-disk":
volumeBindingMode := storagev1.VolumeBindingWaitForFirstConsumer
volume.VolumeBindingMode = &volumeBindingMode
case "", azuredisk.DriverName:
case "", azuredisk.DefaultDriverName:
if !isMultiZone {
return volume
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = ginkgo.BeforeSuite(func() {
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})

nodeid := os.Getenv("nodeid")
azurediskDriver = azuredisk.NewDriver(nodeid, false)
azurediskDriver = azuredisk.NewDriver(nodeid, azuredisk.DefaultDriverName, false)
kubeconfig := os.Getenv(kubeconfigEnvVar)
go func() {
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
Expand Down