<p>I tried to delete my jobs with a LabelSelector by <a href="https://github.com/kubernetes/client-go" rel="noreferrer">client-go</a>:</p>
<pre class="lang-golang prettyprint-override"><code>cli.BatchV1().Jobs(&quot;default&quot;).Delete(context.TODO(), name, metav1.DeleteOptions{})
</code></pre>
<p>And the job was deleted successfully, but the pods of it didn't!</p>
<p>If I delete this job by <code>kubectl</code>, the pod it created would be deleted automatically.</p>
<p>How could I delete jobs with its pods simply by <code>client-go</code>?</p>

Reed Chan
<p>you need to set the <code>PropagationPolicy</code> field in <code>DeleteOptions</code> to <code>Background</code>. This ensures that the Job and its child Pods are deleted.</p>
<pre><code>import metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;

//...

backgroundDeletion := metav1.DeletePropagationBackground

err := cli.BatchV1()
       .Jobs(&quot;default&quot;)
       .Delete(context.TODO(), name, metav1.DeleteOptions{
           PropagationPolicy: &amp;backgroundDeletion, 
       })
</code></pre>
