Skip to content

Commit 5b89e17

Browse files
authored
Merge pull request #19 from IBM/ashima
Fetch Namespace Dynamically In RecoverStaleVolume Controller
2 parents 0c39cc2 + 1618821 commit 5b89e17

File tree

10 files changed

+82
-91
lines changed

10 files changed

+82
-91
lines changed

.nancy-ignore

Whitespace-only changes.

config/manager/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
66
- name: controller
7-
newName: bhagyak1/ibm-object-csi-driver-operator
8-
newTag: apr1801
7+
newName: ashimagarg/csi
8+
newTag: "53"

config/samples/csi_v1alpha1_ibmobjectcsi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313
# and csi-provisioner, csi-attacher, csi-snapshotter and livenessprobe sidecars.
1414
controller:
1515
repository: icr.io/ibm/ibm-object-csi-driver
16-
tag: "v1.0.2-alpha"
16+
tag: "v1.0.3-alpha"
1717
imagePullPolicy: IfNotPresent
1818
resources:
1919
limits:
@@ -36,7 +36,7 @@ spec:
3636
# and csi-node-driver-registrar and livenessprobe sidecars.
3737
node:
3838
repository: icr.io/ibm/ibm-object-csi-driver
39-
tag: "v1.0.2-alpha"
39+
tag: "v1.0.3-alpha"
4040
imagePullPolicy: Always
4141
resources:
4242
limits:

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/ibmobjectcsi_controller_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
ibmObjectCSIReconcileRequest = reconcile.Request{
4040
NamespacedName: types.NamespacedName{
4141
Name: ibmObjectCSICRName,
42-
Namespace: ibmObjectCSICRNamespace,
42+
Namespace: TestNamespace,
4343
},
4444
}
4545

