8000 Fix response schema for delete batch/v1/jobs by JoeryH · Pull Request #93477 · kubernetes/kubernetes · GitHub
[go: up one dir, main page]

Skip to content

Fix response schema for delete batch/v1/jobs #93477

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

Closed
wants to merge 2 commits into from

Conversation

JoeryH
Copy link
@JoeryH JoeryH commented Jul 27, 2020

DELETE batch/v1/jobs actually returns a Job resource,
not the Status the swagger docs currently have.

This causes the clients to be generated incorrectly and
the reference docs to be incorrect.

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:

/kind api-change

/kind bug

/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:

This PR updates the response schema for DELETE batch/v1/jobs in swagger.json.
We need this because swagger.json is currently incorrect (for at least v1.16, v1.17 and latest) and says a Status is returned instead of Job. This causes clients to be generated incorrectly and crashing on deserialisation.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

API reference for DELETE batch/v1/jobs now correctly states a Job is returned.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 27, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @JoeryH!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

8000

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jul 27, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @JoeryH. Thanks for your PR.

I'm waiting for a kubernetes 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 27, 2020
@k8s-ci-robot k8s-ci-robot requested review from justinsb and liggitt July 27, 2020 18:54
@JoeryH
Copy link
Author
JoeryH commented Jul 27, 2020

/assign @thockin

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/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 Oct 25, 2020
@JoeryH
Copy link
Author
JoeryH commented Oct 26, 2020

/remove-lifecycle stale

@spiffxp spiffxp added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 4, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 5, 2020
@thockin thockin removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Dec 5, 2020
@thockin
Copy link
Member 8000
thockin commented Dec 5, 2020

@janetkuo Can you help me find a home for this? I got assigned but I have no real context :)

Copy link
Member
@janetkuo janetkuo left a comment

Choose a reason for hiding this comment

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

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/apiserver area/cloudprovider area/code-generation and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 28, 2020
@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. and removed sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/release Categorizes an issue or PR as relevant to SIG Release. sig/scalability Categorizes an issue or PR as relevant to SIG Scalability. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Dec 28, 2020
@thockin thockin removed their assignment Mar 5, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 6, 2021
JoeryH added 2 commits June 19, 2021 13:50
DELETE batch/v1/jobs actually returns a Job resource,
not the generic Status object.

We can use ReturnDeletedObject: true in the storage
configuration to fix this.

Without this fix clients that are generated will be
incorrectly unmarshalling the json and, at least for
the Java client, throw an exception.
@JoeryH JoeryH force-pushed the fix-job-delete-reference-response branch from a90075b to c8ea423 Compare June 19, 2021 11:54
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 19, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JoeryH
To complete the pull request process, please assign liggitt after the PR has been reviewed.
You can assign the PR to them by writing /assign @liggitt in a comment when ready.

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-triage-robot
Copy link

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

This bot triages issues and PRs 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 or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR 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 Sep 17, 2021
@JoeryH
Copy link
Author
JoeryH commented Sep 17, 2021

/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 Sep 17, 2021
@@ -68,6 +68,7 @@ func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, error) {
UpdateStrategy: job.Strategy,
DeleteStrategy: job.Strategy,
ResetFieldsStrategy: job.Strategy,
ReturnDeletedObject: true,
Copy link
Member

Choose a reason for hiding this comment

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

this actually changes the API behavior of deleting a single job... I don't think we want to do that

Copy link
Member

Choose a reason for hiding this comment

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

hmm... deleting a single job sometimes returning status, as advertised:

kubectl delete jobs --all --v=9
I0917 12:42:00.787591    6800 request.go:1181] Request Body: {"propagationPolicy":"Background"}
I0917 12:42:00.787648    6800 round_trippers.go:435] curl -v -XDELETE  -H "User-Agent: kubectl/v1.23.0 (darwin/amd64) kubernetes/5fb1442" -H "Accept: application/json" -H "Content-Type: application/json" 'https://localhost:6443/apis/batch/v1/namespaces/default/jobs/pi'
I0917 12:42:00.791982    6800 round_trippers.go:454] DELETE https://localhost:6443/apis/batch/v1/namespaces/default/jobs/pi 200 OK in 4 milliseconds
I0917 12:42:00.792008    6800 round_trippers.go:460] Response Headers:
I0917 12:42:00.792017    6800 round_trippers.go:463]     Content-Length: 168
I0917 12:42:00.792025    6800 round_trippers.go:463]     Date: Fri, 17 Sep 2021 16:42:00 GMT
I0917 12:42:00.792031    6800 round_trippers.go:463]     Audit-Id: 6182eca4-fab7-40b0-96ff-406c439e6539
I0917 12:42:00.792037    6800 round_trippers.go:463]     Cache-Control: no-cache, private
I0917 12:42:00.792043    6800 round_trippers.go:463]     Content-Type: application/json
I0917 12:42:00.792049    6800 round_trippers.go:463]     X-Kubernetes-Pf-Flowschema-Uid: f882718c-ee58-4367-baee-cefdd030ae39
I0917 12:42:00.792055    6800 round_trippers.go:463]     X-Kubernetes-Pf-Prioritylevel-Uid: 5d04e46f-af20-40f0-a8f6-bcd5093a5d39
I0917 12:42:00.792072    6800 request.go:1181] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success","details":{"name":"pi","group":"batch","kind":"jobs","uid":"09946e4e-6ba2-4e95-8852-8b6d1ddeabdd"}}
job.batch "pi" deleted

