From cfc6eef0a875fdc8471fc10b1b6963641bdfe96e Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Tue, 22 Feb 2022 16:06:39 +0800 Subject: [PATCH] Modify according to comments 1. rename zoneSeparator to gkeZoneSeparator 2. add example of regional PV's node affinity. modify test case description. Signed-off-by: Xun Jiang --- changelogs/unreleased/{4680-jxun => 4691-jxun} | 0 pkg/backup/item_backupper.go | 4 ++-- pkg/backup/item_backupper_test.go | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) rename changelogs/unreleased/{4680-jxun => 4691-jxun} (100%) diff --git a/changelogs/unreleased/4680-jxun b/changelogs/unreleased/4691-jxun similarity index 100% rename from changelogs/unreleased/4680-jxun rename to changelogs/unreleased/4691-jxun diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 648447625..32a9f5504 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -385,7 +385,7 @@ const ( awsEbsCsiZoneKey = "topology.ebs.csi.aws.com/zone" azureCsiZoneKey = "topology.disk.csi.azure.com/zone" gkeCsiZoneKey = "topology.gke.io/zone" - zoneSeparator = "__" + gkeZoneSeparator = "__" ) // takePVSnapshot triggers a snapshot for the volume/disk underlying a PersistentVolume if the provided @@ -560,7 +560,7 @@ func zoneFromPVNodeAffinity(res *corev1api.PersistentVolume, topologyKeys ...str } if providerGke { - return gkeCsiZoneKey, strings.Join(zones, zoneSeparator) + return gkeCsiZoneKey, strings.Join(zones, gkeZoneSeparator) } return "", "" diff --git a/pkg/backup/item_backupper_test.go b/pkg/backup/item_backupper_test.go index 03ed7c017..2152a5301 100644 --- a/pkg/backup/item_backupper_test.go +++ b/pkg/backup/item_backupper_test.go @@ -132,7 +132,22 @@ func Test_zoneFromPVNodeAffinity(t *testing.T) { wantValue: "us-central", }, { - name: "Volume with multiple valid keys, and provider is gke, returns the all match", // it should never happen + /* an valid example of node affinity in a GKE's regional PV + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: topology.gke.io/zone + operator: In + values: + - us-central1-a + - matchExpressions: + - key: topology.gke.io/zone + operator: In + values: + - us-central1-c + */ + name: "Volume with multiple valid keys, and provider is gke, returns all valid entries's first zone value", pv: builder.ForPersistentVolume("multi-matching-pv").NodeAffinityRequired( builder.ForNodeSelector( *builder.NewNodeSelectorTermBuilder().WithMatchExpression("topology.gke.io/zone",