github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/controller/install/errors.go (about) 1 package install 2 3 const ( 4 StrategyErrReasonComponentMissing = "ComponentMissing" 5 StrategyErrReasonAnnotationsMissing = "AnnotationsMissing" 6 StrategyErrReasonWaiting = "Waiting" 7 StrategyErrReasonInvalidStrategy = "InvalidStrategy" 8 StrategyErrReasonTimeout = "Timeout" 9 StrategyErrReasonUnknown = "Unknown" 10 StrategyErrBadPatch = "PatchUnsuccessful" 11 StrategyErrDeploymentUpdated = "DeploymentUpdated" 12 StrategyErrInsufficientPermissions = "InsufficentPermissions" 13 ) 14 15 // unrecoverableErrors are the set of errors that mean we can't recover an install strategy 16 var unrecoverableErrors = map[string]struct{}{ 17 StrategyErrReasonInvalidStrategy: {}, 18 StrategyErrReasonTimeout: {}, 19 StrategyErrBadPatch: {}, 20 StrategyErrInsufficientPermissions: {}, 21 } 22 23 // StrategyError is used to represent error types for install strategies 24 type StrategyError struct { 25 Reason string 26 Message string 27 } 28 29 var _ error = StrategyError{} 30 31 // Error implements the Error interface. 32 func (e StrategyError) Error() string { 33 return e.Message 34 } 35 36 // IsErrorUnrecoverable reports if a given strategy error is one of the predefined unrecoverable types 37 func IsErrorUnrecoverable(err error) bool { 38 if err == nil { 39 return false 40 } 41 _, ok := unrecoverableErrors[ReasonForError(err)] 42 return ok 43 } 44 45 func ReasonForError(err error) string { 46 switch t := err.(type) { 47 case StrategyError: 48 return t.Reason 49 case *StrategyError: 50 return t.Reason 51 } 52 return StrategyErrReasonUnknown 53 }