Skip to content

Commit f41077b

Browse files
Wei WengWei Weng
authored andcommitted
strip volume name from PVC
Signed-off-by: Wei Weng <Wei.Weng@microsoft.com>
1 parent b1518f3 commit f41077b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pkg/controllers/placement/resource_selector.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ func generateRawContent(object *unstructured.Unstructured) ([]byte, error) {
501501
unstructured.RemoveNestedField(object.Object, "spec", "template", "metadata", "labels", "controller-uid")
502502
unstructured.RemoveNestedField(object.Object, "spec", "template", "metadata", "labels", "batch.kubernetes.io/controller-uid")
503503
}
504+
} else if object.GetKind() == "PersistentVolumeClaim" && object.GetAPIVersion() == "v1" {
505+
// Remove volumeName which references a specific PV from the hub cluster that won't exist on member clusters.
506+
// The member cluster's storage provisioner will create and bind a new PV.
507+
unstructured.RemoveNestedField(object.Object, "spec", "volumeName")
504508
}
505509

506510
rawContent, err := object.MarshalJSON()

pkg/controllers/placement/resource_selector_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func TestGenerateResourceContent(t *testing.T) {
272272
},
273273
},
274274
StorageClassName: ptr.To("standard"),
275+
VolumeName: "pvc-12345-from-hub-cluster",
275276
},
276277
},
277278
wantResource: corev1.PersistentVolumeClaim{
@@ -296,6 +297,7 @@ func TestGenerateResourceContent(t *testing.T) {
296297
},
297298
},
298299
StorageClassName: ptr.To("standard"),
300+
// VolumeName should be removed
299301
},
300302
},
301303
},

0 commit comments

Comments
 (0)