Skip to content

Commit caf53f8

Browse files
controller: update reconcilers for changes in connection API
This patch updates the reconcilers to adapt to the ability of handling errors returned by connection pool. Signed-off-by: Niraj Yadav <[email protected]>
1 parent 827008f commit caf53f8

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

internal/controller/csiaddons/encryptionkeyrotationjob_controller.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ func (r *EncryptionKeyRotationJobReconciler) rotateEncryptionKey(
278278
ctx context.Context,
279279
logger *logr.Logger,
280280
target *targetDetails) error {
281-
clientName, client := r.getClientByNode(target.driverName, target.nodeID)
281+
clientName, client, err := r.getClientByNode(target.driverName, target.nodeID)
282+
if err != nil {
283+
return err
284+
}
282285
if client == nil {
283286
return fmt.Errorf("node client not found for node id: %s", target.nodeID)
284287
}
@@ -292,7 +295,7 @@ func (r *EncryptionKeyRotationJobReconciler) rotateEncryptionKey(
292295
timedCtx, cFunc := context.WithTimeout(ctx, target.timeout)
293296
defer cFunc()
294297

295-
_, err := client.EncryptionKeyRotate(timedCtx, req)
298+
_, err = client.EncryptionKeyRotate(timedCtx, req)
296299
if err != nil {
297300
if status.Code(err) == codes.Unimplemented {
298301
logger.Info("encryptionkeyrotation not implemented by driver")
@@ -305,21 +308,24 @@ func (r *EncryptionKeyRotationJobReconciler) rotateEncryptionKey(
305308
return nil
306309
}
307310

308-
func (r *EncryptionKeyRotationJobReconciler) getClientByNode(driver, nodeID string) (string, proto.EncryptionKeyRotationClient) {
309-
conns := r.ConnPool.GetByNodeID(driver, nodeID)
311+
func (r *EncryptionKeyRotationJobReconciler) getClientByNode(driver, nodeID string) (string, proto.EncryptionKeyRotationClient, error) {
312+
conns, err := r.ConnPool.GetByNodeID(driver, nodeID)
313+
if err != nil {
314+
return "", nil, err
315+
}
310316
for k, v := range conns {
311317
for _, cap := range v.Capabilities {
312318
if cap.GetEncryptionKeyRotation() == nil {
313319
continue
314320
}
315321

316322
if cap.GetEncryptionKeyRotation().Type == identity.Capability_EncryptionKeyRotation_ENCRYPTIONKEYROTATION {
317-
return k, proto.NewEncryptionKeyRotationClient(v.Client)
323+
return k, proto.NewEncryptionKeyRotationClient(v.Client), nil
318324
}
319325
}
320326
}
321327

322-
return "", nil
328+
return "", nil, nil
323329
}
324330

325331
// SetupWithManager sets up the controller with the Manager.

internal/controller/csiaddons/persistentvolumeclaim_controller.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (r *PersistentVolumeClaimReconciler) checkDriverSupportCapability(
171171
logger *logr.Logger,
172172
annotations map[string]string,
173173
driverName string,
174-
cap Operation) (bool, bool) {
174+
cap Operation) (bool, bool, error) {
175175
driverSupportsCap := false
176176
capFound := false
177177

@@ -183,14 +183,17 @@ func (r *PersistentVolumeClaimReconciler) checkDriverSupportCapability(
183183
driverAnnotation = krCSIAddonsDriverAnnotation
184184
default:
185185
logger.Info("Unknown capability", "Capability", cap)
186-
return false, false
186+
return false, false, nil
187187
}
188188

189189
if drivers, ok := annotations[driverAnnotation]; ok && slices.Contains(strings.Split(drivers, ","), driverAnnotation) {
190190
driverSupportsCap = true
191191
}
192192

193-
conns := r.ConnPool.GetByNodeID(driverName, "")
193+
conns, err := r.ConnPool.GetByNodeID(driverName, "")
194+
if err != nil {
195+
return false, false, err
196+
}
194197
for _, conn := range conns {
195198
for _, c := range conn.Capabilities {
196199
switch cap {
@@ -203,20 +206,20 @@ func (r *PersistentVolumeClaimReconciler) checkDriverSupportCapability(
203206
}
204207

205208
if capFound {
206-
return false, true
209+
return false, true, nil
207210
}
208211
}
209212
}
210213

211214
// If the driver supports the capability but the capability is not found in connection pool,
212215
if driverSupportsCap {
213216
logger.Info(fmt.Sprintf("Driver supports %s but driver is not registered in the connection pool, Requeuing request", cap), "DriverName", driverName)
214-
return true, false
217+
return true, false, nil
215218
}
216219

217220
// If the driver does not support the capability, skip requeue
218221
logger.Info(fmt.Sprintf("Driver does not support %s, skip Requeue", cap), "DriverName", driverName)
219-
return false, false
222+
return false, false, nil
220223
}
221224

222225
// determineScheduleAndRequeue determines the schedule from annotations.
@@ -957,15 +960,21 @@ func (r *PersistentVolumeClaimReconciler) getScheduleFromNS(
957960
// Depending on requeue value, it will return ErrorConnNotFoundRequeueNeeded.
958961
switch annotationKey {
959962
case krcJobScheduleTimeAnnotation:
960-
requeue, keyRotationSupported := r.checkDriverSupportCapability(logger, ns.Annotations, driverName, keyRotationOp)
963+
requeue, keyRotationSupported, err := r.checkDriverSupportCapability(logger, ns.Annotations, driverName, keyRotationOp)
964+
if err != nil {
965+
return "", err
966+
}
961967
if keyRotationSupported {
962968
return schedule, nil
963969
}
964970
if requeue {
965971
return "", ErrConnNotFoundRequeueNeeded
966972
}
967973
case rsCronJobScheduleTimeAnnotation:
968-
requeue, supportReclaimspace := r.checkDriverSupportCapability(logger, ns.Annotations, driverName, relciamSpaceOp)
974+
requeue, supportReclaimspace, err := r.checkDriverSupportCapability(logger, ns.Annotations, driverName, relciamSpaceOp)
975+
if err != nil {
976+
return "", err
977+
}
969978
if supportReclaimspace {
970979
// if driver supports space reclamation,
971980
// return schedule from ns annotation.

internal/controller/csiaddons/reclaimspacejob_controller.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -366,20 +366,23 @@ func (r *ReclaimSpaceJobReconciler) getLeadingRSClient(
366366

367367
// getRSClientByNode returns ReclaimSpaceClient given driverName and nodeID.
368368
func (r *ReclaimSpaceJobReconciler) getRSClientByNode(
369-
driverName, nodeID string) (string, proto.ReclaimSpaceClient) {
370-
conns := r.ConnPool.GetByNodeID(driverName, nodeID)
369+
driverName, nodeID string) (string, proto.ReclaimSpaceClient, error) {
370+
conns, err := r.ConnPool.GetByNodeID(driverName, nodeID)
371+
if err != nil {
372+
return "", nil, err
373+
}
371374
for k, v := range conns {
372375
for _, cap := range v.Capabilities {
373376
if cap.GetReclaimSpace() == nil {
374377
continue
375378
}
376379
if cap.GetReclaimSpace().Type == identity.Capability_ReclaimSpace_ONLINE {
377-
return k, proto.NewReclaimSpaceClient(v.Client)
380+
return k, proto.NewReclaimSpaceClient(v.Client), nil
378381
}
379382
}
380383
}
381384

382-
return "", nil
385+
return "", nil, nil
383386
}
384387

385388
// controllerReclaimSpace makes controller reclaim space request if controller client is found
@@ -426,9 +429,12 @@ func (r *ReclaimSpaceJobReconciler) nodeReclaimSpace(
426429
ctx context.Context,
427430
logger *logr.Logger,
428431
target *targetDetails) (*int64, error) {
429-
clientName, nodeClient := r.getRSClientByNode(
432+
clientName, nodeClient, err := r.getRSClientByNode(
430433
target.driverName,
431434
target.nodeID)
435+
if err != nil {
436+
return nil, err
437+
}
432438
if nodeClient == nil {
433439
return nil, fmt.Errorf("node Client not found for %q nodeID", target.nodeID)
434440
}

0 commit comments

Comments
 (0)