Closed shayan-eftekhari closed 6 months ago
Does the apiClient->response_code
meet your requirement ?
FYI https://github.com/kubernetes-client/c/issues/31#issuecomment-704710140
Thank you for looking into this. In this case (already existing job) response_code is 409 which is HTTP conflict. However, the BatchV1APIlocalVarJSON is a json object which has the exact error "jobs.batch
I can imagine the API may fail for various reasons (e.g. lack of some required fields in body), so being able to access this error message for the caller is a big plus.
In the provided example, CoreV1API_deleteNamespacedPod returns a v1_status_t which apparently has a field named message. This is exactly what I'm looking for in v1_job_t.status (data type: v1_job_status_t).
What's the value of elementToReturn
in your code ?
elementToReturn = { api_version = "v1", kind = "Status", metadata = { // All fields are 0 or NULL }, spec = NULL, status = { // All fields are 0 or NULL } }
Can you try to debug the function v1_job_parseFromJSON
and v1_job_status_parseFromJSON
to check why the v1_job_status_t
is NULL ?
# Build
mkdir build
cd build
# If you want to use `gdb` to debug the C client library, add `-DCMAKE_BUILD_TYPE=Debug` to the cmake command line, e.g.
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
Here is the content of BatchV1APIlocalVarJSON that is passed to the v1_job_parseFromJSON function:
{
"apiVersion": "v1",
"kind": "status",
"metadata": null,
"status": "Failure",
"message": "jobs.batch \"hello-world\" already exists",
"reason": "AlreadyExists",
"code": 409,
"details": {
"name": "hello-world",
"kind": "jobs",
"group": "batch"
}
}
Then, the v1_job_parseFromJSON funtion extracts the status part:
cJSON *status = cJSON_GetObjectItemCaseSensitive(v1_jobJSON, "status");
which is a JSON string, "Failure", without any child (type: 16) and the passes it to the v1_job_status_parseFromJSON function. This function is then repeatedly calls cJSON_GetObjectItemCaseSensitive function to extract fields including "active", "completedIndexes", "completionTime", etc. However, cJSON_GetObjectItemCaseSensitive expects its input to be JSON object with a child and since it doesn't find a child, it returns NULL for all of them.
I see.
So if you want detailed error messages instead of error codes like 409
, I think the only way is to use generic client https://github.com/kubernetes-client/c/issues/31#issuecomment-707207108 to send the request and parse the json by yourself.
FYI https://github.com/kubernetes-client/c/tree/master/examples/generic
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle stale
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle rotten
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/reopen
/remove-lifecycle rotten
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
Hi,
I'm using the BatchV1API_createNamespacedJob API to create a Job.
If for any reason the process fails (e.g. if a job with the same name already exists), the API still returns a v1_job_t* with a kind equal to "Status" instead of "Job" but there is no way to understand the reason.
I digged into its implementation and I found this:
https://github.com/kubernetes-client/c/blob/6a82bde3470171aa3e8965f9e3766bda5fa5b170/kubernetes/api/BatchV1API.c#L327
The BatchV1APIlocalVarJSON local variable holds the actual reason, so I'm wondering if there is a way to report it back.
This might be also true on other APIs but I have not examined them yet.
Would you please let me know if there is a way to access the failure reason through the API, or if there is not, do you have a plan to make it possible? I'm wondering if it is possible to extend v1_job_status_t struct to hold such information.
Thank you in advance.