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

Error from karmada-search: apiserver was unable to write a JSON response #6129

Open
iamyeka opened this issue Feb 17, 2025 · 5 comments
Open
Labels
kind/question Indicates an issue that is a support question.

Comments

@iamyeka
Copy link

iamyeka commented Feb 17, 2025

Please provide an in-depth description of the question you have:

Guided by the blog: https://karmada.io/docs/tutorials/karmada-search/, i want to get pod from the true K8s.
What i did:

  1. Install karmada-search with default configs by helm chart
  2. Init a clientSet by default config
restConfig, err := config.ClientConfig()
if err != nil {
	return err
}
restConfig = metadata.ConfigFor(restConfig)
clientSet, err := kubernetes.NewForConfig(restConfig)
if err != nil {
	return err
}
  1. Exec a command like below
pod, err := kubeClientset.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
  1. Error log printed in kramada-search
E0214 08:14:12.024022       1 writers.go:122] "Unhandled Error" err="apiserver was unable to write a JSON response: object *unstructured.Unstructured does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message"

If i specify the restConfig of the clientSet like this: restConfig.AcceptContentTypes = "application/json", the problem is gone.

The default AcceptContentTypes is like this:

// ConfigFor returns a copy of the provided config with the
// appropriate metadata client defaults set.
func ConfigFor(inConfig *rest.Config) *rest.Config {
	config := rest.CopyConfig(inConfig)
	config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
	config.ContentType = "application/vnd.kubernetes.protobuf"
	config.NegotiatedSerializer = metainternalversionscheme.Codecs.WithoutConversion()
	if config.UserAgent == "" {
		config.UserAgent = rest.DefaultKubernetesUserAgent()
	}
	return config
}

What do you think about this question?:

Environment:

  • Karmada version: 1.12.3
  • Kubernetes version: 1.19.3
  • Others: Installed by helm chart, with all default configs
@iamyeka iamyeka added the kind/question Indicates an issue that is a support question. label Feb 17, 2025
@chaosi-zju
Copy link
Member

chaosi-zju commented Feb 18, 2025

If i specify the restConfig of the clientSet like this: restConfig.AcceptContentTypes = "application/json", the problem is gone.

So, what is the problem that bothers you now?

Do you mean you want to get a recommended way to avoid that Unhandled Error when querying pods?

@iamyeka
Copy link
Author

iamyeka commented Feb 18, 2025

If i specify the restConfig of the clientSet like this: restConfig.AcceptContentTypes = "application/json", the problem is gone.

So, what is the problem that bothers you now?

Do you mean you want to get a recommended way to avoid that Unhandled Error when querying pods?

Can the server handle the request that sent by the client with the default header "accept: application/vnd.kubernetes.protobuf,application/json"?

We have several k8s, and we don't want to add a field into our mysql table like "accetType" to specify AcceptContentTypes of the restConfig of the clientSet.

@RainbowMango
Copy link
Member

Do you mean the server can only respond with application/json? What you want is for sever support application/vnd.kubernetes.protobuf,application/json?

Any idea to achieve that?

@iamyeka
Copy link
Author

iamyeka commented Feb 20, 2025

Do you mean the server can only respond with application/json? What you want is for sever support application/vnd.kubernetes.protobuf,application/json?

Any idea to achieve that?

Yes. The problem is i can't use the clientSet with the default config to get info from karmada-search. I need to explicitly set acceptType to application/json to achieve the goal which is not needed for normal k8s.

@RainbowMango
Copy link
Member

Would you like to dig into it and try to work out a solution for your case? Feel free to send a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

3 participants