From 73bc5ceda6f4b067331473180dee9df598fda5fa Mon Sep 17 00:00:00 2001
From: Maksim Paskal <paskal.maksim@gmail.com>
Date: Fri, 18 Nov 2022 09:27:34 +0200
Subject: [PATCH] [enhancement] Use native kubernetes topology region label for
 volumes nodeAffinity (#302)

autoscaler topology label

Signed-off-by: Maksim Paskal <paskal.maksim@gmail.com>
---
 driver/driver.go | 9 ++++++++-
 driver/node.go   | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/driver/driver.go b/driver/driver.go
index 0681199..718fd7d 100644
--- a/driver/driver.go
+++ b/driver/driver.go
@@ -1,5 +1,9 @@
 package driver
 
+import (
+	apiv1 "k8s.io/api/core/v1"
+)
+
 const (
 	PluginName    = "csi.hetzner.cloud"
 	PluginVersion = "1.6.0"
@@ -8,5 +12,8 @@ const (
 	MinVolumeSize     = 10 // GB
 	DefaultVolumeSize = MinVolumeSize
 
-	TopologySegmentLocation = PluginName + "/location"
+	TopologySegmentLocation = apiv1.LabelZoneRegionStable
+
+	// this label will be deprecated in future releases
+	TopologySegmentLocationLegacy = PluginName + "/location"
 )
diff --git a/driver/node.go b/driver/node.go
index f3ca853..a10be49 100644
--- a/driver/node.go
+++ b/driver/node.go
@@ -172,7 +172,12 @@ func (s *NodeService) NodeGetInfo(context.Context, *proto.NodeGetInfoRequest) (*
 		MaxVolumesPerNode: MaxVolumesPerNode,
 		AccessibleTopology: &proto.Topology{
 			Segments: map[string]string{
+				// need this topology key for k8s clusters without hcloud-cloud-controller-manager
+				// that handles this node label
 				TopologySegmentLocation: s.serverLocation,
+				// need this topology key for backward compatibility
+				// for PV created with older version this CSI driver
+				TopologySegmentLocationLegacy: s.serverLocation,
 			},
 		},
 	}
-- 
GitLab