Skip to content

Commit 7128196

Browse files
committed
f
1 parent 14aeb6a commit 7128196

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func getVolumesToDetachForVmFromVC(ctx context.Context,
152152

153153
pvcsToDetach := make(map[string]string)
154154
// Get all PVCs and their corresponding volumeID mapping from instance spec.
155-
volumeIdsInSpec, volumeNamesInSpec, err := getVolumeNameVolumeIdMapsInSpec(ctx, instance)
155+
volumeIdsInSpec, volumeNamesInSpec, err := getVolumeNameVolumeIdMapsInSpec(ctx, instance, client)
156156
if err != nil {
157157
log.Errorf("failed to get PVCs in spec. Err: %s", err)
158158
return pvcsToDetach, err
@@ -248,7 +248,8 @@ func deleteVolumeFromStatus(pvc string, instance *v1alpha1.CnsNodeVmBatchAttachm
248248
// 1. volumeID to PVC name
249249
// 2. VolumeName to PVC name
250250
func getVolumeNameVolumeIdMapsInSpec(ctx context.Context,
251-
instance *v1alpha1.CnsNodeVmBatchAttachment) (volumeIdsInSpec map[string]string,
251+
instance *v1alpha1.CnsNodeVmBatchAttachment,
252+
client client.Client) (volumeIdsInSpec map[string]string,
252253
volumeNamesInSpec map[string]string, err error) {
253254
log := logger.GetLogger(ctx)
254255

@@ -270,12 +271,13 @@ func getVolumeNameVolumeIdMapsInSpec(ctx context.Context,
270271
}
271272

272273
// getPvcsInSpec returns map of PVCs and their volumeIDs.
273-
func getPvcsInSpec(instance *v1alpha1.CnsNodeVmBatchAttachment) (map[string]string, error) {
274+
func getPvcsInSpec(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAttachment, client client.Client) (map[string]string, error) {
274275
pvcsInSpec := make(map[string]string)
275276
for _, volume := range instance.Spec.Volumes {
276277
namespacedPvcName := getNamespacedPvcName(instance.Namespace, volume.PersistentVolumeClaim.ClaimName)
277278
volumeId, ok := commonco.ContainerOrchestratorUtility.GetVolumeIDFromPVCName(namespacedPvcName)
278279
if !ok {
280+
279281
return pvcsInSpec, fmt.Errorf("failed to find volumeID for PVC %s", volume.PersistentVolumeClaim.ClaimName)
280282
}
281283
pvcsInSpec[volume.PersistentVolumeClaim.ClaimName] = volumeId
@@ -461,7 +463,7 @@ func getVolumesToDetach(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAt
461463

462464
if instance.DeletionTimestamp != nil {
463465
log.Debugf("Instance %s is being deleted, adding all volumes in spec to volumesToDetach list.", instance.Name)
464-
volumesToDetach, err := getPvcsInSpec(instance)
466+
volumesToDetach, err := getPvcsInSpec(ctx, instance, client)
465467
if err != nil {
466468
log.Errorf("failed to get volumes to detach from instance spec. Err: %s", err)
467469
return volumesToDetach, err

0 commit comments

Comments
 (0)