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

Add more detail about media types #46230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sftim
Copy link
Contributor

@sftim sftim commented May 6, 2024

Revise https://k8s.io/docs/reference/using-api/api-concepts/
Preview

  • Add section about JSON encoding for API
  • Mention that the HTTP API doesn't use YAML
  • Add links to JSON, YAML and Protobuf

/wg api-expression
/language en

@k8s-ci-robot k8s-ci-robot added wg/api-expression Categorizes an issue or PR as relevant to WG API Expression. language/en Issues or PRs related to English language labels May 6, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from sftim. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the sig/docs Categorizes an issue or PR as relevant to SIG Docs. label May 6, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 6, 2024

<!--more-->
A manifest specifies the desired state of an object that Kubernetes will maintain when you apply the manifest. Each configuration file can contain multiple manifests.
A manifest specifies the desired state of an object that Kubernetes will maintain when you apply the manifest.
For YAML format, each file can contain multiple manifests.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can put more than one manifest in a file in JSON format, and still call that file “JSON”.

Comment on lines +128 to +130
Although YAML is widely used to define Kubernetes manifests locally, Kubernetes does not
support the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html) media type
for API operations.
Copy link
Contributor Author

@sftim sftim May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is application/apply-patch+yaml (and documents in that format look like, uh, JSON). For simplicity I am deliberately not mentioning that detail here. The statement:

Kubernetes does not support the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html)
media type for API operations.

remains true.

Copy link

netlify bot commented May 6, 2024

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit cab0fbc
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/66395ffc79e6750008444aeb
😎 Deploy Preview https://deploy-preview-46230--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +188 to +195
### Kubernetes Protobuf encoding {#protobuf-encoding}

Kubernetes uses an envelope wrapper to encode [Protobuf](https://protobuf.dev/) responses.
That wrapper starts with a 4 byte magic number to help identify content in disk or in etcd as Protobuf
(as opposed to JSON). The 4 byte magic number data is followed by a Protobuf encoded wrapper message, which
describes the encoding and type of the underlying object. Within the Protobuf wrapper message,
the inner object data is recorded using the `raw` field of Unknown (see the [IDL](##protobuf-encoding-idl)
for more detail).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved, not new. A local diff with git diff --color-moved=… might help show the changes better than GitHub's web UI.

Comment on lines +160 to +168
```
GET /api/v1/pods
Accept: application/json
---
200 OK
Content-Type: application/json

… JSON encoded collection of Pods (PodList object)
```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapted from the existing protobuf example

Comment on lines +140 to +144
The Kubernetes API implements standard HTTP content type negotiation: passing an
`Accept` header with a `GET` call will request that the server tries to return
a response in your preferred media type. If you want to send an object in Protobuf to
the server for a `PUT` or `POST` call means that you must set the `Content-Type`
header appropriately.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved and adapted, not new. A local diff with git diff --color-moved=… might help show the changes better than GitHub's web UI.

- Add section about JSON encoding for API
- Mention that the HTTP API doesn't use YAML
@sftim sftim force-pushed the 20240506_explain_api_media_types branch from 97af243 to cab0fbc Compare May 6, 2024 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. wg/api-expression Categorizes an issue or PR as relevant to WG API Expression.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants