Add new type for infeasible errors
This commit is contained in:
@@ -216,7 +216,7 @@ func NewActualStateOfWorld(
|
|||||||
attachedVolumes: make(map[v1.UniqueVolumeName]attachedVolume),
|
attachedVolumes: make(map[v1.UniqueVolumeName]attachedVolume),
|
||||||
foundDuringReconstruction: make(map[v1.UniqueVolumeName]map[volumetypes.UniquePodName]types.UID),
|
foundDuringReconstruction: make(map[v1.UniqueVolumeName]map[volumetypes.UniquePodName]types.UID),
|
||||||
volumePluginMgr: volumePluginMgr,
|
volumePluginMgr: volumePluginMgr,
|
||||||
volumesWithFinalExpansionErrors: sets.New[string](),
|
volumesWithFinalExpansionErrors: sets.New[v1.UniqueVolumeName](),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ func (c *csiPlugin) nodeExpandWithClient(
|
|||||||
failedConditionErr := fmt.Errorf("Expander.NodeExpand failed to expand the volume : %w", volumetypes.NewFailedPreconditionError(err.Error()))
|
failedConditionErr := fmt.Errorf("Expander.NodeExpand failed to expand the volume : %w", volumetypes.NewFailedPreconditionError(err.Error()))
|
||||||
return false, failedConditionErr
|
return false, failedConditionErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isInfeasibleError(err) {
|
||||||
|
infeasibleError := fmt.Errorf("Expander.NodeExpand failed to expand the volume: %w", volumetypes.NewInfeasibleError(err.Error()))
|
||||||
|
return false, infeasibleError
|
||||||
|
}
|
||||||
return false, fmt.Errorf("Expander.NodeExpand failed to expand the volume : %w", err)
|
return false, fmt.Errorf("Expander.NodeExpand failed to expand the volume : %w", err)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
@@ -135,3 +140,25 @@ func inUseError(err error) bool {
|
|||||||
// More info - https://github.com/container-storage-interface/spec/blob/master/spec.md#controllerexpandvolume-errors
|
// More info - https://github.com/container-storage-interface/spec/blob/master/spec.md#controllerexpandvolume-errors
|
||||||
return st.Code() == codes.FailedPrecondition
|
return st.Code() == codes.FailedPrecondition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsInfeasibleError returns true for grpc errors that are considered terminal in a way
|
||||||
|
// that they indicate CSI operation as infeasible.
|
||||||
|
// This function returns a subset of final errors. All infeasible errors are also final errors.
|
||||||
|
func isInfeasibleError(err error) bool {
|
||||||
|
st, ok := status.FromError(err)
|
||||||
|
if !ok {
|
||||||
|
// This is not gRPC error. The operation must have failed before gRPC
|
||||||
|
// method was called, otherwise we would get gRPC error.
|
||||||
|
// We don't know if any previous volume operation is in progress, be on the safe side.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch st.Code() {
|
||||||
|
case codes.InvalidArgument,
|
||||||
|
codes.OutOfRange,
|
||||||
|
codes.NotFound:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// All other errors mean that operation either did not
|
||||||
|
// even start or failed. It is for sure are not infeasible errors
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -102,6 +102,27 @@ func IsFailedPreconditionError(err error) bool {
|
|||||||
return errors.As(err, &failedPreconditionError)
|
return errors.As(err, &failedPreconditionError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InfeasibleError errors are a subset of OperationFinished or final error
|
||||||
|
// codes. In terms of CSI - this usually means that, the operation is not possible
|
||||||
|
// in current state with given arguments.
|
||||||
|
type InfeasibleError struct {
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err *InfeasibleError) Error() string {
|
||||||
|
return err.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInfeasibleError returns a new instance of InfeasibleError
|
||||||
|
func NewInfeasibleError(msg string) *InfeasibleError {
|
||||||
|
return &InfeasibleError{msg: msg}
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInfeasibleError(err error) bool {
|
||||||
|
var infeasibleError *InfeasibleError
|
||||||
|
return errors.As(err, &infeasibleError)
|
||||||
|
}
|
||||||
|
|
||||||
type OperationNotSupported struct {
|
type OperationNotSupported struct {
|
||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user