@@ -34,6 +34,7 @@ import (
3434 mount "k8s.io/mount-utils"
3535
3636 "github.com/ceph/ceph-csi/internal/util/k8s"
37+ "github.com/ceph/ceph-csi/internal/util/log"
3738)
3839
3940// Driver types to identify type of driver running.
@@ -349,7 +350,8 @@ func GetControllerPublishSecretRef(volumeId, driverType string) (string, string,
349350 )
350351 err := vi .DecomposeCSIID (volumeId )
351352 if err != nil {
352- return secretName , secretNamespace , fmt .Errorf ("failed to decode volume ID (%s): %w" , volumeId , err )
353+ return secretName , secretNamespace , fmt .Errorf ("failed to decode volume ID (%s): %w" ,
354+ volumeId , errors .Join (ErrInvalidVolID , err ))
353355 }
354356
355357 secretName , secretNamespace , err = getControllerPublishSecretRef (vi .ClusterID , driverType )
@@ -395,6 +397,35 @@ func GetControllerPublishSecretRef(volumeId, driverType string) (string, string,
395397 return secretName , secretNamespace , nil
396398}
397399
400+ // GetControllerPublishSecrets resolves secrets for a controller publish/unpublish operation.
401+ // If reqSecrets is non-nil, return it. Otherwise secrets are fetched from the CSI config.
402+ // When the second return value is true the caller should return early with no error.
403+ func GetControllerPublishSecrets (
404+ ctx context.Context ,
405+ reqSecrets map [string ]string ,
406+ volumeID , driverType string ,
407+ ) (map [string ]string , bool , error ) {
408+ if reqSecrets != nil {
409+ return reqSecrets , false , nil
410+ }
411+ secretName , secretNamespace , err := GetControllerPublishSecretRef (volumeID , driverType )
412+ if errors .Is (err , ErrInvalidVolID ) || errors .Is (err , ErrConfigNotFound ) {
413+ // Possibly the volume is a static/older volume. In this case, we have nothing to do.
414+ // Even if it's not a static/older volume, we should skip handling it because
415+ // we have no way to process handling anyway.
416+ log .WarningLog (ctx , "should skip handling this volume: %v" , err )
417+ return nil , true , nil
418+ }
419+ if err != nil {
420+ return nil , false , fmt .Errorf ("failed to get controller publish secret ref: %w" , err )
421+ }
422+ secrets , err := k8s .GetSecret (secretName , secretNamespace )
423+ if err != nil {
424+ return nil , false , fmt .Errorf ("failed to get controller publish secret from k8s: %w" , err )
425+ }
426+ return secrets , false , nil
427+ }
428+
398429func getControllerPublishSecretRef (clusterId , driverType string ) (string , string , error ) {
399430 var (
400431 err error
0 commit comments