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

Generated API hides kubernetes REST API response result #1498

Open
jimjaeger opened this issue Jan 4, 2024 · 4 comments
Open

Generated API hides kubernetes REST API response result #1498

jimjaeger opened this issue Jan 4, 2024 · 4 comments

Comments

@jimjaeger
Copy link

Describe the bug
If kubernetes request returns a non 2xx response the generated kubernetes api returns HttpError 'HTTP request failed' and hides
the response details, e.g. error details / causes.

It makes it impossible to identify the cause.

For example, the createNamespacedJob API tolerates non valid label values (https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) and send the job object to the REST API. As result the REST API returns a [422 Unprocessable Content] status code and a response body that contains the cause of the error. The returning error class does not contain the reponse body.

Example Reference:
https://github.com/kubernetes-client/javascript/blob/master/src/gen/api/batchV1Api.ts#L16

Client Version
Latest

To Reproduce
Steps to reproduce the behavior:

  1. Create a Job with invalid label values e.g. abc="abc/def"
  2. use createNamespacedJob API
  3. Get HttpError without cause information

Expected behavior
Option1: Validate the input including the labels.
It is may not be possible if the openapi spec it does not defines. Label Definition:
"Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels"

Option2: Return a detailed error class including the information from the REST API body.

Example Error response:

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "Job.batch \"abc\" is invalid: [metadata.labels: Invalid value: \"abc/\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'), spec.template.labels: Invalid value: \"avc==\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')]",
  "reason": "Invalid",
  "details": {
    "name": "abc",
    "group": "batch",
    "kind": "Job",
    "causes": [
      {
        "reason": "FieldValueInvalid",
        "message": "Invalid value: \"abc/def\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')",
        "field": "metadata.labels"
      },
      {
        "reason": "FieldValueInvalid",
        "message": "Invalid value: \"abc==\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')",
        "field": "spec.template.labels"
      }
    ]
  }
}
@brendandburns
Copy link
Contributor

As you say, client side validation isn't possible because the open api specification for things like labels isn't well defined.

For the second option, the body of the response should be in the error object somewhere, I'm pretty certain you can look at that response and get the details that are returned from the server. The client is not in a position to add additional error messages, it can only reply with what the server provides.

@brendandburns
Copy link
Contributor

If you have ideas for improving this, please feel free to send a PR. But note that most of the code for interacting with the API server is code generated, and it needs to be code generated because of the volume of APIs and API changes, so if you want to make changes in the generated code it needs to be in the upstream code generator.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 5, 2024
@jimjaeger
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants