...
1
16
17
18 package types
19
20 import (
21 "errors"
22
23 "k8s.io/apimachinery/pkg/types"
24 "k8s.io/apimachinery/pkg/util/runtime"
25 "k8s.io/mount-utils"
26 )
27
28
29 type UniquePodName types.UID
30
31
32 type UniquePVCName types.UID
33
34
35
36 type GeneratedOperations struct {
37
38 OperationName string
39 OperationFunc func() (context OperationContext)
40 EventRecorderFunc func(*error)
41 CompleteFunc func(CompleteFuncParam)
42 }
43
44 type OperationContext struct {
45 EventErr error
46 DetailedErr error
47 Migrated bool
48 }
49
50 func NewOperationContext(eventErr, detailedErr error, migrated bool) OperationContext {
51 return OperationContext{
52 EventErr: eventErr,
53 DetailedErr: detailedErr,
54 Migrated: migrated,
55 }
56 }
57
58 type CompleteFuncParam struct {
59 Err *error
60 Migrated *bool
61 }
62
63
64 func (o *GeneratedOperations) Run() (eventErr, detailedErr error) {
65 var context OperationContext
66 if o.CompleteFunc != nil {
67 c := CompleteFuncParam{
68 Err: &context.DetailedErr,
69 Migrated: &context.Migrated,
70 }
71 defer o.CompleteFunc(c)
72 }
73 if o.EventRecorderFunc != nil {
74 defer o.EventRecorderFunc(&eventErr)
75 }
76
77 defer runtime.RecoverFromPanic(&detailedErr)
78
79 context = o.OperationFunc()
80 return context.EventErr, context.DetailedErr
81 }
82
83
84
85 type FailedPrecondition struct {
86 msg string
87 }
88
89 func (err *FailedPrecondition) Error() string {
90 return err.msg
91 }
92
93
94 func NewFailedPreconditionError(msg string) *FailedPrecondition {
95 return &FailedPrecondition{msg: msg}
96 }
97
98
99
100 func IsFailedPreconditionError(err error) bool {
101 var failedPreconditionError *FailedPrecondition
102 return errors.As(err, &failedPreconditionError)
103 }
104
105 type OperationNotSupported struct {
106 msg string
107 }
108
109 func (err *OperationNotSupported) Error() string {
110 return err.msg
111 }
112
113 func NewOperationNotSupportedError(msg string) *OperationNotSupported {
114 return &OperationNotSupported{msg: msg}
115 }
116
117 func IsOperationNotSupportedError(err error) bool {
118 var operationNotSupportedError *OperationNotSupported
119 return errors.As(err, &operationNotSupportedError)
120 }
121
122
123
124 type TransientOperationFailure struct {
125 msg string
126 }
127
128 func (err *TransientOperationFailure) Error() string {
129 return err.msg
130 }
131
132
133 func NewTransientOperationFailure(msg string) *TransientOperationFailure {
134 return &TransientOperationFailure{msg: msg}
135 }
136
137
138
139 type UncertainProgressError struct {
140 msg string
141 }
142
143 func (err *UncertainProgressError) Error() string {
144 return err.msg
145 }
146
147
148 func NewUncertainProgressError(msg string) *UncertainProgressError {
149 return &UncertainProgressError{msg: msg}
150 }
151
152
153
154 func IsOperationFinishedError(err error) bool {
155 if _, ok := err.(*UncertainProgressError); ok {
156 return false
157 }
158 if _, ok := err.(*TransientOperationFailure); ok {
159 return false
160 }
161 return true
162 }
163
164
165
166 func IsFilesystemMismatchError(err error) bool {
167 mountError := mount.MountError{}
168 return errors.As(err, &mountError) && mountError.Type == mount.FilesystemMismatch
169 }
170
171
172
173 func IsUncertainProgressError(err error) bool {
174 if _, ok := err.(*UncertainProgressError); ok {
175 return true
176 }
177 return false
178 }
179
180 const (
181
182
183
184 VolumeResizerKey = "volume.kubernetes.io/storage-resizer"
185 )
186
View as plain text