kubernetes-client / c

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

How to update namespaced Custom Resource status with Kubernetes client in C? #150

Closed hariramshankar closed 1 year ago

hariramshankar commented 1 year ago

Hi there, what would be the recommended way of modifying (replace/ merge) the status subresource of a namespaced Custom Resource?

Reading the code the APIs of interest are CustomObjectsAPI_replaceNamespacedCustomObject() CustomObjectsAPI_patchNamespacedCustomObjectStatus() But looking at the implementation kubernetes/api/CustomObjectsAPI.c, I see both call object_convertToJSON

    if (body != NULL)
    {
        //string
        localVarSingleItemJSON_body = object_convertToJSON(body);
        localVarBodyParameters = cJSON_Print(localVarSingleItemJSON_body);
    }

But object_convertToJSON(), does not do anything with the CJSON *item that is created in it

cJSON *object_convertToJSON(object_t *object) {
    cJSON *item = cJSON_CreateObject();

    return item;
fail:
    cJSON_Delete(item);
    return NULL;
}

As a result the localVarBodyParameters in CustomObjectsAPI_replaceNamespacedCustomObject() and CustomObjectsAPI_patchNamespacedCustomObjectStatus() methods are not set properly.

I also looked at the generics API in include/generic.h. The file does not have a patch/replace call for the status subresource.

Is this an issue with the code in the way object_convertToJSON() does not handle the object arg or is there another way to update the status sub resource of the CR?

ityuhui commented 1 year ago

The latest object.{h,c} in master branch have changed. Please check out and check if they can meet your requirement. You can populate the "patch json string" to object->temporary https://github.com/kubernetes-client/c/blob/eb35d276690107cfc57395e3b7388e549b81a17d/kubernetes/model/object.c#L25-L35

ityuhui commented 1 year ago

I also looked at the generics API in include/generic.h. The file does not have a patch/replace call for the status subresource.

Yes. the generic client cannot send the request to subresources(status, scale) now, we will add the feature later and the contributions are welcome !

hariramshankar commented 1 year ago

Thank you, the latest object.{h,c} in master and populating the JSON string to object->temporary works now when calling CustomObjectsAPI_replaceNamespacedCustomObject() and CustomObjectsAPI_patchNamespacedCustomObjectStatus()