@@ -75,7 +75,7 @@ var (
7575
ibmObjectCSICR = &v1alpha1.IBMObjectCSI{
7676
ObjectMeta: metav1.ObjectMeta{
7777
Name: ibmObjectCSICRName,
78-
Namespace: ibmObjectCSICRNamespace,
78+
Namespace: TestNamespace,
7979
},
8080
Spec: v1alpha1.IBMObjectCSISpec{
8181
Controller: v1alpha1.IBMObjectCSIControllerSpec{
@@ -128,7 +128,7 @@ var (
128128
ibmObjectCSICRWithDeletionTS = &v1alpha1.IBMObjectCSI{
129129
ObjectMeta: metav1.ObjectMeta{
130130
Name: ibmObjectCSICRName,
131-
Namespace: ibmObjectCSICRNamespace,
131+
Namespace: TestNamespace,
132132
Finalizers: []string{ibmObjectCSIfinalizer},
133133
DeletionTimestamp: &currentTime,
134134
},
@@ -137,7 +137,7 @@ var (
137137
ibmObjectCSICRWithFinaliser = &v1alpha1.IBMObjectCSI{
138138
ObjectMeta: metav1.ObjectMeta{
139139
Name: ibmObjectCSICRName,
140-
Namespace: ibmObjectCSICRNamespace,
140+
Namespace: TestNamespace,
141141
Finalizers: []string{ibmObjectCSIfinalizer},
142142
},
143143
Spec: ibmObjectCSICR.Spec,
@@ -156,7 +156,7 @@ var (
156156
csiNode = &appsv1.DaemonSet{
157157
ObjectMeta: metav1.ObjectMeta{
158158
Name: config.GetNameForResource(config.CSINode, ibmObjectCSICRName),
159-
Namespace: ibmObjectCSICRNamespace,
159+
Namespace: TestNamespace,
160160
Annotations: annotations,
161161
},
162162
Spec: appsv1.DaemonSetSpec{
@@ -167,7 +167,7 @@ var (
167167
controllerDeployment = &appsv1.Deployment{
168168
ObjectMeta: metav1.ObjectMeta{
169169
Name: config.GetNameForResource(config.CSIController, ibmObjectCSICRName),
170-
Namespace: ibmObjectCSICRNamespace,
170+
Namespace: TestNamespace,
171171
Annotations: annotations,
172172
},
173173
Spec: appsv1.DeploymentSpec{
@@ -178,7 +178,7 @@ var (
178178
controllerPod = &corev1.Pod{
179179
ObjectMeta: metav1.ObjectMeta{
180180
Name: controllerDeployment.Name + "-pod",
181-
Namespace: ibmObjectCSICRNamespace,
181+
Namespace: TestNamespace,
182182
},
183183
}
184184

@@ -197,15 +197,15 @@ var (
197197
controllerSA = &corev1.ServiceAccount{
198198
ObjectMeta: metav1.ObjectMeta{
199199
Name: config.GetNameForResource(config.CSIControllerServiceAccount, ibmObjectCSICRName),
200-
Namespace: ibmObjectCSICRNamespace,
200+
Namespace: TestNamespace,
201201
},
202202
ImagePullSecrets: secrets,
203203
}
204204

205205
nodeSA = &corev1.ServiceAccount{
206206
ObjectMeta: metav1.ObjectMeta{
207207
Name: config.GetNameForResource(config.CSINodeServiceAccount, ibmObjectCSICRName),
208-
Namespace: ibmObjectCSICRNamespace,
208+
Namespace: TestNamespace,
209209
},
210210
ImagePullSecrets: secrets,
211211
}
@@ -218,7 +218,7 @@ var (
218218
{
219219
Kind: "ServiceAccount",
220220
Name: config.GetNameForResource(config.CSIControllerServiceAccount, ibmObjectCSICRName),
221-
Namespace: ibmObjectCSICRNamespace,
221+
Namespace: TestNamespace,
222222
},
223223
},
224224
RoleRef: rbacv1.RoleRef{
@@ -236,7 +236,7 @@ var (
236236
{
237237
Kind: "ServiceAccount",
238238
Name: config.GetNameForResource(config.CSIControllerServiceAccount, ibmObjectCSICRName),
239-
Namespace: ibmObjectCSICRNamespace,
239+
Namespace: TestNamespace,
240240
},
241241
},
242242
RoleRef: rbacv1.RoleRef{
@@ -254,7 +254,7 @@ var (
254254
{
255255
Kind: "ServiceAccount",
256256
Name: config.GetNameForResource(config.CSINodeServiceAccount, ibmObjectCSICRName),
257-
Namespace: ibmObjectCSICRNamespace,
257+
Namespace: TestNamespace,
258258
},
259259
},
260260
RoleRef: rbacv1.RoleRef{
@@ -441,7 +441,7 @@ func TestIBMObjectCSIReconcile(t *testing.T) {
441441
&corev1.Pod{
442442
ObjectMeta: metav1.ObjectMeta{
443443
Name: controllerDeployment.Name + "-pod2",
444-
Namespace: ibmObjectCSICRNamespace,
444+
Namespace: TestNamespace,
445445
},
446446
},
447447
},
@@ -791,7 +791,7 @@ func TestIBMObjectCSIReconcile(t *testing.T) {
791791

792792
for _, testcase := range testCases {
793793
t.Run(testcase.testCaseName, func(t *testing.T) {
794-
testLog.Info("Testcase being executed", "testcase", testcase.testCaseName)
794+
TestLog.Info("Testcase being executed", "testcase", testcase.testCaseName)
795795

796796
scheme := setupScheme()
797797
client := testcase.clientFunc(testcase.objects)
@@ -803,8 +803,8 @@ func TestIBMObjectCSIReconcile(t *testing.T) {
803803
ControllerHelper: common.NewControllerHelper(client),
804804
}
805805

806-
res, err := ibmObjectCSIReconciler.Reconcile(testCtx, ibmObjectCSIReconcileRequest)
807-
testLog.Info("Testcase return values", "result", res, "error", err)
806+
res, err := ibmObjectCSIReconciler.Reconcile(TestCtx, ibmObjectCSIReconcileRequest)
807+
TestLog.Info("Testcase return values", "result", res, "error", err)
808808

809809
assert.Equal(t, testcase.expectedResp, res)
810810

controllers/recoverstalevolume_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525
"time"
2626

27+
objectdriverv1alpha1 "github.com/IBM/ibm-object-csi-driver-operator/api/v1alpha1"
2728
appsv1 "k8s.io/api/apps/v1"
2829
corev1 "k8s.io/api/core/v1"
2930
k8serr "k8s.io/apimachinery/pkg/api/errors"
@@ -34,8 +35,6 @@ import (
3435
ctrl "sigs.k8s.io/controller-runtime"
3536
"sigs.k8s.io/controller-runtime/pkg/client"
3637
logf "sigs.k8s.io/controller-runtime/pkg/log"
37-
38-
objectdriverv1alpha1 "github.com/IBM/ibm-object-csi-driver-operator/api/v1alpha1"
3938
)
4039

4140
// RecoverStaleVolumeReconciler reconciles a RecoverStaleVolume object
@@ -52,7 +51,6 @@ type KubernetesClient struct {
5251

5352
var staleVolLog = logf.Log.WithName("recoverstalevolume_controller")
5453
var reconcileTime = 2 * time.Minute
55-
var csiOperatorNamespace = "ibm-object-csi-operator-system"
5654
var csiNodePodPrefix = "ibm-object-csi-node"
5755
var transportEndpointError = "transport endpoint is not connected"
5856
var kubeClient = createK8sClient
@@ -204,15 +202,15 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
204202
}
205203
reqLogger.Info("node-names maped with volumes and deployment pods", "nodeVolumeMap", nodeVolumePodMapping)
206204

207-
// Get Pods in csiOperatorNamespace ns
208-
var listOptions2 = &client.ListOptions{Namespace: csiOperatorNamespace}
205+
// Get Pods in operator ns
206+
var listOptions2 = &client.ListOptions{Namespace: req.Namespace}
209207
csiPodsList := &corev1.PodList{}
210208
err = r.List(ctx, csiPodsList, listOptions2)
211209
if err != nil {
212210
reqLogger.Error(err, "failed to fetch csi pods")
213211
return ctrl.Result{}, err
214212
}
215-
reqLogger.Info("Successfully fetched pods in csi-plugin-operator ns", "number-of-pods", len(csiPodsList.Items))
213+
reqLogger.Info("Successfully fetched pods in operator ns", "number-of-pods", len(csiPodsList.Items))
216214

217215
for ind := range csiPodsList.Items {
218216
pod := csiPodsList.Items[ind]
@@ -230,7 +228,7 @@ func (r *RecoverStaleVolumeReconciler) Reconcile(ctx context.Context, req ctrl.R
230228

231229
for nodeName, volumesData := range nodeVolumePodMapping {
232230
// Fetch volume stats from Logs of the Node Server Pod
233-
getVolStatsFromLogs, err := fetchVolumeStatsFromNodeServerLogs(ctx, csiNodeServerPods[nodeName], logTailLines, r.IsTest)
231+
getVolStatsFromLogs, err := fetchVolumeStatsFromNodeServerLogs(ctx, csiNodeServerPods[nodeName], req.Namespace, logTailLines, r.IsTest)
234232
if err != nil {
235233
return ctrl.Result{}, err
236234
}
@@ -305,7 +303,9 @@ func createK8sClient() (*KubernetesClient, error) {
305303
}, nil
306304
}
307305

308-
func fetchVolumeStatsFromNodeServerLogs(ctx context.Context, nodeServerPod string, logTailLines int64, isTest bool) (map[string]string, error) {
306+
func fetchVolumeStatsFromNodeServerLogs(ctx context.Context, nodeServerPod, namespace string, logTailLines int64,
307+
isTest bool) (map[string]string, error) {
308+
staleVolLog.Info("Input Parameters: ", "nodeServerPod", nodeServerPod, "namespace", namespace, "isTest", isTest)
309309
podLogOpts := &corev1.PodLogOptions{
310310
Container: csiNodePodPrefix,
311311
TailLines: &logTailLines,
@@ -315,7 +315,7 @@ func fetchVolumeStatsFromNodeServerLogs(ctx context.Context, nodeServerPod strin
315315
if err != nil {
316316
return nil, err
317317
}
318-
request := k8sClient.Clientset.CoreV1().Pods(csiOperatorNamespace).GetLogs(nodeServerPod, podLogOpts)
318+
request := k8sClient.Clientset.CoreV1().Pods(namespace).GetLogs(nodeServerPod, podLogOpts)
319319

320320
nodePodLogs, err := request.Stream(ctx)
321321
if err != nil {

controllers/recoverstalevolume_controller_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ var (
2929
recoverStaleVolumeReconcileRequest = reconcile.Request{
3030
NamespacedName: types.NamespacedName{
3131
Name: recoverStaleVolCRName,
32-
Namespace: recoverStaleVolCRNamespace,
32+
Namespace: TestNamespace,
3333
},
3434
}
3535

3636
recoverStaleVolumeCR = &v1alpha1.RecoverStaleVolume{
3737
ObjectMeta: metav1.ObjectMeta{
3838
Name: recoverStaleVolCRName,
39-
Namespace: recoverStaleVolCRNamespace,
39+
Namespace: TestNamespace,
4040
},
4141
Spec: v1alpha1.RecoverStaleVolumeSpec{
4242
NoOfLogLines: int64(100),
@@ -133,7 +133,7 @@ var (
133133
nodeServerPod1 = &corev1.Pod{
134134
ObjectMeta: metav1.ObjectMeta{
135135
Name: csiNodePodPrefix + "-pod1",
136-
Namespace: csiOperatorNamespace,
136+
Namespace: TestNamespace,
137137
},
138138
Spec: corev1.PodSpec{
139139
NodeName: testNode1,
@@ -143,7 +143,7 @@ var (
143143
nodeServerPod2 = &corev1.Pod{
144144
ObjectMeta: metav1.ObjectMeta{
145145
Name: csiNodePodPrefix + "-pod2",
146-
Namespace: csiOperatorNamespace,
146+
Namespace: TestNamespace,
147147
},
148148
Spec: corev1.PodSpec{
149149
NodeName: testNode2,
@@ -153,7 +153,7 @@ var (
153153
nodeServerPod3 = &corev1.Pod{
154154
ObjectMeta: metav1.ObjectMeta{
155155
Name: csiNodePodPrefix + "-pod3",
156-
Namespace: csiOperatorNamespace,
156+
Namespace: TestNamespace,
157157
},
158158
Spec: corev1.PodSpec{
159159
NodeName: testNode3,
@@ -382,7 +382,7 @@ func TestRecoverStaleVolumeReconcile(t *testing.T) {
382382

383383
for _, testcase := range testCases {
384384
t.Run(testcase.testCaseName, func(t *testing.T) {
385-
testLog.Info("Testcase being executed", "testcase", testcase.testCaseName)
385+
TestLog.Info("Testcase being executed", "testcase", testcase.testCaseName)
386386

387387
scheme := setupScheme()
388388
client := testcase.clientFunc(testcase.objects)
@@ -394,8 +394,8 @@ func TestRecoverStaleVolumeReconcile(t *testing.T) {
394394
IsTest: true,
395395
}
396396

397-
res, err := recoverStaleVolumeReconciler.Reconcile(testCtx, recoverStaleVolumeReconcileRequest)
398-
testLog.Info("Testcase return values", "result", res, "error", err)
397+
res, err := recoverStaleVolumeReconciler.Reconcile(TestCtx, recoverStaleVolumeReconcileRequest)
398+
TestLog.Info("Testcase return values", "result", res, "error", err)
399399

400400
assert.Equal(t, testcase.expectedResp, res)
401401

controllers/test_variables.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,26 @@ const (
2727
)
2828

2929
var (
30-
testLog = log.Log.WithName("test")
31-
testCtx = context.TODO()
30+
TestLog = log.Log.WithName("test")
31+
TestCtx = context.TODO()
32+
TestNamespace = "test-namespace"
3233

3334
currentTime = metav1.Now()
3435

35-
ibmObjectCSICRName = "test-csi-cr"
36-
ibmObjectCSICRNamespace = "test-namespace"
37-
ibmObjectCSIfinalizer = "ibmobjectcsi.objectdriver.csi.ibm.com"
38-
39-
recoverStaleVolCRName = "test-vol-cr"
40-
recoverStaleVolCRNamespace = "test-namespace"
41-
testDeploymentName = "test-deployment"
42-
testDeploymentNamespace = "default"
43-
testPVName1 = "test-pv-1"
44-
testPVName2 = "test-pv-2"
45-
testPVCName1 = "test-pvc-1"
46-
testPVCName2 = "test-pvc-2"
47-
testStorageClassName = "test-csi-storage-class"
48-
testNode1 = "test-node-1"
49-
testNode2 = "test-node-2"
50-
testNode3 = "test-node-3"
36+
ibmObjectCSICRName = "test-csi-cr"
37+
ibmObjectCSIfinalizer = "ibmobjectcsi.objectdriver.csi.ibm.com"
38+
39+
recoverStaleVolCRName = "test-vol-cr"
40+
testDeploymentName = "test-deployment"
41+
testDeploymentNamespace = "default"
42+
testPVName1 = "test-pv-1"
43+
testPVName2 = "test-pv-2"
44+
testPVCName1 = "test-pvc-1"
45+
testPVCName2 = "test-pvc-2"
46+
testStorageClassName = "test-csi-storage-class"
47+
testNode1 = "test-node-1"
48+
testNode2 = "test-node-2"
49+
testNode3 = "test-node-3"
5150
)
5251

5352
var testNodeServerPodLogs = `E0319 05:32:00.429871 1 nodeserver.go:245] NodeGetVolumeStats: error occurred while getting volume stats map[Error:transport endpoint is not connected VolumeId:test-pv-1]`

0 commit comments

Comments
 (0)