From c9a1e1ffe21560c24ef13ae0cf5bd2cc1b020692 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20T=C3=B6lle?= <julian.toelle@hetzner-cloud.de>
Date: Fri, 25 Nov 2022 13:01:18 +0100
Subject: [PATCH] fix: revert invalid topology changes #333 (#335)

Revert all changes we made to our reported topology for nodes and
volumes.

Because we report two segments on the `NodeGetInfo` call, but
only one of them on `CreateVolume` we are not compliant with the CSI
spec. This did not matter for Kubernetes, because the scheduler still
worked, but it breaks Nomad.

As we are not compliant with the CSI spec, we decided to revert these
changes, even though it will require user intervention to fix volumes
created in the meantime.

For details see issue #333.
---
 driver/controller.go      | 2 +-
 driver/controller_test.go | 4 ++--
 driver/driver.go          | 9 +--------
 driver/node.go            | 5 -----
 4 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/driver/controller.go b/driver/controller.go
index f2da5ea..f42c29e 100644
--- a/driver/controller.go
+++ b/driver/controller.go
@@ -94,7 +94,7 @@ func (s *ControllerService) CreateVolume(ctx context.Context, req *proto.CreateV
 			AccessibleTopology: []*proto.Topology{
 				{
 					Segments: map[string]string{
-						TopologySegmentLocationLegacy: volume.Location,
+						TopologySegmentLocation: volume.Location,
 					},
 				},
 			},
diff --git a/driver/controller_test.go b/driver/controller_test.go
index 1abdb35..7b14042 100644
--- a/driver/controller_test.go
+++ b/driver/controller_test.go
@@ -91,7 +91,7 @@ func TestControllerServiceCreateVolume(t *testing.T) {
 	}
 	if len(resp.Volume.AccessibleTopology) == 1 {
 		top := resp.Volume.AccessibleTopology[0]
-		if loc := top.Segments[TopologySegmentLocationLegacy]; loc != "testloc" {
+		if loc := top.Segments[TopologySegmentLocation]; loc != "testloc" {
 			t.Errorf("unexpected location segment in topology: %s", loc)
 		}
 	} else {
@@ -146,7 +146,7 @@ func TestControllerServiceCreateVolumeWithLocation(t *testing.T) {
 	}
 	if len(resp.Volume.AccessibleTopology) == 1 {
 		top := resp.Volume.AccessibleTopology[0]
-		if loc := top.Segments[TopologySegmentLocationLegacy]; loc != "explicit" {
+		if loc := top.Segments[TopologySegmentLocation]; loc != "explicit" {
 			t.Errorf("unexpected location segment in topology: %s", loc)
 		}
 	} else {
diff --git a/driver/driver.go b/driver/driver.go
index 718fd7d..0681199 100644
--- a/driver/driver.go
+++ b/driver/driver.go
@@ -1,9 +1,5 @@
 package driver
 
-import (
-	apiv1 "k8s.io/api/core/v1"
-)
-
 const (
 	PluginName    = "csi.hetzner.cloud"
 	PluginVersion = "1.6.0"
@@ -12,8 +8,5 @@ const (
 	MinVolumeSize     = 10 // GB
 	DefaultVolumeSize = MinVolumeSize
 
-	TopologySegmentLocation = apiv1.LabelZoneRegionStable
-
-	// this label will be deprecated in future releases
-	TopologySegmentLocationLegacy = PluginName + "/location"
+	TopologySegmentLocation = PluginName + "/location"
 )
diff --git a/driver/node.go b/driver/node.go
index a10be49..f3ca853 100644
--- a/driver/node.go
+++ b/driver/node.go
@@ -172,12 +172,7 @@ 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