Add support for DeletionPropagation
Luzifer opened this issue · 2 comments
When deleting a job the spawned pods persist after the job has been deleted. The kubectl
command as well as the API does support removing the related pods with one delete command using DeletionPropagation
.
Trying to achieve this behaviour with k8s.QueryParam()
leads to an error:
[...]
job := &batchv1.Job{}
if err := client.Get(ctx, "default", name, job); err != nil {
t.Fatalf("client.Get failed: %s", err)
}
if err := client.Delete(ctx, job, k8s.QueryParam("propagationPolicy", "Background")); err != nil {
t.Fatalf("client.Delete failed: %s", err)
}
[...]
client.Delete failed: kubernetes api: Failure 400 converting (url.Values).[]string.[]string to (v1.DeleteOptions).*v1.DeletionPropagation.v1.DeletionPropagation: couldn't copy '[]string' into 'v1.DeletionPropagation'; didn't understand types
Also passing *"github.com/ericchiang/k8s/apis/meta/v1".DeleteOptions
as an k8s.Option
does not work:
cannot use *"github.com/ericchiang/k8s/apis/meta/v1".DeleteOptions literal (type *"github.com/ericchiang/k8s/apis/meta/v1".DeleteOptions) as type k8s.Option in argument to client.Client.Delete: *"github.com/ericchiang/k8s/apis/meta/v1".DeleteOptions does not implement k8s.Option (missing k8s.updateURL method)
In order to delete the pods using the API it seems there must be a JSON payload in the DELETE
request: kubernetes/kubernetes#20902 (comment)
So far it seems to me the only current way to clean up the pods as well is to collect them before deleting the job and delete them in separate requests which could be far more easy using the DeletionPropagation.
Ah, I hadn't realized that deletion policy was serialized in the body of the request. It seems reasonable to add something to the k8s.Option
to set the body of the DELETE request.
At least that's my - until now quite limited - knowledge of the k8s API… Maybe there is another method (it seems to detect a query parameter but fails to convert []string
to string
) but I haven't found one yet…