mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
cleanup: address golangci 'funcorder' linter problems
The new 'funcorder' linter expects all public functions to be placed before private functions of a struct. Many private functions needed moving further down into their files. Some files had many issues reported. To reduce the churn in those files, they have been annotated with a `//nolint:funcorder` comment. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
0907f39d95
commit
0a22e3a186
@ -60,6 +60,103 @@ func (r *ReconcilePersistentVolume) Add(mgr manager.Manager, config ctrl.Config)
|
||||
return add(mgr, newPVReconciler(mgr, config))
|
||||
}
|
||||
|
||||
// Reconcile reconciles the PersistentVolume object and creates a new omap entries
|
||||
// for the volume.
|
||||
func (r *ReconcilePersistentVolume) Reconcile(ctx context.Context,
|
||||
request reconcile.Request,
|
||||
) (reconcile.Result, error) {
|
||||
pv := &corev1.PersistentVolume{}
|
||||
err := r.client.Get(ctx, request.NamespacedName, pv)
|
||||
if err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
// Check if the object is under deletion
|
||||
if !pv.GetDeletionTimestamp().IsZero() {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
err = r.reconcilePV(ctx, pv)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
// reconcilePV will extract the image details from the pv spec and regenerates
|
||||
// the omap data.
|
||||
func (r *ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime.Object) error {
|
||||
pv, ok := obj.(*corev1.PersistentVolume)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if pv.Spec.CSI == nil || pv.Spec.CSI.Driver != r.config.DriverName {
|
||||
return nil
|
||||
}
|
||||
// PV is not attached to any PVC
|
||||
if pv.Spec.ClaimRef == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pvcNamespace := pv.Spec.ClaimRef.Namespace
|
||||
requestName := pv.Name
|
||||
volumeHandler := pv.Spec.CSI.VolumeHandle
|
||||
secretName := ""
|
||||
secretNamespace := ""
|
||||
// check static volume
|
||||
static := checkStaticVolume(pv)
|
||||
// if the volume is static, dont generate OMAP data
|
||||
if static {
|
||||
return nil
|
||||
}
|
||||
if pv.Spec.CSI.ControllerExpandSecretRef != nil {
|
||||
secretName = pv.Spec.CSI.ControllerExpandSecretRef.Name
|
||||
secretNamespace = pv.Spec.CSI.ControllerExpandSecretRef.Namespace
|
||||
} else if pv.Spec.CSI.NodeStageSecretRef != nil {
|
||||
secretName = pv.Spec.CSI.NodeStageSecretRef.Name
|
||||
secretNamespace = pv.Spec.CSI.NodeStageSecretRef.Namespace
|
||||
}
|
||||
|
||||
// Take lock to process only one volumeHandle at a time.
|
||||
if ok := r.Locks.TryAcquire(pv.Spec.CSI.VolumeHandle); !ok {
|
||||
return fmt.Errorf(util.VolumeOperationAlreadyExistsFmt, pv.Spec.CSI.VolumeHandle)
|
||||
}
|
||||
defer r.Locks.Release(pv.Spec.CSI.VolumeHandle)
|
||||
|
||||
cr, err := r.getCredentials(ctx, secretName, secretNamespace)
|
||||
if err != nil {
|
||||
log.ErrorLogMsg("failed to get credentials from secret %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
defer cr.DeleteCredentials()
|
||||
|
||||
rbdVolID, err := rbd.RegenerateJournal(
|
||||
pv.Spec.CSI.VolumeAttributes,
|
||||
pv.Spec.ClaimRef.Name,
|
||||
volumeHandler,
|
||||
requestName,
|
||||
pvcNamespace,
|
||||
r.config.ClusterName,
|
||||
r.config.InstanceID,
|
||||
r.config.SetMetadata,
|
||||
cr)
|
||||
if err != nil {
|
||||
log.ErrorLogMsg("failed to regenerate journal %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
if rbdVolID != volumeHandler {
|
||||
log.DebugLog(ctx, "volumeHandler changed from %s to %s", volumeHandler, rbdVolID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// newReconciler returns a ReconcilePersistentVolume.
|
||||
func newPVReconciler(mgr manager.Manager, config ctrl.Config) reconcile.Reconciler {
|
||||
r := &ReconcilePersistentVolume{
|
||||
@ -133,100 +230,3 @@ func (r *ReconcilePersistentVolume) getCredentials(
|
||||
func checkStaticVolume(pv *corev1.PersistentVolume) bool {
|
||||
return pv.Spec.CSI.VolumeAttributes["staticVolume"] == "true"
|
||||
}
|
||||
|
||||
// reconcilePV will extract the image details from the pv spec and regenerates
|
||||
// the omap data.
|
||||
func (r *ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime.Object) error {
|
||||
pv, ok := obj.(*corev1.PersistentVolume)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if pv.Spec.CSI == nil || pv.Spec.CSI.Driver != r.config.DriverName {
|
||||
return nil
|
||||
}
|
||||
// PV is not attached to any PVC
|
||||
if pv.Spec.ClaimRef == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pvcNamespace := pv.Spec.ClaimRef.Namespace
|
||||
requestName := pv.Name
|
||||
volumeHandler := pv.Spec.CSI.VolumeHandle
|
||||
secretName := ""
|
||||
secretNamespace := ""
|
||||
// check static volume
|
||||
static := checkStaticVolume(pv)
|
||||
// if the volume is static, dont generate OMAP data
|
||||
if static {
|
||||
return nil
|
||||
}
|
||||
if pv.Spec.CSI.ControllerExpandSecretRef != nil {
|
||||
secretName = pv.Spec.CSI.ControllerExpandSecretRef.Name
|
||||
secretNamespace = pv.Spec.CSI.ControllerExpandSecretRef.Namespace
|
||||
} else if pv.Spec.CSI.NodeStageSecretRef != nil {
|
||||
secretName = pv.Spec.CSI.NodeStageSecretRef.Name
|
||||
secretNamespace = pv.Spec.CSI.NodeStageSecretRef.Namespace
|
||||
}
|
||||
|
||||
// Take lock to process only one volumeHandle at a time.
|
||||
if ok := r.Locks.TryAcquire(pv.Spec.CSI.VolumeHandle); !ok {
|
||||
return fmt.Errorf(util.VolumeOperationAlreadyExistsFmt, pv.Spec.CSI.VolumeHandle)
|
||||
}
|
||||
defer r.Locks.Release(pv.Spec.CSI.VolumeHandle)
|
||||
|
||||
cr, err := r.getCredentials(ctx, secretName, secretNamespace)
|
||||
if err != nil {
|
||||
log.ErrorLogMsg("failed to get credentials from secret %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
defer cr.DeleteCredentials()
|
||||
|
||||
rbdVolID, err := rbd.RegenerateJournal(
|
||||
pv.Spec.CSI.VolumeAttributes,
|
||||
pv.Spec.ClaimRef.Name,
|
||||
volumeHandler,
|
||||
requestName,
|
||||
pvcNamespace,
|
||||
r.config.ClusterName,
|
||||
r.config.InstanceID,
|
||||
r.config.SetMetadata,
|
||||
cr)
|
||||
if err != nil {
|
||||
log.ErrorLogMsg("failed to regenerate journal %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
if rbdVolID != volumeHandler {
|
||||
log.DebugLog(ctx, "volumeHandler changed from %s to %s", volumeHandler, rbdVolID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reconcile reconciles the PersistentVolume object and creates a new omap entries
|
||||
// for the volume.
|
||||
func (r *ReconcilePersistentVolume) Reconcile(ctx context.Context,
|
||||
request reconcile.Request,
|
||||
) (reconcile.Result, error) {
|
||||
pv := &corev1.PersistentVolume{}
|
||||
err := r.client.Get(ctx, request.NamespacedName, pv)
|
||||
if err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
// Check if the object is under deletion
|
||||
if !pv.GetDeletionTimestamp().IsZero() {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
err = r.reconcilePV(ctx, pv)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user