/
errors.go
99 lines (80 loc) · 3.09 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
/*
Copyright 2020 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package errors
import (
"fmt"
"k8s.io/apimachinery/pkg/types"
)
// ReconciliationError is describes a generic reconciliation error for a resource, it includes the Kind and NamespacedName
// of the resource, and any underlying Err.
type ReconciliationError struct {
Kind string
NamespacedName types.NamespacedName
Err error
}
func (e *ReconciliationError) Error() string {
return fmt.Sprintf("%s '%s' reconciliation failed: %v", e.Kind, e.NamespacedName.String(), e.Err)
}
func (e *ReconciliationError) Unwrap() error {
return e.Err
}
// ResourceNotReadyError describes an error in which a referred resource is not in a meta.ReadyCondition state,
// it includes the Kind and NamespacedName, and any underlying Err.
type ResourceNotReadyError struct {
Kind string
NamespacedName types.NamespacedName
Err error
}
func (e *ResourceNotReadyError) Error() string {
return fmt.Sprintf("%s resource '%s' is not ready", e.Kind, e.NamespacedName.String())
}
func (e *ResourceNotReadyError) Unwrap() error {
return e.Err
}
// ResourceNotFoundError describes an error in which a referred resource could not be found,
// it includes the Kind and NamespacedName, and any underlying Err.
type ResourceNotFoundError struct {
Kind string
NamespacedName types.NamespacedName
Err error
}
func (e *ResourceNotFoundError) Error() string {
return fmt.Sprintf("%s resource '%s' could not be found", e.Kind, e.NamespacedName.String())
}
// UnsupportedResourceKindError describes an error in which a referred resource is of an unsupported kind,
// it includes the Kind and NamespacedName of the resource, and any underlying Err.
type UnsupportedResourceKindError struct {
Kind string
NamespacedName types.NamespacedName
SupportedKinds []string
}
func (e *UnsupportedResourceKindError) Error() string {
err := fmt.Sprintf("source '%s' with kind %s is not supported", e.NamespacedName.String(), e.Kind)
if len(e.SupportedKinds) == 0 {
return err
}
return fmt.Sprintf("%s (must be one of: %q)", err, e.SupportedKinds)
}
// GarbageCollectionError is describes a garbage collection error for a resources, it includes the Kind and
// NamespacedName of the resource, and the underlying Err.
type GarbageCollectionError struct {
Kind string
NamespacedName types.NamespacedName
Err error
}
func (e *GarbageCollectionError) Error() string {
return fmt.Sprintf("failed to garbage collect %s '%s': %v", e.Kind, e.NamespacedName, e.Err)
}
func (e *GarbageCollectionError) Unwrap() error {
return e.Err
}