Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #38219 #38344

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/openapi-spec/swagger.json
Expand Up @@ -3638,7 +3638,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.Pod"
"type": "string"
}
},
"401": {
Expand Down
4 changes: 2 additions & 2 deletions api/swagger-spec/v1.json
Expand Up @@ -8980,7 +8980,7 @@
"description": "API at /api/v1",
"operations": [
{
"type": "v1.Pod",
"type": "string",
"method": "GET",
"summary": "read log of the specified Pod",
"nickname": "readNamespacedPodLog",
Expand Down Expand Up @@ -9078,7 +9078,7 @@
{
"code": 200,
"message": "OK",
"responseModel": "v1.Pod"
"responseModel": "string"
}
],
"produces": [
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/v1/operations.html
Expand Up @@ -8979,7 +8979,7 @@ <h4 id="_responses_63">Responses</h4>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">200</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">success</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../definitions#_v1_pod">v1.Pod</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/rest/rest.go
Expand Up @@ -289,6 +289,10 @@ type StorageMetadata interface {
// ProducesMIMETypes returns a list of the MIME types the specified HTTP verb (GET, POST, DELETE,
// PATCH) can respond with.
ProducesMIMETypes(verb string) []string

// ProducesObject returns an object the specified HTTP verb respond with. It will overwrite storage object if
// it is not nil. Only the type of the return object matters, the value will be ignored.
ProducesObject(verb string) interface{}
}

// ConnectRequest is an object passed to admission control for Connect operations
Expand Down
10 changes: 9 additions & 1 deletion pkg/apiserver/api_installer.go
Expand Up @@ -197,7 +197,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if err != nil {
return nil, err
}
versionedObject := indirectArbitraryPointer(versionedPtr)
defaultVersionedObject := indirectArbitraryPointer(versionedPtr)
kind := fqKindToRegister.Kind
hasSubresource := len(subresource) > 0

Expand Down Expand Up @@ -503,6 +503,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Kind: fqKindToRegister,
}
for _, action := range actions {
versionedObject := storageMeta.ProducesObject(action.Verb)
if versionedObject == nil {
versionedObject = defaultVersionedObject
}
reqScope.Namer = action.Namer
namespaced := ""
if apiResource.Namespaced {
Expand Down Expand Up @@ -1022,6 +1026,10 @@ func (defaultStorageMetadata) ProducesMIMETypes(verb string) []string {
return nil
}

func (defaultStorageMetadata) ProducesObject(verb string) interface{} {
return nil
}

// splitSubresource checks if the given storage path is the path of a subresource and returns
// the resource and subresource components.
func splitSubresource(path string) (string, string, error) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/apiserver/apiserver_test.go
Expand Up @@ -619,6 +619,10 @@ func (m *MetadataRESTStorage) ProducesMIMETypes(method string) []string {
return m.types
}

func (m *MetadataRESTStorage) ProducesObject(verb string) interface{} {
return nil
}

var _ rest.StorageMetadata = &MetadataRESTStorage{}

type GetWithOptionsRESTStorage struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/registry/core/pod/rest/log.go
Expand Up @@ -55,6 +55,11 @@ func (r *LogREST) ProducesMIMETypes(verb string) []string {
}
}

// LogREST implements StorageMetadata, return string as the generating object
func (r *LogREST) ProducesObject(verb string) interface{} {
return ""
}

// Get retrieves a runtime.Object that will stream the contents of the pod log
func (r *LogREST) Get(ctx api.Context, name string, opts runtime.Object) (runtime.Object, error) {
logOpts, ok := opts.(*api.PodLogOptions)
Expand Down