mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-26 08:10:20 +00:00
cleanup: resolve exhaustive linter
This commit resolves exhaustive linter error. Updates: #2240 Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
parent
680a7bf411
commit
84c1fe52c7
11
e2e/pod.go
11
e2e/pod.go
@ -314,12 +314,13 @@ func waitForPodInRunningState(name, ns string, c kubernetes.Interface, t int, ex
|
|||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case v1.PodUnknown:
|
||||||
|
e2elog.Logf(
|
||||||
|
"%s app is in %s phase expected to be in Running state (%d seconds elapsed)",
|
||||||
|
name,
|
||||||
|
pod.Status.Phase,
|
||||||
|
int(time.Since(start).Seconds()))
|
||||||
}
|
}
|
||||||
e2elog.Logf(
|
|
||||||
"%s app is in %s phase expected to be in Running state (%d seconds elapsed)",
|
|
||||||
name,
|
|
||||||
pod.Status.Phase,
|
|
||||||
int(time.Since(start).Seconds()))
|
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package cephfs
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
)
|
)
|
||||||
@ -43,6 +42,23 @@ const (
|
|||||||
snapshotIsProtected = "yes"
|
snapshotIsProtected = "yes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// toError checks the state of the clone if it's not cephFSCloneComplete.
|
||||||
|
func (cs cephFSCloneState) toError() error {
|
||||||
|
switch cs {
|
||||||
|
case cephFSCloneComplete:
|
||||||
|
return nil
|
||||||
|
case cephFSCloneError:
|
||||||
|
return ErrInvalidClone
|
||||||
|
case cephFSCloneInprogress:
|
||||||
|
return ErrCloneInProgress
|
||||||
|
case cephFSClonePending:
|
||||||
|
return ErrClonePending
|
||||||
|
case cephFSCloneFailed:
|
||||||
|
return ErrCloneFailed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volOpt, parentvolOpt *volumeOptions) error {
|
func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volOpt, parentvolOpt *volumeOptions) error {
|
||||||
snapshotID := cloneID
|
snapshotID := cloneID
|
||||||
err := parentvolOpt.createSnapshot(ctx, snapshotID, volID)
|
err := parentvolOpt.createSnapshot(ctx, snapshotID, volID)
|
||||||
@ -95,42 +111,34 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
|||||||
|
|
||||||
cloneState, cloneErr := volOpt.getCloneState(ctx, cloneID)
|
cloneState, cloneErr := volOpt.getCloneState(ctx, cloneID)
|
||||||
if cloneErr != nil {
|
if cloneErr != nil {
|
||||||
|
util.ErrorLog(ctx, "failed to get clone state: %v", cloneErr)
|
||||||
return cloneErr
|
return cloneErr
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cloneState {
|
if cloneState != cephFSCloneComplete {
|
||||||
case cephFSCloneInprogress:
|
util.ErrorLog(ctx, "clone %s did not complete: %v", cloneID, cloneState.toError())
|
||||||
util.ErrorLog(ctx, "clone is in progress for %v", cloneID)
|
return cloneState.toError()
|
||||||
return ErrCloneInProgress
|
}
|
||||||
case cephFSClonePending:
|
// This is a work around to fix sizing issue for cloned images
|
||||||
util.ErrorLog(ctx, "clone is pending for %v", cloneID)
|
err = volOpt.resizeVolume(ctx, cloneID, volOpt.Size)
|
||||||
return ErrClonePending
|
if err != nil {
|
||||||
case cephFSCloneFailed:
|
util.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err)
|
||||||
util.ErrorLog(ctx, "clone failed for %v", cloneID)
|
return err
|
||||||
cloneFailedErr := fmt.Errorf("clone %s is in %s state", cloneID, cloneState)
|
}
|
||||||
return cloneFailedErr
|
// As we completed clone, remove the intermediate snap
|
||||||
case cephFSCloneComplete:
|
if err = parentvolOpt.unprotectSnapshot(ctx, snapshotID, volID); err != nil {
|
||||||
// This is a work around to fix sizing issue for cloned images
|
// In case the snap is already unprotected we get ErrSnapProtectionExist error code
|
||||||
err = volOpt.resizeVolume(ctx, cloneID, volOpt.Size)
|
// in that case we are safe and we could discard this error and we are good to go
|
||||||
if err != nil {
|
// ahead with deletion
|
||||||
util.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err)
|
if !errors.Is(err, ErrSnapProtectionExist) {
|
||||||
return err
|
util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapshotID, err)
|
||||||
}
|
|
||||||
// As we completed clone, remove the intermediate snap
|
|
||||||
if err = parentvolOpt.unprotectSnapshot(ctx, snapshotID, volID); err != nil {
|
|
||||||
// In case the snap is already unprotected we get ErrSnapProtectionExist error code
|
|
||||||
// in that case we are safe and we could discard this error and we are good to go
|
|
||||||
// ahead with deletion
|
|
||||||
if !errors.Is(err, ErrSnapProtectionExist) {
|
|
||||||
util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapshotID, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err = parentvolOpt.deleteSnapshot(ctx, snapshotID, volID); err != nil {
|
|
||||||
util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err = parentvolOpt.deleteSnapshot(ctx, snapshotID, volID); err != nil {
|
||||||
|
util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,25 +200,20 @@ func createCloneFromSnapshot(
|
|||||||
|
|
||||||
cloneState, err := volOptions.getCloneState(ctx, volumeID(vID.FsSubvolName))
|
cloneState, err := volOptions.getCloneState(ctx, volumeID(vID.FsSubvolName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
util.ErrorLog(ctx, "failed to get clone state: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cloneState {
|
if cloneState != cephFSCloneComplete {
|
||||||
case cephFSCloneInprogress:
|
return cloneState.toError()
|
||||||
return ErrCloneInProgress
|
}
|
||||||
case cephFSClonePending:
|
// The clonedvolume currently does not reflect the proper size due to an issue in cephfs
|
||||||
return ErrClonePending
|
// however this is getting addressed in cephfs and the parentvolume size will be reflected
|
||||||
case cephFSCloneFailed:
|
// in the new cloned volume too. Till then we are explicitly making the size set
|
||||||
return fmt.Errorf("clone %s is in %s state", vID.FsSubvolName, cloneState)
|
err = volOptions.resizeVolume(ctx, volumeID(vID.FsSubvolName), volOptions.Size)
|
||||||
case cephFSCloneComplete:
|
if err != nil {
|
||||||
// The clonedvolume currently does not reflect the proper size due to an issue in cephfs
|
util.ErrorLog(ctx, "failed to expand volume %s with error: %v", vID.FsSubvolName, err)
|
||||||
// however this is getting addressed in cephfs and the parentvolume size will be reflected
|
return err
|
||||||
// in the new cloned volume too. Till then we are explicitly making the size set
|
|
||||||
err = volOptions.resizeVolume(ctx, volumeID(vID.FsSubvolName), volOptions.Size)
|
|
||||||
if err != nil {
|
|
||||||
util.ErrorLog(ctx, "failed to expand volume %s with error: %v", vID.FsSubvolName, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,12 @@ var (
|
|||||||
// ErrClonePending is returned when snapshot clone state is `pending`
|
// ErrClonePending is returned when snapshot clone state is `pending`
|
||||||
ErrClonePending = errors.New("clone from snapshot is pending")
|
ErrClonePending = errors.New("clone from snapshot is pending")
|
||||||
|
|
||||||
|
// ErrInvalidClone is returned when the clone state is invalid
|
||||||
|
ErrInvalidClone = errors.New("invalid clone state")
|
||||||
|
|
||||||
|
// ErrCloneFailed is returned when the clone state is failed.
|
||||||
|
ErrCloneFailed = errors.New("clone from snapshot failed")
|
||||||
|
|
||||||
// ErrInvalidVolID is returned when a CSI passed VolumeID is not conformant to any known volume ID
|
// ErrInvalidVolID is returned when a CSI passed VolumeID is not conformant to any known volume ID
|
||||||
// formats.
|
// formats.
|
||||||
ErrInvalidVolID = errors.New("invalid VolumeID")
|
ErrInvalidVolID = errors.New("invalid VolumeID")
|
||||||
|
Loading…
Reference in New Issue
Block a user