kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

Cannot delete pod forcibly with CoreV1API_deleteNamespacedPod API #158

Closed privmc closed 1 year ago

privmc commented 1 year ago

To delete a pod forcibly you need to set gracePeriodSeconds to zero. zero means delete immediately.

Example:

DELETE /api/v1/namespaces/{namespace}/pods/{name}?gracePeriodSeconds=0

However, if calling CoreV1API_deleteNamespacedPod with the gracePeriodSeconds parameter set to 0 the gracePeriodSeconds query parameter is not created in the HTTP request.

ityuhui commented 1 year ago

Yes. it's a problem. Now, can you set a small value such as gracePeriodSeconds=1 to walkaround this ?

Later, I want to fix this issue by introducing a magic number for the undefined integer parameter in openapi-generator.

e.g.

#define INT_UNDEFINED -9997
or
#define INT_UNDEFINED INT_MIN // INT_MIN is defined in <limits.h>

...
    if (gracePeriodSeconds != INT_UNDEFINED)  // the current code is `if (gracePeriodSeconds)`
    {
        keyQuery_gracePeriodSeconds = strdup("gracePeriodSeconds");
        valueQuery_gracePeriodSeconds = calloc(1,MAX_NUMBER_LENGTH);
        snprintf(valueQuery_gracePeriodSeconds, MAX_NUMBER_LENGTH, "%d", gracePeriodSeconds);
        keyPairQuery_gracePeriodSeconds = keyValuePair_create(keyQuery_gracePeriodSeconds, valueQuery_gracePeriodSeconds);
        list_addElement(localVarQueryParameters,keyPairQuery_gracePeriodSeconds);
    }
...

cc @brendandburns @wing328 @zhemant @michelealbano

privmc commented 1 year ago

Ok, thanks for the confirmation.

gracePeriodSeconds=1 does not work in my test.

If I do "kubectl delete pod " when the pod is in Running phase the kubectl commands hangs until the pod is forcibly deleted by sending a Pod delete with gracePeriodSeconds=0.

ityuhui commented 1 year ago

Got it.

If you need a fix now, apply the patch below and build yourself please.

diff --git a/kubernetes/api/CoreV1API.c b/kubernetes/api/CoreV1API.c
index 0dff85d..cb0ce55 100644
--- a/kubernetes/api/CoreV1API.c
+++ b/kubernetes/api/CoreV1API.c
@@ -16088,7 +16088,6 @@ CoreV1API_deleteNamespacedPod(apiClient_t *apiClient, char * name , char * _name
     char *keyQuery_gracePeriodSeconds = NULL;
     char * valueQuery_gracePeriodSeconds = NULL;
     keyValuePair_t *keyPairQuery_gracePeriodSeconds = 0;
-    if (gracePeriodSeconds)
     {
         keyQuery_gracePeriodSeconds = strdup("gracePeriodSeconds");
         valueQuery_gracePeriodSeconds = calloc(1,MAX_NUMBER_LENGTH);