Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 9fda7f1

Browse files
committed
update StatusDetails to handle Groups
1 parent 5c4479f commit 9fda7f1

File tree

75 files changed

+303
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+303
-238
lines changed

api/swagger-spec/v1.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13070,6 +13070,10 @@
1307013070
"type": "string",
1307113071
"description": "The name attribute of the resource associated with the status StatusReason (when there is a single name which can be described)."
1307213072
},
13073+
"group": {
13074+
"type": "string",
13075+
"description": "The group attribute of the resource associated with the status StatusReason."
13076+
},
1307313077
"kind": {
1307413078
"type": "string",
1307513079
"description": "The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds"

api/swagger-spec/v1beta1.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,10 @@
29002900
"type": "string",
29012901
"description": "The name attribute of the resource associated with the status StatusReason (when there is a single name which can be described)."
29022902
},
2903+
"group": {
2904+
"type": "string",
2905+
"description": "The group attribute of the resource associated with the status StatusReason."
2906+
},
29032907
"kind": {
29042908
"type": "string",
29052909
"description": "The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds"

docs/api-reference/extensions/v1beta1/definitions.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,13 @@ <h3 id="_unversioned_statusdetails">unversioned.StatusDetails</h3>
13311331
<td class="tableblock halign-left valign-top"></td>
13321332
</tr>
13331333
<tr>
1334+
<td class="tableblock halign-left valign-top"><p class="tableblock">group</p></td>
1335+
<td class="tableblock halign-left valign-top"><p class="tableblock">The group attribute of the resource associated with the status StatusReason.</p></td>
1336+
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
1337+
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
1338+
<td class="tableblock halign-left valign-top"></td>
1339+
</tr>
1340+
<tr>
13341341
<td class="tableblock halign-left valign-top"><p class="tableblock">kind</p></td>
13351342
<td class="tableblock halign-left valign-top"><p class="tableblock">The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds</a></p></td>
13361343
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
@@ -4278,7 +4285,7 @@ <h3 id="_any">any</h3>
42784285
</div>
42794286
<div id="footer">
42804287
<div id="footer-text">
4281-
Last updated 2015-12-14 19:06:25 UTC
4288+
Last updated 2015-12-16 14:33:53 UTC
42824289
</div>
42834290
</div>
42844291
</body>

docs/api-reference/v1/definitions.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4435,6 +4435,13 @@ <h3 id="_unversioned_statusdetails">unversioned.StatusDetails</h3>
44354435
<td class="tableblock halign-left valign-top"></td>
44364436
</tr>
44374437
<tr>
4438+
<td class="tableblock halign-left valign-top"><p class="tableblock">group</p></td>
4439+
<td class="tableblock halign-left valign-top"><p class="tableblock">The group attribute of the resource associated with the status StatusReason.</p></td>
4440+
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
4441+
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
4442+
<td class="tableblock halign-left valign-top"></td>
4443+
</tr>
4444+
<tr>
44384445
<td class="tableblock halign-left valign-top"><p class="tableblock">kind</p></td>
44394446
<td class="tableblock halign-left valign-top"><p class="tableblock">The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds</a></p></td>
44404447
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
@@ -6918,7 +6925,7 @@ <h3 id="_any">any</h3>
69186925
</div>
69196926
<div id="footer">
69206927
<div id="footer-text">
6921-
Last updated 2015-12-16 19:00:42 UTC
6928+
Last updated 2015-12-17 12:59:31 UTC
69226929
</div>
69236930
</div>
69246931
</body>

pkg/admission/errors.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import (
2323
utilerrors "k8s.io/kubernetes/pkg/util/errors"
2424
)
2525

26-
func extractKindName(a Attributes) (name string, kind unversioned.GroupKind, err error) {
26+
func extractResourceName(a Attributes) (name string, resource unversioned.GroupResource, err error) {
2727
name = "Unknown"
28-
kind = a.GetKind()
28+
resource = a.GetResource()
2929
obj := a.GetObject()
3030
if obj != nil {
3131
objectMeta, err := api.ObjectMetaFor(obj)
3232
if err != nil {
33-
return "", unversioned.GroupKind{}, err
33+
return "", unversioned.GroupResource{}, err
3434
}
3535

3636
// this is necessary because name object name generation has not occurred yet
@@ -40,7 +40,7 @@ func extractKindName(a Attributes) (name string, kind unversioned.GroupKind, err
4040
name = objectMeta.GenerateName
4141
}
4242
}
43-
return name, kind, nil
43+
return name, resource, nil
4444
}
4545

4646
// NewForbidden is a utility function to return a well-formatted admission control error response
@@ -49,18 +49,18 @@ func NewForbidden(a Attributes, internalError error) error {
4949
if apierrors.IsForbidden(internalError) {
5050
return internalError
5151
}
52-
name, kind, err := extractKindName(a)
52+
name, resource, err := extractResourceName(a)
5353
if err != nil {
5454
return apierrors.NewInternalError(utilerrors.NewAggregate([]error{internalError, err}))
5555
}
56-
return apierrors.NewForbidden(kind.Kind, name, internalError)
56+
return apierrors.NewForbidden(resource, name, internalError)
5757
}
5858

5959
// NewNotFound is a utility function to return a well-formatted admission control error response
6060
func NewNotFound(a Attributes) error {
61-
name, kind, err := extractKindName(a)
61+
name, resource, err := extractResourceName(a)
6262
if err != nil {
6363
return apierrors.NewInternalError(err)
6464
}
65-
return apierrors.NewNotFound(kind.Kind, name)
65+
return apierrors.NewNotFound(resource, name)
6666
}

pkg/api/errors/errors.go

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,32 @@ func FromObject(obj runtime.Object) error {
9393
}
9494

9595
// NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
96-
func NewNotFound(kind, name string) error {
96+
func NewNotFound(qualifiedResource unversioned.GroupResource, name string) error {
9797
return &StatusError{unversioned.Status{
9898
Status: unversioned.StatusFailure,
9999
Code: http.StatusNotFound,
100100
Reason: unversioned.StatusReasonNotFound,
101101
Details: &unversioned.StatusDetails{
102-
Kind: kind,
103-
Name: name,
102+
Group: qualifiedResource.Group,
103+
Kind: qualifiedResource.Resource,
104+
Name: name,
104105
},
105-
Message: fmt.Sprintf("%s %q not found", kind, name),
106+
Message: fmt.Sprintf("%s %q not found", qualifiedResource.String(), name),
106107
}}
107108
}
108109

109110
// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
110-
func NewAlreadyExists(kind, name string) error {
111+
func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string) error {
111112
return &StatusError{unversioned.Status{
112113
Status: unversioned.StatusFailure,
113114
Code: http.StatusConflict,
114115
Reason: unversioned.StatusReasonAlreadyExists,
115116
Details: &unversioned.StatusDetails{
116-
Kind: kind,
117-
Name: name,
117+
Group: qualifiedResource.Group,
118+
Kind: qualifiedResource.Resource,
119+
Name: name,
118120
},
119-
Message: fmt.Sprintf("%s %q already exists", kind, name),
121+
Message: fmt.Sprintf("%s %q already exists", qualifiedResource.String(), name),
120122
}}
121123
}
122124

@@ -136,30 +138,32 @@ func NewUnauthorized(reason string) error {
136138
}
137139

138140
// NewForbidden returns an error indicating the requested action was forbidden
139-
func NewForbidden(kind, name string, err error) error {
141+
func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err error) error {
140142
return &StatusError{unversioned.Status{
141143
Status: unversioned.StatusFailure,
142144
Code: http.StatusForbidden,
143145
Reason: unversioned.StatusReasonForbidden,
144146
Details: &unversioned.StatusDetails{
145-
Kind: kind,
146-
Name: name,
147+
Group: qualifiedResource.Group,
148+
Kind: qualifiedResource.Resource,
149+
Name: name,
147150
},
148-
Message: fmt.Sprintf("%s %q is forbidden: %v", kind, name, err),
151+
Message: fmt.Sprintf("%s %q is forbidden: %v", qualifiedResource.String(), name, err),
149152
}}
150153
}
151154

152155
// NewConflict returns an error indicating the item can't be updated as provided.
153-
func NewConflict(kind, name string, err error) error {
156+
func NewConflict(qualifiedResource unversioned.GroupResource, name string, err error) error {
154157
return &StatusError{unversioned.Status{
155158
Status: unversioned.StatusFailure,
156159
Code: http.StatusConflict,
157160
Reason: unversioned.StatusReasonConflict,
158161
Details: &unversioned.StatusDetails{
159-
Kind: kind,
160-
Name: name,
162+
Group: qualifiedResource.Group,
163+
Kind: qualifiedResource.Resource,
164+
Name: name,
161165
},
162-
Message: fmt.Sprintf("%s %q cannot be updated: %v", kind, name, err),
166+
Message: fmt.Sprintf("%s %q cannot be updated: %v", qualifiedResource.String(), name, err),
163167
}}
164168
}
165169

@@ -174,7 +178,7 @@ func NewGone(message string) error {
174178
}
175179

176180
// NewInvalid returns an error indicating the item is invalid and cannot be processed.
177-
func NewInvalid(kind, name string, errs field.ErrorList) error {
181+
func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.ErrorList) error {
178182
causes := make([]unversioned.StatusCause, 0, len(errs))
179183
for i := range errs {
180184
err := errs[i]
@@ -189,11 +193,12 @@ func NewInvalid(kind, name string, errs field.ErrorList) error {
189193
Code: StatusUnprocessableEntity, // RFC 4918: StatusUnprocessableEntity
190194
Reason: unversioned.StatusReasonInvalid,
191195
Details: &unversioned.StatusDetails{
192-
Kind: kind,
196+
Group: qualifiedKind.Group,
197+
Kind: qualifiedKind.Kind,
193198
Name: name,
194199
Causes: causes,
195200
},
196-
Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, errs.ToAggregate()),
201+
Message: fmt.Sprintf("%s %q is invalid: %v", qualifiedKind.String(), name, errs.ToAggregate()),
197202
}}
198203
}
199204

@@ -218,34 +223,42 @@ func NewServiceUnavailable(reason string) error {
218223
}
219224

220225
// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
221-
func NewMethodNotSupported(kind, action string) error {
226+
func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action string) error {
222227
return &StatusError{unversioned.Status{
223228
Status: unversioned.StatusFailure,
224229
Code: http.StatusMethodNotAllowed,
225230
Reason: unversioned.StatusReasonMethodNotAllowed,
226231
Details: &unversioned.StatusDetails{
227-
Kind: kind,
232+
Group: qualifiedResource.Group,
233+
Kind: qualifiedResource.Resource,
228234
},
229-
Message: fmt.Sprintf("%s is not supported on resources of kind %q", action, kind),
235+
Message: fmt.Sprintf("%s is not supported on resources of kind %q", action, qualifiedResource.String()),
230236
}}
231237
}
232238

233239
// NewServerTimeout returns an error indicating the requested action could not be completed due to a
234240
// transient error, and the client should try again.
235-
func NewServerTimeout(kind, operation string, retryAfterSeconds int) error {
241+
func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation string, retryAfterSeconds int) error {
236242
return &StatusError{unversioned.Status{
237243
Status: unversioned.StatusFailure,
238244
Code: http.StatusInternalServerError,
239245
Reason: unversioned.StatusReasonServerTimeout,
240246
Details: &unversioned.StatusDetails{
241-
Kind: kind,
247+
Group: qualifiedResource.Group,
248+
Kind: qualifiedResource.Resource,
242249
Name: operation,
243250
RetryAfterSeconds: int32(retryAfterSeconds),
244251
},
245-
Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, kind),
252+
Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, qualifiedResource.String()),
246253
}}
247254
}
248255

256+
// NewServerTimeoutForKind should not exist. Server timeouts happen when accessing resources, the Kind is just what we
257+
// happened to be looking at when the request failed. This delegates to keep code sane, but we should work towards removing this.
258+
func NewServerTimeoutForKind(qualifiedKind unversioned.GroupKind, operation string, retryAfterSeconds int) error {
259+
return NewServerTimeout(unversioned.GroupResource{Group: qualifiedKind.Group, Resource: qualifiedKind.Kind}, operation, retryAfterSeconds)
260+
}
261+
249262
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
250263
func NewInternalError(err error) error {
251264
return &StatusError{unversioned.Status{
@@ -274,7 +287,7 @@ func NewTimeoutError(message string, retryAfterSeconds int) error {
274287
}
275288

276289
// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
277-
func NewGenericServerResponse(code int, verb, kind, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) error {
290+
func NewGenericServerResponse(code int, verb string, qualifiedResource unversioned.GroupResource, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) error {
278291
reason := unversioned.StatusReasonUnknown
279292
message := fmt.Sprintf("the server responded with the status code %d but did not return more information", code)
280293
switch code {
@@ -316,10 +329,10 @@ func NewGenericServerResponse(code int, verb, kind, name, serverMessage string,
316329
}
317330
}
318331
switch {
319-
case len(kind) > 0 && len(name) > 0:
320-
message = fmt.Sprintf("%s (%s %s %s)", message, strings.ToLower(verb), kind, name)
321-
case len(kind) > 0:
322-
message = fmt.Sprintf("%s (%s %s)", message, strings.ToLower(verb), kind)
332+
case !qualifiedResource.IsEmpty() && len(name) > 0:
333+
message = fmt.Sprintf("%s (%s %s %s)", message, strings.ToLower(verb), qualifiedResource.String(), name)
334+
case !qualifiedResource.IsEmpty():
335+
message = fmt.Sprintf("%s (%s %s)", message, strings.ToLower(verb), qualifiedResource.String())
323336
}
324337
var causes []unversioned.StatusCause
325338
if isUnexpectedResponse {
@@ -337,8 +350,9 @@ func NewGenericServerResponse(code int, verb, kind, name, serverMessage string,
337350
Code: int32(code),
338351
Reason: reason,
339352
Details: &unversioned.StatusDetails{
340-
Kind: kind,
341-
Name: name,
353+
Group: qualifiedResource.Group,
354+
Kind: qualifiedResource.Resource,
355+
Name: name,
342356

343357
Causes: causes,
344358
RetryAfterSeconds: int32(retryAfterSeconds),

0 commit comments

Comments
 (0)