Skip to content

Commit c0f6587

Browse files
committed
fetch ns dynamically
Signed-off-by: Ashima-Ashima1 <[email protected]>
1 parent 16368c2 commit c0f6587

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

controllers/fake/client_list/nodeserverpod/client.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ import (
5858
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"
5959
)
6060

61-
var csiOperatorNamespace = "ibm-object-csi-operator-system"
62-
6361
type versionedTracker struct {
6462
testing.ObjectTracker
6563
scheme *runtime.Scheme
@@ -507,7 +505,7 @@ func (c *fakeClient) List(ctx context.Context, obj client.ObjectList, opts ...cl
507505

508506
switch obj.(type) {
509507
case *corev1.PodList:
510-
if listOpts.Namespace == csiOperatorNamespace {
508+
if strings.Contains(listOpts.Namespace, "test") {
511509
return errors.New("failed to list object")
512510
}
513511
}

controllers/recoverstalevolume_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ type KubernetesClient struct {
5252

5353
var staleVolLog = logf.Log.WithName("recoverstalevolume_controller")
5454
var reconcileTime = 2 * time.Minute
55-
var csiOperatorNamespace = "ibm-object-csi-operator-system"
5655
var csiNodePodPrefix = "ibm-object-csi-node"
5756
var transportEndpointError = "transport endpoint is not connected"
5857
var kubeClient = createK8sClient
@@ -204,8 +203,8 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
204203
}
205204
reqLogger.Info("node-names maped with volumes and deployment pods", "nodeVolumeMap", nodeVolumePodMapping)
206205

207-
// Get Pods in csiOperatorNamespace ns
208-
var listOptions2 = &client.ListOptions{Namespace: csiOperatorNamespace}
206+
// Get Pods in operator ns
207+
var listOptions2 = &client.ListOptions{Namespace: req.Namespace}
209208
csiPodsList := &corev1.PodList{}
210209
err = r.List(ctx, csiPodsList, listOptions2)
211210
if err != nil {
@@ -230,7 +229,7 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
230229

231230
for nodeName, volumesData := range nodeVolumePodMapping {
232231
// Fetch volume stats from Logs of the Node Server Pod
233-
getVolStatsFromLogs, err := fetchVolumeStatsFromNodeServerLogs(ctx, csiNodeServerPods[nodeName], logTailLines, r.IsTest)
232+
getVolStatsFromLogs, err := fetchVolumeStatsFromNodeServerLogs(ctx, csiNodeServerPods[nodeName], req.Namespace, logTailLines, r.IsTest)
234233
if err != nil {
235234
return ctrl.Result{}, err
236235
}
@@ -305,7 +304,7 @@ func createK8sClient() (*KubernetesClient, error) {
305304
}, nil
306305
}
307306

308-
func fetchVolumeStatsFromNodeServerLogs(ctx context.Context, nodeServerPod string, logTailLines int64, isTest bool) (map[string]string, error) {
307+
func fetchVolumeStatsFromNodeServerLogs(ctx context.Context, nodeServerPod, ns string, logTailLines int64, isTest bool) (map[string]string, error) {
309308
podLogOpts := &corev1.PodLogOptions{
310309
Container: csiNodePodPrefix,
311310
TailLines: &logTailLines,
@@ -315,7 +314,7 @@ func fetchVolumeStatsFromNodeServerLogs(ctx context.Context, nodeServerPod strin
315314
if err != nil {
316315
return nil, err
317316
}
318-
request := k8sClient.Clientset.CoreV1().Pods(csiOperatorNamespace).GetLogs(nodeServerPod, podLogOpts)
317+
request := k8sClient.Clientset.CoreV1().Pods(ns).GetLogs(nodeServerPod, podLogOpts)
319318

320319
nodePodLogs, err := request.Stream(ctx)
321320
if err != nil {

0 commit comments

Comments
 (0)