From cd50ee00ac6fb290c31c20357e2263bc20ebb6e8 Mon Sep 17 00:00:00 2001 From: ederst Date: Mon, 13 Feb 2023 17:31:28 +0100 Subject: [PATCH] Pass actual cluster name to cinder-csi-plugin This passes the acutal cluster name to the cinder-csi-plugin, so that the plugin will add the name as metadata to the backing volume in OpenStack. Effectively, the change will help to better identify which volume in OpenStack belongs to which cluster, which is especially helpful when running multiple clusters in one OpenStack tenant/project. Setting the cluster name in both - the controller and the nodeserver - will ensure that dynamic and ephemeral volumes will receive the correct metadata. --- pkg/apis/kops/componentconfig.go | 2 ++ pkg/apis/kops/v1alpha2/componentconfig.go | 2 ++ pkg/apis/kops/v1alpha3/componentconfig.go | 2 ++ .../k8s-1.16.yaml.template | 9 ++++++++- upup/pkg/fi/cloudup/new_cluster.go | 5 +++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 3809eccbff..c628baae70 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -790,6 +790,8 @@ type OpenstackBlockStorageConfig struct { CreateStorageClass *bool `json:"createStorageClass,omitempty"` CSIPluginImage string `json:"csiPluginImage,omitempty"` CSITopologySupport *bool `json:"csiTopologySupport,omitempty"` + // ClusterName sets the --cluster flag for the cinder-csi-plugin to the provided name + ClusterName string `json:"clusterName,omitempty"` } // OpenstackMonitor defines the config for a health monitor diff --git a/pkg/apis/kops/v1alpha2/componentconfig.go b/pkg/apis/kops/v1alpha2/componentconfig.go index 8a9e3105cd..b2b08a49f2 100644 --- a/pkg/apis/kops/v1alpha2/componentconfig.go +++ b/pkg/apis/kops/v1alpha2/componentconfig.go @@ -796,6 +796,8 @@ type OpenstackBlockStorageConfig struct { CreateStorageClass *bool `json:"createStorageClass,omitempty"` CSIPluginImage string `json:"csiPluginImage,omitempty"` CSITopologySupport *bool `json:"csiTopologySupport,omitempty"` + // ClusterName sets the --cluster flag for the cinder-csi-plugin to the provided name + ClusterName string `json:"clusterName,omitempty"` } // OpenstackMonitor defines the config for a health monitor diff --git a/pkg/apis/kops/v1alpha3/componentconfig.go b/pkg/apis/kops/v1alpha3/componentconfig.go index cf17cb3892..a5f4d451d9 100644 --- a/pkg/apis/kops/v1alpha3/componentconfig.go +++ b/pkg/apis/kops/v1alpha3/componentconfig.go @@ -787,6 +787,8 @@ type OpenstackBlockStorageConfig struct { CreateStorageClass *bool `json:"createStorageClass,omitempty"` CSIPluginImage string `json:"csiPluginImage,omitempty"` CSITopologySupport *bool `json:"csiTopologySupport,omitempty"` + // ClusterName sets the --cluster flag for the cinder-csi-plugin to the provided name + ClusterName string `json:"clusterName,omitempty"` } // OpenstackMonitor defines the config for a health monitor diff --git a/upup/models/cloudup/resources/addons/storage-openstack.addons.k8s.io/k8s-1.16.yaml.template b/upup/models/cloudup/resources/addons/storage-openstack.addons.k8s.io/k8s-1.16.yaml.template index 65e70b423c..e02bf8a004 100644 --- a/upup/models/cloudup/resources/addons/storage-openstack.addons.k8s.io/k8s-1.16.yaml.template +++ b/upup/models/cloudup/resources/addons/storage-openstack.addons.k8s.io/k8s-1.16.yaml.template @@ -333,7 +333,7 @@ spec: - name: CLOUD_CONFIG value: /etc/kubernetes/cloud.config - name: CLUSTER_NAME - value: kubernetes + value: "{{- if .CloudProvider.Openstack.BlockStorage.ClusterName -}} {{ .CloudProvider.Openstack.BlockStorage.ClusterName }} {{- else -}} kubernetes {{- end -}}" imagePullPolicy: "IfNotPresent" ports: - containerPort: 9808 @@ -465,11 +465,18 @@ spec: - /bin/cinder-csi-plugin - "--endpoint=$(CSI_ENDPOINT)" - "--cloud-config=$(CLOUD_CONFIG)" +{{- if .CloudProvider.Openstack.BlockStorage.ClusterName }} + - "--cluster=$(CLUSTER_NAME)" +{{- end }} env: - name: CSI_ENDPOINT value: unix://csi/csi.sock - name: CLOUD_CONFIG value: /etc/kubernetes/cloud.config +{{- if .CloudProvider.Openstack.BlockStorage.ClusterName }} + - name: CLUSTER_NAME + value: {{ .CloudProvider.Openstack.BlockStorage.ClusterName }} +{{- end }} imagePullPolicy: "IfNotPresent" ports: - containerPort: 9808 diff --git a/upup/pkg/fi/cloudup/new_cluster.go b/upup/pkg/fi/cloudup/new_cluster.go index 5dcf5ead63..cd859206fc 100644 --- a/upup/pkg/fi/cloudup/new_cluster.go +++ b/upup/pkg/fi/cloudup/new_cluster.go @@ -324,8 +324,9 @@ func NewCluster(opt *NewClusterOptions, clientset simple.Clientset) (*NewCluster ExternalNetwork: fi.PtrTo(opt.OpenstackExternalNet), }, BlockStorage: &api.OpenstackBlockStorageConfig{ - Version: fi.PtrTo("v3"), - IgnoreAZ: fi.PtrTo(opt.OpenstackStorageIgnoreAZ), + Version: fi.PtrTo("v3"), + IgnoreAZ: fi.PtrTo(opt.OpenstackStorageIgnoreAZ), + ClusterName: opt.ClusterName, }, Monitor: &api.OpenstackMonitor{ Delay: fi.PtrTo("15s"),