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

use protobuf content type instead of json for k8s client #2138

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

bhavi-koduru
Copy link
Contributor

@bhavi-koduru bhavi-koduru commented Sep 9, 2024

Is this a bug fix or adding new feature?

What is this PR about? / Why do we need it?
This MR is a part of effort to elevate single eks cluster performance by migrating the EKS components to use protobuf instead of json.

Modify kubeconfig type to use content type application/vnd.kubernetes.protobuf instead of json for performance gain.

This change essentially lets the ebs driver (client) to talk to apiserver using protobuf and falls back to json if protobuf isn't supported. It will only affect the wire format between ebs driver and apiserver.

What testing is done?

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 9, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @bhavi-koduru. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 9, 2024
@AndrewSirenko
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 9, 2024
@hakuna-matatah
Copy link

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 10, 2024
@AndrewSirenko
Copy link
Contributor

AndrewSirenko commented Sep 10, 2024

FYI @ConnorJC3 @ElijahQuinones @torredil Seems like this is documented in Kubernetes API Concepts | Alternate Representations of resources

@bhavi-koduru mentioned that this support was enabled in k8s 1.13 so we are safe for all supported K8s versions. (x-ref: kubernetes/client-go#76).

CRDs (sometimes?) are JSON-only. We require snapshot CRDs for snapshot workflows. (not the driver binary) But it seems that snapshot CRDs have protobuf encodings anyway? (see external-snapshotter/client/apis/...types.go)

I may do some research to ensure no noticeable performance regression before approving this PR, but it is good that e2e tests are passing.

Seems like there have been some (old) cases of setting ContentType to protobuf breaking things, but that might have been because those projects did not set the fallback to be JSON via config.AcceptContentTypes?

@ConnorJC3
Copy link
Contributor

ConnorJC3 commented Sep 10, 2024

If protobuf is so much better than JSON is there a reason it isn't enabled by default in client-go? Are we opting into potentially less tested or less stable code here?

Also, is it even worth taking this risk for the driver binary itself? It rarely communicates with the API server (off the top of my head I can only think of the startup taint removal and pre-stop hooks).

@AndrewSirenko
Copy link
Contributor

AndrewSirenko commented Sep 10, 2024

If protobuf is so much better than JSON is there a reason it isn't enabled by default in client-go?

Yeah I had same question, turns out it was not enabled by default because not all CRDs support protobuf, and there was concern about protobuf encodings being less stable than JSON encodings back in 2017. At-least that is what this issue rabbit hole mentions: kubernetes/client-go#76

Also, is it even worth taking this risk for the driver binary itself? It rarely communicates with the API server

Good point, @bhavi-koduru is there a world where PRs on the kubernetes-csi sidecars (e.g. external-attacher, resizer, provisioner, snapshotter) makes more sense?

Those are the components of EBS CSI Driver that watch the K8s API Server and then call this plugin's gRPC endpoints to perform EBS volume / EC2 instance actions like creating and mounting volumes.

@mengqiy
Copy link
Member

mengqiy commented Sep 11, 2024

CRDs currently only support json. That's why this change has a fallback after protobuf.
Protobuf encoding is as reliable as (if not more) json encoding. Protobuf is used for all core types between apiserver <-> etcd and apiserver <-> kube-controller-manager, scheduler, kubelet and more core components.

Controller-runtime which is most popular SDK to build controller has adopted protobuf in 2020: kubernetes-sigs/controller-runtime#1149

There is an attempt kubernetes/kubernetes#125314 in upstream to change the default. But it will take some time.

@bhavi-koduru
Copy link
Contributor Author

is there a world where PRs on the kubernetes-csi sidecars (e.g. external-attacher, resizer, provisioner, snapshotter) makes more sense?

The scope of this task is to get eks/aws components using protobuf. Hence, we are not focusing on upstream components currently.

@torredil
Copy link
Member

I think @ConnorJC3 and @AndrewSirenko raise valid concerns here. That said, I'm more inclined to accept this change if kubernetes-csi/external-attacher#585 is accepted, especially given that standard components default to protobuf.

@hakuna-matatah
Copy link

If protobuf is so much better than JSON is there a reason it isn't enabled by default in client-go? Are we opting into potentially less tested or less stable code here?

Main reason why it wasn't defaulted is because of this today FMU kubernetes/kubernetes#26130

If it wasn't exposed, defaulting would have happened already.

Copy link
Member

@torredil torredil left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution!
/lgtm

@ElijahQuinones
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@ElijahQuinones: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@ConnorJC3
Copy link
Contributor

/approve

I did some deep digging, and based on what I found this looks to be safe in the versions we support. I would still encourage the submitter to consider contributing to other upstream projects like the sidecars if they're looking for a big improvement howerver.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ConnorJC3

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 16, 2024
@ConnorJC3
Copy link
Contributor

/retest

likely flake

@k8s-ci-robot k8s-ci-robot merged commit 2b29cb0 into kubernetes-sigs:master Sep 16, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants