From cd50ee00ac6fb290c31c20357e2263bc20ebb6e8 Mon Sep 17 00:00:00 2001 From: ederst Date: Mon, 13 Feb 2023 17:31:28 +0100 Subject: [PATCH 1/3] 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"), From b4557d47297d51b7be245ee6c01553b05754ace4 Mon Sep 17 00:00:00 2001 From: ederst Date: Mon, 13 Feb 2023 17:34:31 +0100 Subject: [PATCH 2/3] Run make apimachinery and crds --- k8s/crds/kops.k8s.io_clusters.yaml | 4 ++++ pkg/apis/kops/v1alpha2/zz_generated.conversion.go | 2 ++ pkg/apis/kops/v1alpha3/zz_generated.conversion.go | 2 ++ 3 files changed, 8 insertions(+) diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index 9e55c32641..2869196c6d 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -428,6 +428,10 @@ spec: properties: bs-version: type: string + clusterName: + description: ClusterName sets the --cluster flag for the + cinder-csi-plugin to the provided name + type: string createStorageClass: description: CreateStorageClass provisions a default class for the Cinder plugin diff --git a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go index c562439460..9fa3215bbb 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go @@ -6420,6 +6420,7 @@ func autoConvert_v1alpha2_OpenstackBlockStorageConfig_To_kops_OpenstackBlockStor out.CreateStorageClass = in.CreateStorageClass out.CSIPluginImage = in.CSIPluginImage out.CSITopologySupport = in.CSITopologySupport + out.ClusterName = in.ClusterName return nil } @@ -6436,6 +6437,7 @@ func autoConvert_kops_OpenstackBlockStorageConfig_To_v1alpha2_OpenstackBlockStor out.CreateStorageClass = in.CreateStorageClass out.CSIPluginImage = in.CSIPluginImage out.CSITopologySupport = in.CSITopologySupport + out.ClusterName = in.ClusterName return nil } diff --git a/pkg/apis/kops/v1alpha3/zz_generated.conversion.go b/pkg/apis/kops/v1alpha3/zz_generated.conversion.go index 2acc378689..5bced74abf 100644 --- a/pkg/apis/kops/v1alpha3/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha3/zz_generated.conversion.go @@ -6669,6 +6669,7 @@ func autoConvert_v1alpha3_OpenstackBlockStorageConfig_To_kops_OpenstackBlockStor out.CreateStorageClass = in.CreateStorageClass out.CSIPluginImage = in.CSIPluginImage out.CSITopologySupport = in.CSITopologySupport + out.ClusterName = in.ClusterName return nil } @@ -6685,6 +6686,7 @@ func autoConvert_kops_OpenstackBlockStorageConfig_To_v1alpha3_OpenstackBlockStor out.CreateStorageClass = in.CreateStorageClass out.CSIPluginImage = in.CSIPluginImage out.CSITopologySupport = in.CSITopologySupport + out.ClusterName = in.ClusterName return nil } From 30495063a35c533ff4c46bc9a8f914b52239d321 Mon Sep 17 00:00:00 2001 From: ederst Date: Mon, 13 Feb 2023 17:45:29 +0100 Subject: [PATCH 3/3] Update expected --- .../create_cluster/ha_openstack/expected-v1alpha2.yaml | 1 + .../create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml | 1 + .../create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml b/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml index c64a7d3ab7..2de2ba8256 100644 --- a/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml +++ b/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml @@ -14,6 +14,7 @@ spec: openstack: blockStorage: bs-version: v3 + clusterName: minimal.k8s.local ignore-volume-az: false monitor: delay: 15s diff --git a/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml b/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml index e27554adcc..96b9da5383 100644 --- a/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml +++ b/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml @@ -14,6 +14,7 @@ spec: openstack: blockStorage: bs-version: v3 + clusterName: ha.example.com ignore-volume-az: false loadbalancer: floatingNetwork: vlan1 diff --git a/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml b/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml index 4b40f59c16..df6cb5ede4 100644 --- a/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml +++ b/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml @@ -14,6 +14,7 @@ spec: openstack: blockStorage: bs-version: v3 + clusterName: minimal.k8s.local ignore-volume-az: false loadbalancer: floatingNetwork: vlan1