|
7 | 7 | "sort"
|
8 | 8 | "strings"
|
9 | 9 |
|
| 10 | + kapi "k8s.io/kubernetes/pkg/api" |
| 11 | + |
10 | 12 | "github.com/docker/distribution/registry/api/errcode"
|
11 | 13 | "github.com/golang/glog"
|
12 | 14 |
|
@@ -206,3 +208,60 @@ func TryProtocolsWithRegistryURL(registry string, allowInsecure bool, action fun
|
206 | 208 | type retryPath struct{ err error }
|
207 | 209 |
|
208 | 210 | func (rp *retryPath) Error() string { return rp.err.Error() }
|
| 211 | + |
| 212 | +// ErrBadReference denotes an invalid reference to image, imagestreamtag or imagestreamimage stored in a |
| 213 | +// particular object. The object is identified by kind, namespace and name. |
| 214 | +type ErrBadReference struct { |
| 215 | + kind string |
| 216 | + namespace string |
| 217 | + name string |
| 218 | + targetKind string |
| 219 | + reference string |
| 220 | + reason string |
| 221 | +} |
| 222 | + |
| 223 | +func newErrBadReferenceToImage(reference string, obj *kapi.ObjectReference, reason string) error { |
| 224 | + kind := "<UnknownType>" |
| 225 | + namespace := "" |
| 226 | + name := "<unknown-name>" |
| 227 | + if obj != nil { |
| 228 | + kind = obj.Kind |
| 229 | + namespace = obj.Namespace |
| 230 | + name = obj.Name |
| 231 | + } |
| 232 | + |
| 233 | + return &ErrBadReference{ |
| 234 | + kind: kind, |
| 235 | + namespace: namespace, |
| 236 | + name: name, |
| 237 | + reference: reference, |
| 238 | + reason: reason, |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +func newErrBadReferenceTo(targetKind, reference string, obj *kapi.ObjectReference, reason string) error { |
| 243 | + return &ErrBadReference{ |
| 244 | + kind: obj.Kind, |
| 245 | + namespace: obj.Namespace, |
| 246 | + name: obj.Name, |
| 247 | + targetKind: targetKind, |
| 248 | + reference: reference, |
| 249 | + reason: reason, |
| 250 | + } |
| 251 | +} |
| 252 | + |
| 253 | +func (e *ErrBadReference) Error() string { |
| 254 | + return e.String() |
| 255 | +} |
| 256 | + |
| 257 | +func (e *ErrBadReference) String() string { |
| 258 | + name := e.name |
| 259 | + if len(e.namespace) > 0 { |
| 260 | + name = e.namespace + "/" + name |
| 261 | + } |
| 262 | + targetKind := "docker image" |
| 263 | + if len(e.targetKind) > 0 { |
| 264 | + targetKind = e.targetKind |
| 265 | + } |
| 266 | + return fmt.Sprintf("%s[%s]: invalid %s reference %q: %s", e.kind, name, targetKind, e.reference, e.reason) |
| 267 | +} |
0 commit comments