python: Deleting job with delete_namespaced_job() does not delete pods

When deleting a job with BatchV1Api.delete_namespaced_job, the job resource is deleted, but the pod(s) remain.

From this documentation, my assumption was to try Ophaned, Background, or Foreground as the propagation_policy, but none of them did anything to the pod after the job was deleted.

Upon further inspection of the pod metadata, both finalizers and owner_references are set with None.

Here’s the gist of the script I used to reproduce this.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@alanbchristie

See #423

The following code works for me: body = client.V1DeleteOptions(propagation_policy='Background') resp = api.delete_namespaced_deployment(name=item.metadata.name, body=body, namespace=self.namespace)

thank you for all the discussion.

I had the same problem and confirmed that it is resolved by setting

        body = client.V1DeleteOptions(propagation_policy='Background')

agree that we shall remove the propagation_policy parameter in delete_namespaced_job() as it has no effect and cause confusion.

I disagree - I just tested the parameter like this

    api_response = api_instance.delete_namespaced_job(name, namespace, propagation_policy="Background")

and it works as expected. Now I don’t know if it will be deprecated but saying that it has no effect is incorrect.

Thanks all, I met the same problem and got solved by your solutions. By the way, since propagation_policy parameter has no effect by passing the parameter as query parameter, could @thomaswtsang update doc and remind developers to put it in the body?

Sorry, I know this topic is closed but I’m running into this problem now and this and #43329 don’t really help. Can you explain precisely how you fixed this i.e. what do you mean by Try encoding the parameter in the body (set it in V1DeleteOptions).?

Do I need to set anything in the V1DeleteOptions() body object and what, if any, other arguments need to be passed to delete_namespaced_job?