but can also return the full job:

kubectl delete --raw /apis/batch/v1/namespaces/default/jobs/pi --v=9
I0917 12:40:58.372314    5319 loader.go:372] Config loaded from file:  /Users/liggitt/go/src/k8s.io/kubernetes/_output/certs/admin.kubeconfig
I0917 12:40:58.373235    5319 round_trippers.go:435] curl -v -XDELETE  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.23.0 (darwin/amd64) kubernetes/5fb1442" 'https://localhost:6443/apis/batch/v1/namespaces/default/jobs/pi'
I0917 12:40:58.383272    5319 round_trippers.go:454] DELETE https://localhost:6443/apis/batch/v1/namespaces/default/jobs/pi 200 OK in 10 milliseconds
I0917 12:40:58.383309    5319 round_trippers.go:460] Response Headers:
I0917 12:40:58.383323    5319 round_trippers.go:463]     X-Kubernetes-Pf-Prioritylevel-Uid: 5d04e46f-af20-40f0-a8f6-bcd5093a5d39
I0917 12:40:58.383332    5319 round_trippers.go:463]     Content-Length: 2009
I0917 12:40:58.383337    5319 round_trippers.go:463]     Date: Fri, 17 Sep 2021 16:40:58 GMT
I0917 12:40:58.383341    5319 round_trippers.go:463]     Audit-Id: 95d873ed-b5cb-4f8b-90ea-50d1f03ff23a
I0917 12:40:58.383362    5319 round_trippers.go:463]     Cache-Control: no-cache, private
I0917 12:40:58.383367    5319 round_trippers.go:463]     Content-Type: application/json
I0917 12:40:58.383372    5319 round_trippers.go:463]     Warning: 299 - "child pods are preserved by default when jobs are deleted; set propagationPolicy=Background to remove them or set propagationPolicy=Orphan to suppress this warning"
I0917 12:40:58.383377    5319 round_trippers.go:463]     X-Kubernetes-Pf-Flowschema-Uid: f882718c-ee58-4367-baee-cefdd030ae39
Warning: child pods are preserved by default when jobs are deleted; set propagationPolicy=Background to remove them or set propagationPolicy=Orphan to suppress this warning
{"kind":"Job","apiVersion":"batch/v1","metadata":{"name":"pi","namespace":"default","uid":"907a1e0e-f72a-4e42-9988-560925192ba3","resourceVersion":"436","generation":2,"creationTimestamp":"2021-09-17T16:40:50Z","deletionTimestamp":"2021-09-17T16:40:58Z","deletionGracePeriodSeconds":0,"labels":{"controller-uid":"907a1e0e-f72a-4e42-9988-560925192ba3","job-name":"pi"},"finalizers":["orphan"],"managedFields":[{"manager":"kube-controller-manager","operation":"Update","apiVersion":"batch/v1","time":"2021-09-17T16:40:50Z","fieldsType":"FieldsV1","fieldsV1":{"f:status":{"f:active":{},"f:startTime":{}}},"subresource":"status"},{"manager":"kubectl-create","operation":"Update","apiVersion":"batch/v1","time":"2021-09-17T16:40:50Z","fieldsType":"FieldsV1","fieldsV1":{"f:spec":{"f:backoffLimit":{},"f:completionMode":{},"f:completions":{},"f:parallelism":{},"f:suspend":{},"f:template":{"f:metadata":{"f:name":{}},"f:spec":{"f:containers":{"k:{\"name\":\"pi\"}":{".":{},"f:command":{},"f:image":{},"f:imagePullPolicy":{},"f:name":{},"f:resources":{},"f:terminationMessagePath":{},"f:terminationMessagePolicy":{}}},"f:dnsPolicy":{},"f:restartPolicy":{},"f:schedulerName":{},"f:securityContext":{},"f:terminationGracePeriodSeconds":{}}}}}}]},"spec":{"parallelism":1,"completions":1,"backoffLimit":6,"selector":{"matchLabels":{"controller-uid":"907a1e0e-f72a-4e42-9988-560925192ba3"}},"template":{"metadata":{"name":"pi","creationTimestamp":null,"labels":{"controller-uid":"907a1e0e-f72a-4e42-9988-560925192ba3","job-name":"pi"}},"spec":{"containers":[{"name":"pi","image":"perl","command":["perl","-Mbignum=bpi","-wle","print bpi(2000)"],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"Always"}],"restartPolicy":"Never","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{},"schedulerName":"default-scheduler"}},"completionMode":"NonIndexed","suspend":false},"status":{"startTime":"2021-09-17T16:40:50Z","active":1}}

Copy link
Member

Choose a reason for hiding this comment

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

It looks like the difference is whether or not propagationPolicy=Background is specified.

When it isn't, Status is returned. When it is, Job is returned.

Copy link
Author
@JoeryH JoeryH Sep 17, 2021

Choose a reason for hiding this comment

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

Ah I think I'm specifying propagationPolicy=Foregound.
Any reason to not always return a Job? Most clients crash right now because of type mismatch.
Edit: looks like there is a workaround? kubernetes-client/java#1445

Copy link
Member
@liggitt liggitt Sep 17, 2021

Choose a reason for hiding this comment

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

Any reason to not always return a Job?

well... some clients generated to expect status and not specifying propagationPolicy are successfully working ... switching to always return a Job will break them...

Copy link
Author

Choose a reason for hiding this comment

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

Okay thanks for looking into it, will close this then.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth trying to improve the schema to indicate the object type is a possible return schema for the delete endpoints, even if we don't change the server behavior for existing types

@JoeryH JoeryH closed this Sep 17, 2021
@liggitt
Copy link
Member
liggitt commented Sep 17, 2021

There's a few things going on here:

  1. Many (most?) types do not specify ReturnDeletedObject, not just Jobs
  2. For those types, the generated schema specifies Status as the return type for deleting a single item and collection of items
  3. Actual behavior of deleting a single item :
    • Deleting a job with propagationPolicy=Orphan, propagationPolicy=Foreground, or no propagationPolicy (which defaults to orphan) returns Job
    • Deleting a job with propagationPolicy=Background returns Status
    • Deleting a validationwebhook with propagationPolicy=Orphan or propagationPolicy=Foreground return ValidatingWebhookConfiguration
    • Deleting a validationwebhook with propagationPolicy=Background or no propagationPolicy (which defaults to background) returns Status
  4. Actual behavior of deleting a collection of items:
    • Deleting a collection of jobs returns JobList in all cases
    • Deleting a collection of validating webhooks returns ValidatingWebhookConfigurationList in all cases

So, for objects which do not set ReturnDeletedObject: true, the generated schema is incorrect in some cases for the single-item delete, and incorrect in all cases for the collection delete.

However, if we change to set ReturnDeletedObject: true for all objects, we will start returning objects in some cases where we previous returned Status, and will break clients successfully using those deletion paths that could not handle an object return.

Since all clients have to be able to handle Status in all cases (since it can be returned for forbidden errors, not found errors, etc), I think the safest thing to do is to make schema generation stop paying attention to ReturnDeletedObject and have it indicate the object can be a potential return value for single-item and collection deletion.

@liggitt
Copy link
Member
liggitt commented Sep 17, 2021

hoisted to #105104 to avoid losing the investigation and details

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. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. kind/bug Categorizes issue or PR as related to a bug. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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
0