From f361a691032450530c6aebf1c2f101cc3e5de422 Mon Sep 17 00:00:00 2001 From: "vincent.baer" Date: Mon, 18 Sep 2023 14:14:04 +0000 Subject: [PATCH] Add topology.kubernetes.io/zone if topology.bsu.outscale.com/zone not found --- pkg/driver/controller.go | 8 ++++++++ pkg/driver/controller_test.go | 22 ++++++++++++++++++++++ pkg/driver/driver.go | 5 +++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index db5fe32f..5a9ac11c 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -534,12 +534,20 @@ func pickAvailabilityZone(requirement *csi.TopologyRequirement) string { if exists { return zone } + zone, exists = topology.GetSegments()[TopologyK8sKey] + if exists { + return zone + } } for _, topology := range requirement.GetRequisite() { zone, exists := topology.GetSegments()[TopologyKey] if exists { return zone } + zone, exists = topology.GetSegments()[TopologyK8sKey] + if exists { + return zone + } } return "" } diff --git a/pkg/driver/controller_test.go b/pkg/driver/controller_test.go index 72660eba..c64f36c9 100644 --- a/pkg/driver/controller_test.go +++ b/pkg/driver/controller_test.go @@ -1266,6 +1266,28 @@ func TestPickAvailabilityZone(t *testing.T) { }, expZone: expZone, }, + { + name: "Pick from requisite topologyK8sKey", + requirement: &csi.TopologyRequirement{ + Requisite: []*csi.Topology{ + { + Segments: map[string]string{TopologyK8sKey: expZone}, + }, + }, + }, + expZone: expZone, + }, + { + name: "Pick from multi requisites", + requirement: &csi.TopologyRequirement{ + Requisite: []*csi.Topology{ + { + Segments: map[string]string{TopologyKey: expZone, TopologyK8sKey: expZone}, + }, + }, + }, + expZone: expZone, + }, { name: "Pick from empty topology", requirement: &csi.TopologyRequirement{ diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index e06387fa..64a843c9 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -41,8 +41,9 @@ const ( ) const ( - DriverName = "bsu.csi.outscale.com" - TopologyKey = "topology." + DriverName + "/zone" + DriverName = "bsu.csi.outscale.com" + TopologyKey = "topology." + DriverName + "/zone" + TopologyK8sKey = "topology.kubernetes.io/zone" ) type Driver struct {