Skip to content

Since v37.0.0, create_* and delete_* calls send a body without a Content-Type header #2782

Open

Description

@bryanculver

What happened

Since v37.0.0, generated methods whose OpenAPI operation declares consumes: ["*/*"] send a JSON body with no Content-Type header. Examples: BatchV1Api.create_namespaced_job and BatchV1Api.delete_namespaced_job with a V1DeleteOptions body.

  • v36.0.3 sent Content-Type: application/json. The legacy select_header_content_type mapped */* to application/json, and rest.py defaulted a missing header to application/json.
  • In v37.0.0 through v37.0.2 and master, the generated _create_namespaced_job_serialize sets Accept but not Content-Type. rest.py still serializes the body as JSON when the header is missing, but it no longer writes the header.
  • _content_type="application/json" is accepted but ignored by these serializers. _headers={"Content-Type": "application/json"} works.

This change is not listed in the v37.0.0 "Breaking Change" notes.

Why it matters

  • RFC 9110 section 8.3: "A sender that generates a message containing content SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender." The client knows the body is JSON.
  • kube-apiserver tolerates a missing header (it uses the first supported media type), so stock setups keep working. Anything between the client and the server that fills in a default breaks. We hit this with urllib3-future, which replaces urllib3 when niquests is installed. It sends Content-Type: text/plain; charset=utf-8 for str bodies without a header, and the API server returns 415 Unsupported Media Type.
  • PR Regenerate the synchronous client with the modern Python generator #2631 fixed the same class of problem for DynamicClient discovery (a literal */* Content-Type). The typed API create/delete paths were not covered.

Reproduce (no cluster needed)

import http.server, threading
import kubernetes.client as k

seen = []
class H(http.server.BaseHTTPRequestHandler):
    def do_POST(self):
        seen.append(self.headers.get("Content-Type"))
        self.rfile.read(int(self.headers.get("Content-Length") or 0))
        self.send_response(201); self.send_header("Content-Type", "application/json"); self.end_headers(); self.wfile.write(b"{}")
    def log_message(self, *a): pass

srv = http.server.HTTPServer(("127.0.0.1", 0), H); threading.Thread(target=srv.serve_forever, daemon=True).start()
cfg = k.Configuration(); cfg.host = f"http://127.0.0.1:{srv.server_port}"
body = {"apiVersion": "batch/v1", "kind": "Job", "metadata": {"name": "x"},
        "spec": {"template": {"spec": {"containers": [{"name": "c", "image": "i"}]}}}}
with k.ApiClient(cfg) as c:
    k.BatchV1Api(c).create_namespaced_job(namespace="n", body=body)
print(seen)  # v36.0.3: ['application/json']   v37.0.1: [None]

Expected

Content-Type: application/json on JSON bodies, as in v36. Possible fixes:

  • Map */* consumes to application/json in the generated serializers (matching the legacy behavior), or
  • Default Content-Type to application/json in rest.py when serializing a JSON body without one, and
  • Honor _content_type on these methods.

Environment

kubernetes 37.0.1 (also checked 37.0.2 and master), Python 3.13, urllib3 2.8.0 / urllib3-future 2.25.906, EKS 1.36.

Activity

  1. bryanculver commented on Nov 13, 2026

    @bryanculver
    Author

    Downstream workaround (explicit _headers={"Content-Type": "application/json"}): nautobot/nautobot#9805

  2. christianfrei791 commented on Nov 16, 2026

    @christianfrei791

    The regression in _create_namespaced_job_serialize suggests that the generator template for consumes: ["*/*"] is no longer correctly defaulting the header value into the request dictionary. I suspect the change was introduced by a refactor of the serialization logic in the v37.0.0 codegen templates, likely moving away from the previous behavior in rest.py that implicitly injected the header. Have you checked if reverting the template change that removed the mapping for */* in _serialize methods restores the expected header without requiring manual overrides in _headers?

  3. yliaog commented on Nov 20, 2026

    @yliaog
    Contributor
  4. kubernetes-prow commented on Nov 20, 2026

    @kubernetes-prow
    Contributor

    @yliaog: GitHub didn't allow me to assign the following users: brendanburns.

    Note that only kubernetes-client members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
    For more information please see the contributor guide

    Details

    In response to this:

    /assign @brendanburns

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

  5. yliaog commented on Nov 20, 2026

    @yliaog
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions