From cf9e7c5fcb94c627e001e09005530906587f84fb Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Thu, 11 Sep 2025 14:49:41 +0800 Subject: [PATCH] backupPVC to different node Signed-off-by: Lyndon-Li --- changelogs/unreleased/9233-Lyndon-Li | 1 - changelogs/unreleased/9297-Lyndon-Li | 1 + pkg/exposer/csi_snapshot.go | 5 +++-- pkg/exposer/csi_snapshot_test.go | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) delete mode 100644 changelogs/unreleased/9233-Lyndon-Li create mode 100644 changelogs/unreleased/9297-Lyndon-Li diff --git a/changelogs/unreleased/9233-Lyndon-Li b/changelogs/unreleased/9233-Lyndon-Li deleted file mode 100644 index 492765e63..000000000 --- a/changelogs/unreleased/9233-Lyndon-Li +++ /dev/null @@ -1 +0,0 @@ -Fix issue #9229, add intolerateSourceNode backupPVC option \ No newline at end of file diff --git a/changelogs/unreleased/9297-Lyndon-Li b/changelogs/unreleased/9297-Lyndon-Li new file mode 100644 index 000000000..f6dd7213a --- /dev/null +++ b/changelogs/unreleased/9297-Lyndon-Li @@ -0,0 +1 @@ +Fix issue #9229, don't attach backupPVC to the source node \ No newline at end of file diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index 50b7c976f..781739ff5 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -52,7 +52,7 @@ type CSISnapshotExposeParam struct { // SourcePVCName is the original name of the PVC that the snapshot is taken for SourcePVCName string - // SourcePVCName is the name of PV for SourcePVC + // SourcePVName is the name of PV for SourcePVC SourcePVName string // AccessMode defines the mode to access the snapshot @@ -217,7 +217,8 @@ func (e *csiSnapshotExposer) Expose(ctx context.Context, ownerObject corev1api.O if _, found := backupPVCAnnotations[util.VSphereCNSFastCloneAnno]; found { if n, err := kube.GetPVAttachedNodes(ctx, csiExposeParam.SourcePVName, e.kubeClient.StorageV1()); err != nil { - curLog.WithField("source PV", csiExposeParam.SourcePVName).WithError(err).Warn("Failed to get attached node for source PV, ignore intolerable nodes") + curLog.WithField("source PV", csiExposeParam.SourcePVName).WithError(err).Warnf("Failed to get attached node for source PV, ignore %s annotation", util.VSphereCNSFastCloneAnno) + delete(backupPVCAnnotations, util.VSphereCNSFastCloneAnno) } else { intoleratableNodes = n } diff --git a/pkg/exposer/csi_snapshot_test.go b/pkg/exposer/csi_snapshot_test.go index 95e5789e7..7e8e6d883 100644 --- a/pkg/exposer/csi_snapshot_test.go +++ b/pkg/exposer/csi_snapshot_test.go @@ -197,6 +197,7 @@ func TestExpose(t *testing.T) { expectedReadOnlyPVC bool expectedBackupPVCStorageClass string expectedAffinity *corev1api.Affinity + expectedPVCAnnotation map[string]string }{ { name: "wait vs ready fail", @@ -686,7 +687,8 @@ func TestExpose(t *testing.T) { }, }, }, - expectedAffinity: nil, + expectedAffinity: nil, + expectedPVCAnnotation: nil, }, { name: "IntolerateSourceNode, get empty source node", @@ -713,7 +715,8 @@ func TestExpose(t *testing.T) { kubeClientObj: []runtime.Object{ daemonSet, }, - expectedAffinity: nil, + expectedAffinity: nil, + expectedPVCAnnotation: map[string]string{util.VSphereCNSFastCloneAnno: "true"}, }, { name: "IntolerateSourceNode, get source nodes", @@ -759,6 +762,7 @@ func TestExpose(t *testing.T) { }, }, }, + expectedPVCAnnotation: map[string]string{util.VSphereCNSFastCloneAnno: "true"}, }, } @@ -841,6 +845,12 @@ func TestExpose(t *testing.T) { if test.expectedAffinity != nil { assert.Equal(t, test.expectedAffinity, backupPod.Spec.Affinity) } + + if test.expectedPVCAnnotation != nil { + assert.Equal(t, test.expectedPVCAnnotation, backupPVC.Annotations) + } else { + assert.Empty(t, backupPVC.Annotations) + } } else { assert.EqualError(t, err, test.err) }