@@ -26,30 +26,68 @@ import (
2626 "github.com/arangodb/kube-arangodb/pkg/util/errors"
2727)
2828
29+ func isError (err error , precondition func (err error ) bool ) bool {
30+ if err == nil {
31+ return false
32+ }
33+
34+ if precondition (err ) {
35+ return true
36+ }
37+
38+ if c := errors .CauseWithNil (err ); c == err || c == nil {
39+ return false
40+ } else {
41+ return isError (c , precondition )
42+ }
43+ }
44+
2945// IsAlreadyExists returns true if the given error is or is caused by a
3046// kubernetes AlreadyExistsError,
3147func IsAlreadyExists (err error ) bool {
32- return apierrors .IsAlreadyExists (errors .Cause (err ))
48+ return isError (err , isAlreadyExistsC )
49+ }
50+
51+ func isAlreadyExistsC (err error ) bool {
52+ return apierrors .IsAlreadyExists (err )
3353}
3454
3555// IsConflict returns true if the given error is or is caused by a
3656// kubernetes ConflictError,
3757func IsConflict (err error ) bool {
38- return apierrors .IsConflict (errors .Cause (err ))
58+ return isError (err , isConflictC )
59+ }
60+
61+ func isConflictC (err error ) bool {
62+ return apierrors .IsConflict (err )
3963}
4064
4165// IsNotFound returns true if the given error is or is caused by a
4266// kubernetes NotFoundError,
4367func IsNotFound (err error ) bool {
44- return apierrors . IsNotFound ( errors . Cause ( err ) )
68+ return isError ( err , isNotFoundC )
4569}
4670
47- // IsNotFound returns true if the given error is or is caused by a
71+ func isNotFoundC (err error ) bool {
72+ return apierrors .IsNotFound (err )
73+ }
74+
75+ // IsInvalid returns true if the given error is or is caused by a
4876// kubernetes InvalidError,
4977func IsInvalid (err error ) bool {
5078 return apierrors .IsInvalid (errors .Cause (err ))
5179}
5280
81+ func isInvalidC (err error ) bool {
82+ return isError (err , isInvalidC )
83+ }
84+
85+ // IsForbiddenOrNotFound returns true if the given error is or is caused by a
86+ // kubernetes NotFound or Forbidden,
5387func IsForbiddenOrNotFound (err error ) bool {
88+ return isError (err , isForbiddenOrNotFoundC )
89+ }
90+
91+ func isForbiddenOrNotFoundC (err error ) bool {
5492 return apierrors .IsNotFound (err ) || apierrors .IsForbidden (err )
5593}
0 commit comments