apps API: Accept with protobuf first and JSON as a fallback gets 406 instead of JSON

Aberta
#5,297 0 comentários 1 reação 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 3 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
go, kubernetes
Domínio
api, backend

Direção de pesquisa

Start with TestAppsAPIContentNegotiation in pkg/cmd/server/apiserver_surface_test.go, then trace the apps API serializer setup in pkg/apiserver and how it advertises media types. The issue leaves the behavior open pending a maintainer decision, so first confirm which option is accepted; done means the test and API negotiation match that decision, including the protobuf-only client case.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

triage/needs-triage

A client that prefers protobuf and accepts JSON as a fallback gets 406 Not Acceptable from the apps API instead of a JSON answer. GET on an Application with Accept: application/vnd.kubernetes.protobuf, application/json;q=0.9 returns 406. With application/cbor, application/json;q=0.9 the same request returns JSON. TestAppsAPIContentNegotiation in pkg/cmd/server/apiserver_surface_test.go (#4869) pins both answers as they are today.

The cause is that the apps API advertises a media type it cannot encode. pkg/apiserver serves through serializer.NewCodecFactory(Scheme), wrapped in kindPreservingSerializer, and that factory lists protobuf among its supported media types. Negotiation in k8s.io/apiserver picks the best match from that list, so protobuf wins over the JSON fallback. Encoding then fails because the Application types do not implement the protobuf marshalling interface. The protobuf serializer reports that as errNotMarshalable, whose status is 406 (k8s.io/apimachinery pkg/runtime/serializer/protobuf/protobuf.go), and the response never goes back to JSON. CBOR is not in the factory's list, so negotiation skips it and the fallback works.

Upstream custom resources behave the same way. apiextensions-apiserver also lists protobuf for them, because some objects it returns, like Status, do support it. So this is not specific to cozystack, but the result still breaks the Accept header's promise: JSON was acceptable and the server had it.

Two ways to handle it:

  1. Drop protobuf from the media types the apps group negotiates, so a fallback in Accept is honoured. Objects like Status that the apps API returns would then be served as JSON too, which needs checking against clients that send protobuf only.
  2. Keep the upstream behaviour and treat the pinned 406 as the contract. The test already describes the mechanism, so only this issue would close.

I'd go with the first, but it is a change to what the API advertises, so it needs a maintainer decision.

Linguagem predominante
Go
Estrelas
2.2k
Forks
209
Merge médio
4d 14h
PRs com merge (30d)
140

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de cozystack/cozystack

Todas as issues de cozystack/cozystack

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.