This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
forked from ngrok/ngrok-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
153 lines (125 loc) · 4.58 KB
/
errors.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package errors
import (
"fmt"
"strings"
netv1 "k8s.io/api/networking/v1"
)
// Not all domains are reconciled yet and have a domain in their status
type NotAllDomainsReadyYetError struct{}
// Error returns the error message
func (e *NotAllDomainsReadyYetError) Error() string {
return "not all domains ready yet"
}
// NewNotAllDomainsReadyYetError returns a new NotAllDomainsReadyYetError
func NewNotAllDomainsReadyYetError() error {
return &NotAllDomainsReadyYetError{}
}
// IsNotAllDomainsReadyYet returns true if the error is a NotAllDomainsReadyYetError
func IsNotAllDomainsReadyYet(err error) bool {
_, ok := err.(*NotAllDomainsReadyYetError)
return ok
}
// ErrNotFoundInStore is meant to be used when an object is not found in the store so
// that the caller can decide what to do with it.
type ErrNotFoundInStore struct {
message string
}
// NewErrorNotFound returns a new ErrNotFoundInStore
func NewErrorNotFound(message string) ErrNotFoundInStore {
return ErrNotFoundInStore{message: message}
}
// Error: Stringer: returns the error message
func (e ErrNotFoundInStore) Error() string {
return e.message
}
// IsErrorNotFound: Reflect: returns true if the error is a ErrNotFoundInStore
func IsErrorNotFound(err error) bool {
_, ok := err.(ErrNotFoundInStore)
return ok
}
// ErrInvalidIngressClass is meant to be used when an ingress object has an invalid ingress class
type ErrDifferentIngressClass struct {
message string
}
// NewErrDifferentIngressClass returns a new ErrDifferentIngressClass
func NewErrDifferentIngressClass(ourIngressClasses []*netv1.IngressClass, foundIngressClass *string) ErrDifferentIngressClass {
msg := []string{"The controller will not reconcile this ingress object due to the ingress class mismatching."}
if foundIngressClass == nil {
msg = append(msg, "The ingress object does not have an ingress class set.")
} else {
msg = append(msg, fmt.Sprintf("The ingress object has an ingress class set to %s.", *foundIngressClass))
}
for _, ingressClass := range ourIngressClasses {
if ingressClass.Annotations["ingressclass.kubernetes.io/is-default-class"] == "true" {
msg = append(msg, fmt.Sprintf("This controller is the default ingress controller ingress class %s.", ingressClass.Name))
}
msg = append(msg, fmt.Sprintf("This controller is watching for the class %s", ingressClass.Name))
}
if len(ourIngressClasses) == 0 {
msg = append(msg, "There are no ngrok ingress classes registered in the cluster.")
}
return ErrDifferentIngressClass{message: strings.Join(msg, "\n")}
}
// Error: Stringer: returns the error message
func (e ErrDifferentIngressClass) Error() string {
if e.message == "" {
return "different ingress class"
}
return e.message
}
// IsErrDifferentIngressClass: Reflect: returns true if the error is a ErrDifferentIngressClass
func IsErrDifferentIngressClass(err error) bool {
_, ok := err.(ErrDifferentIngressClass)
return ok
}
// ErrInvalidIngressSpec is meant to be used when an ingress object has an invalid spec
type ErrInvalidIngressSpec struct {
errors []string
}
// NewErrInvalidIngressSpec returns a new ErrInvalidIngressSpec
func NewErrInvalidIngressSpec() ErrInvalidIngressSpec {
return ErrInvalidIngressSpec{}
}
// AddError adds an error to the list of errors
func (e *ErrInvalidIngressSpec) AddError(err string) {
e.errors = append(e.errors, err)
}
// HasErrors returns true if there are errors
func (e ErrInvalidIngressSpec) HasErrors() bool {
return len(e.errors) > 0
}
// Error: Stringer: returns the error message
func (e ErrInvalidIngressSpec) Error() string {
return fmt.Sprintf("invalid ingress spec: %s", e.errors)
}
// IsErrInvalidIngressSpec: Reflect: returns true if the error is a ErrInvalidIngressSpec
func IsErrInvalidIngressSpec(err error) bool {
_, ok := err.(ErrInvalidIngressSpec)
return ok
}
type ErrMissingRequiredSecret struct {
message string
}
func NewErrMissingRequiredSecret(message string) ErrMissingRequiredSecret {
return ErrMissingRequiredSecret{message: message}
}
func (e ErrMissingRequiredSecret) Error() string {
return fmt.Sprintf("missing required secret: %s", e.message)
}
// IsErrMissingRequiredSecret: Reflect: returns true if the error is a ErrMissingRequiredSecret
func IsErrMissingRequiredSecret(err error) bool {
_, ok := err.(ErrMissingRequiredSecret)
return ok
}
type ErrInvalidConfiguration struct {
cause error
}
func NewErrInvalidConfiguration(cause error) error {
return ErrInvalidConfiguration{cause: cause}
}
func (e ErrInvalidConfiguration) Error() string {
return fmt.Sprintf("invalid configuration: %s", e.cause.Error())
}
func (e ErrInvalidConfiguration) Unwrap() error {
return e.cause
}