Skip to content

Commit 9ba69dd

Browse files
Wei WengWei Weng
authored andcommitted
ignore some pvc annotations
Signed-off-by: Wei Weng <Wei.Weng@microsoft.com>
1 parent bda3414 commit 9ba69dd

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

pkg/controllers/placement/resource_selector.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/runtime/schema"
3232
"k8s.io/apimachinery/pkg/types"
33+
pvutil "k8s.io/component-helpers/storage/volume"
3334
"k8s.io/klog/v2"
3435
"k8s.io/kubectl/pkg/util/deployment"
3536
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -444,6 +445,15 @@ func generateRawContent(object *unstructured.Unstructured) ([]byte, error) {
444445
delete(annots, corev1.LastAppliedConfigAnnotation)
445446
// Remove the revision annotation set by deployment controller.
446447
delete(annots, deployment.RevisionAnnotation)
448+
// Remove node-specific annotations from PVCs that would break when propagated to member clusters
449+
// These annotations reference specific nodes from the hub cluster which don't exist on member clusters
450+
// The member cluster's storage provisioner will set appropriate values for its own nodes
451+
// All annotations below are listed in well-known labels, annotations and taints document:
452+
// https://kubernetes.io/docs/reference/labels-annotations-taints/
453+
delete(annots, pvutil.AnnSelectedNode) // Node selected for volume binding
454+
delete(annots, pvutil.AnnBindCompleted) // Binding completion status
455+
delete(annots, pvutil.AnnBoundByController) // Controller binding status
456+
delete(annots, pvutil.AnnBetaStorageProvisioner) // Beta storage provisioner annotation
447457
if len(annots) == 0 {
448458
object.SetAnnotations(nil)
449459
} else {

pkg/controllers/placement/resource_selector_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import (
2727
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
"k8s.io/apimachinery/pkg/api/meta"
30+
"k8s.io/apimachinery/pkg/api/resource"
3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
"k8s.io/apimachinery/pkg/runtime/schema"
3435
"k8s.io/apimachinery/pkg/types"
3536
utilrand "k8s.io/apimachinery/pkg/util/rand"
37+
pvutil "k8s.io/component-helpers/storage/volume"
3638
"k8s.io/kubectl/pkg/util/deployment"
3739
"k8s.io/utils/ptr"
3840

@@ -243,6 +245,60 @@ func TestGenerateResourceContent(t *testing.T) {
243245
},
244246
},
245247
},
248+
"PersistentVolumeClaim with node-specific annotations": {
249+
resource: corev1.PersistentVolumeClaim{
250+
TypeMeta: metav1.TypeMeta{
251+
APIVersion: "v1",
252+
Kind: "PersistentVolumeClaim",
253+
},
254+
ObjectMeta: metav1.ObjectMeta{
255+
Name: "test-pvc",
256+
Namespace: "test-namespace",
257+
Annotations: map[string]string{
258+
pvutil.AnnSelectedNode: "hub-control-plane",
259+
pvutil.AnnBindCompleted: "yes",
260+
pvutil.AnnBoundByController: "yes",
261+
pvutil.AnnBetaStorageProvisioner: "kubernetes.io/no-provisioner",
262+
"custom-annotation": "should-remain",
263+
},
264+
},
265+
Spec: corev1.PersistentVolumeClaimSpec{
266+
AccessModes: []corev1.PersistentVolumeAccessMode{
267+
corev1.ReadWriteOnce,
268+
},
269+
Resources: corev1.VolumeResourceRequirements{
270+
Requests: corev1.ResourceList{
271+
corev1.ResourceStorage: resource.MustParse("1Gi"),
272+
},
273+
},
274+
StorageClassName: ptr.To("standard"),
275+
},
276+
},
277+
wantResource: corev1.PersistentVolumeClaim{
278+
TypeMeta: metav1.TypeMeta{
279+
APIVersion: "v1",
280+
Kind: "PersistentVolumeClaim",
281+
},
282+
ObjectMeta: metav1.ObjectMeta{
283+
Name: "test-pvc",
284+
Namespace: "test-namespace",
285+
Annotations: map[string]string{
286+
"custom-annotation": "should-remain",
287+
},
288+
},
289+
Spec: corev1.PersistentVolumeClaimSpec{
290+
AccessModes: []corev1.PersistentVolumeAccessMode{
291+
corev1.ReadWriteOnce,
292+
},
293+
Resources: corev1.VolumeResourceRequirements{
294+
Requests: corev1.ResourceList{
295+
corev1.ResourceStorage: resource.MustParse("1Gi"),
296+
},
297+
},
298+
StorageClassName: ptr.To("standard"),
299+
},
300+
},
301+
},
246302
}
247303

248304
for testName, tt := range tests {

0 commit comments

Comments
 (0)