forked from giantswarm/operatorkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
96 lines (73 loc) · 2.03 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package controller
import (
"strings"
"github.com/giantswarm/microerror"
"k8s.io/apimachinery/pkg/api/errors"
)
var executionFailedError = µerror.Error{
Kind: "executionFailedError",
}
// IsExecutionFailed asserts executionFailedError.
func IsExecutionFailed(err error) bool {
return microerror.Cause(err) == executionFailedError
}
var invalidConfigError = µerror.Error{
Kind: "invalidConfigError",
}
// IsInvalidConfig asserts invalidConfigError.
func IsInvalidConfig(err error) bool {
return microerror.Cause(err) == invalidConfigError
}
var noResourceSetError = µerror.Error{
Kind: "noResourceSetError",
}
// IsNoResourceSet asserts noResourceSetError.
func IsNoResourceSet(err error) bool {
return microerror.Cause(err) == noResourceSetError
}
var portForwardError = µerror.Error{
Kind: "portForwardError",
}
// IsPortforward asserts portForwardError.
func IsPortforward(err error) bool {
if err == nil {
return false
}
c := microerror.Cause(err)
if c == portForwardError {
return true
}
if strings.Contains(c.Error(), "error copying from local connection to remote stream") {
return true
}
if strings.Contains(c.Error(), "error copying from remote stream to local connection") {
return true
}
return false
}
var statusForbiddenError = µerror.Error{
Kind: "statusForbiddenError",
}
// IsStatusForbiddenError asserts statusForbiddenError and apimachinery
// StatusError with StatusReasonForbidden.
func IsStatusForbidden(err error) bool {
if err == nil {
return false
}
c := microerror.Cause(err)
if c == statusForbiddenError {
return true
}
if errors.IsForbidden(c) {
return true
}
return false
}
var tooManyResourceSetsError = µerror.Error{
Desc: "Multiple resource sets to reconcile the same runtime object is not supported. There must only be one resource set configured.",
Kind: "tooManyResourceSetsError",
}
// IsTooManyResourceSets asserts tooManyResourceSetsError.
func IsTooManyResourceSets(err error) bool {
return microerror.Cause(err) == tooManyResourceSetsError
}