<p>I want to use the python client of K8s and delete some of the resources such as statefulset. I can delete the statefulset itself but Ks8 doesn't delete the running pods. I found some examples that they set <code>propagation_policy="Foreground"</code> in delete options and that get the job done but the problem is in the kubernetes client > 9.0 they changed the API and when I pass the delete_options it returns this error:</p>

<pre><code>TypeError: delete_namespaced_stateful_set() takes 3 positional arguments but 4 were given
</code></pre>

<p>I tried to find the correct way to set the propagation policy for delete but it didn't work and running pods were not being killed, how I can delete all the running pods and statefuleset in one api call?</p>

<p>My current code that just deletes the statefulset:</p>

<pre><code>api_response = k8s_api.delete_namespaced_stateful_set(statefulset_name,namespace)
</code></pre>

<p>The code that produces above error:</p>

<pre><code>delete_options = client.V1DeleteOptions(propagation_policy="Foreground", grace_period_seconds=5)
api_response = k8s_api.delete_namespaced_stateful_set(statefulset_name,namespace,delete_options)
</code></pre>

AVarf
<p>After reading the <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/client/apis/apps_v1beta1_api.py" rel="nofollow noreferrer">source code</a>:</p>

<pre><code>def delete_namespaced_stateful_set(self, name, namespace, **kwargs):
    """
    delete a StatefulSet
    This method makes a synchronous HTTP request by default. To make an
    asynchronous HTTP request, please pass async_req=True
    &gt;&gt;&gt; thread = api.delete_namespaced_stateful_set(name, namespace, async_req=True)
    &gt;&gt;&gt; result = thread.get()
    :param async_req bool
    :param str name: name of the StatefulSet (required)
    :param str namespace: object name and auth scope, such as for teams and projects (required)
    :param str pretty: If 'true', then the output is pretty printed.
    :param V1DeleteOptions body:
    :param str dry_run: When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed
    :param int grace_period_seconds: The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.
    :param bool orphan_dependents: Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.
    :param str propagation_policy: Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.
    :return: V1Status
             If the method is called asynchronously,
             returns the request thread.
    """
</code></pre>

<p>I believe the correct way to set the extra params (<code>**kwargs</code>) is using the <code>key=value</code> format, also <em>V1DeleteOptions</em> is not a valid parameter so instead of passing <code>delete_options</code> as an argument you should pass each option of <em>V1DeleteOptions</em>, such as <code>propagation_policy="Foreground"</code> and <code>grace_period_seconds=5</code>:</p>

<pre><code>api_response = k8s_api.delete_namespaced_stateful_set(statefulset_name,namespace,propagation_policy="Foreground", grace_period_seconds=5)
</code></pre>

<p>There is a way, however, to pass an entire <em>V1DeleteOptions</em> object. You can first convert it to a dict and then unpack it:</p>

<pre><code>delete_options = client.V1DeleteOptions(propagation_policy="Foreground", grace_period_seconds=5)
api_response = k8s_api.delete_namespaced_stateful_set(statefulset_name,namespace,**delete_options.do_dict())
</code></pre>
