Skip to content

Commit 285800f

Browse files
committed
fix code
Signed-off-by: Ashima-Ashima1 <[email protected]>
1 parent 73d0a2f commit 285800f

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

controllers/internal/crutils/k8s-resource-ops.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ func (op *K8sResourceOps) ListPod() (*corev1.PodList, error) {
4242
return podList, err
4343
}
4444

45-
func (op *K8sResourceOps) GetPVC(name string) (*corev1.PersistentVolumeClaim, error) {
46-
pvc := &corev1.PersistentVolumeClaim{}
47-
err := op.Get(op.Ctx, types.NamespacedName{Name: name, Namespace: op.Namespace}, pvc)
48-
return pvc, err
49-
}
50-
5145
func (op *K8sResourceOps) ListPVC() (*corev1.PersistentVolumeClaimList, error) {
5246
var listOptions = &client.ListOptions{Namespace: op.Namespace}
5347
pvcList := &corev1.PersistentVolumeClaimList{}

controllers/recoverstalevolume_controller.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
106106
reqLogger.Info("Data Requested", "namespace", namespace, "deployments", deployments)
107107

108108
k8sOps := &crutils.K8sResourceOps{
109-
Client: r.Client,
110-
Ctx: ctx,
109+
Client: r.Client,
110+
Ctx: ctx,
111+
Namespace: namespace,
111112
}
112113

113114
// If applications are not set, then fetch all deployments from given ns
@@ -288,32 +289,23 @@ func fetchCSIPVCAndPVNames(k8sOps *crutils.K8sResourceOps, log logr.Logger) (map
288289

289290
reqData := map[string]string{}
290291

291-
for _, pvcData := range pvcList.Items {
292-
pvcName := pvcData.Name
293-
pvc, err := k8sOps.GetPVC(pvcName)
294-
if err != nil {
295-
if k8serr.IsNotFound(err) {
296-
log.Info("PVC not found.")
297-
continue
298-
}
299-
log.Error(err, "failed to get pvc")
300-
return nil, err
301-
}
292+
for _, pvc := range pvcList.Items {
293+
log.Info("PVC Found", "pvc-name", pvc.Name, "namespace", pvc.Namespace)
302294

303295
storageClassName := pvc.Spec.StorageClassName
304296
if storageClassName == nil {
305-
log.Info("PVC does not have any storageClass", "pvc-name", pvcName)
297+
log.Info("PVC does not have any storageClass", "pvc-name", pvc.Name)
306298
continue
307299
}
308300

309301
scName := *storageClassName
310302
if scName == "" {
311-
log.Info("PVC does not have any storageClass", "pvc-name", pvcName)
303+
log.Info("PVC does not have any storageClass", "pvc-name", pvc.Name)
312304
continue
313305
}
314306

315307
if strings.HasPrefix(scName, constants.StorageClassPrefix) && strings.HasSuffix(scName, constants.StorageClassSuffix) {
316-
reqData[pvcName] = pvc.Spec.VolumeName
308+
reqData[pvc.Name] = pvc.Spec.VolumeName
317309
}
318310
}
319311

0 commit comments

Comments
 (0)