Skip to content

Commit a92a367

Browse files
committed
remove namespace name from pvc owner annotation
remove namespace name from pvc owner annotation. Name should be enough to identify vgr/vr the pvc belongs to as the annotation key for vr and vgr is different and both are namespaced scope CRs which would belong to the same namespace as PVC. Signed-off-by: Nikhil-Ladha <nikhilladha1999@gmail.com>
1 parent 8816325 commit a92a367

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

internal/controller/replication.storage/pvc_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ func TestVolumeReplicationReconciler_annotatePVCWithOwner(t *testing.T) {
232232
ctx := context.TODO()
233233
logger := log.FromContext(ctx)
234234
reconciler := createFakeVolumeReplicationReconciler(t, testPVC, volumeReplication)
235-
reqOwner := fmt.Sprintf("%s/%s", volumeReplication.Namespace, volumeReplication.Name)
236-
err := annotatePVCWithOwner(reconciler.Client, ctx, logger, reqOwner, testPVC, replicationv1alpha1.VolumeReplicationNameAnnotation)
235+
err := annotatePVCWithOwner(reconciler.Client, ctx, logger, volumeReplication.Name, testPVC, replicationv1alpha1.VolumeReplicationNameAnnotation)
237236
if tc.errorExpected {
238237
assert.Error(t, err)
239238
} else {
@@ -248,7 +247,7 @@ func TestVolumeReplicationReconciler_annotatePVCWithOwner(t *testing.T) {
248247
err = reconciler.Get(ctx, pvcNamespacedName, testPVC)
249248
assert.NoError(t, err)
250249

251-
assert.Equal(t, testPVC.Annotations[replicationv1alpha1.VolumeReplicationNameAnnotation], reqOwner)
250+
assert.Equal(t, testPVC.Annotations[replicationv1alpha1.VolumeReplicationNameAnnotation], volumeReplication.Name)
252251
}
253252

254253
err = removeOwnerFromPVCAnnotation(reconciler.Client, ctx, log.FromContext(context.TODO()), testPVC, replicationv1alpha1.VolumeReplicationNameAnnotation)

internal/controller/replication.storage/volumegroupreplication_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ func (r *VolumeGroupReplicationReconciler) updateFinalizerAndAnnotationOnPVCs(vg
602602

603603
// Annotate each new PVC with owner and add finalizer to it
604604
for _, pvc := range toAddPVCs {
605-
reqOwner := fmt.Sprintf("%s/%s", vgr.Namespace, vgr.Name)
606-
err := annotatePVCWithOwner(r.Client, r.ctx, r.log, reqOwner, &pvc, replicationv1alpha1.VolumeGroupReplicationNameAnnotation)
605+
err := annotatePVCWithOwner(r.Client, r.ctx, r.log, vgr.Name, &pvc, replicationv1alpha1.VolumeGroupReplicationNameAnnotation)
607606
if err != nil {
608607
r.log.Error(err, "Failed to add VGR owner annotation on PVC")
609608
return nil, err

internal/controller/replication.storage/volumegroupreplication_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controller
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"testing"
2322

2423
"github.com/stretchr/testify/assert"
@@ -185,8 +184,7 @@ func TestVolumeGroupReplication(t *testing.T) {
185184
assert.Equal(t, pvc.Name, mockVGRPersistentVolumeClaim.Name)
186185
}
187186
// Check PVC annotation
188-
expectedOwner := fmt.Sprintf("%s/%s", volumeGroupReplication.Namespace, volumeGroupReplication.Name)
189-
assert.Equal(t, expectedOwner, pvc.Annotations[replicationv1alpha1.VolumeGroupReplicationNameAnnotation])
187+
assert.Equal(t, volumeGroupReplication.Name, pvc.Annotations[replicationv1alpha1.VolumeGroupReplicationNameAnnotation])
190188
// Check VGRContent Created
191189
assert.NotEmpty(t, vgr.Spec.VolumeGroupReplicationContentName)
192190
} else {

internal/controller/replication.storage/volumereplication_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
233233
}
234234
switch instance.Spec.DataSource.Kind {
235235
case pvcDataSource:
236-
reqOwner := fmt.Sprintf("%s/%s", instance.Namespace, instance.Name)
237-
err = annotatePVCWithOwner(r.Client, ctx, logger, reqOwner, pvc, replicationv1alpha1.VolumeReplicationNameAnnotation)
236+
err = annotatePVCWithOwner(r.Client, ctx, logger, instance.Name, pvc, replicationv1alpha1.VolumeReplicationNameAnnotation)
238237
if err != nil {
239238
logger.Error(err, "Failed to annotate PVC owner")
240239
return ctrl.Result{}, err

0 commit comments

Comments
 (0)