kubernetes-client / c

Official C client library for Kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

hariramshankar opened this issue · comments

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?

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

cJSON *object_convertToJSON(object_t *object) {
if (!object) {
return NULL;
}
if (!object->temporary) {
return cJSON_Parse("null");
}
return cJSON_Parse(object->temporary);
}

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 !

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()