kubernetes-client / c

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

CoreV1API_readNamespacedPodLog doesn't work and contains a segfault #222

Open homer6 opened 4 months ago

homer6 commented 4 months ago

The text/plain header is being rejected:

{\n  \"kind\": \"Status\",\n  \"apiVersion\": \"v1\",\n  \"metadata\": {},\n  \"status\": \"Failure\",\n  \"message\": \"only the following media types are accepted: application/json, application/yaml, application/vnd.kubernetes.protobuf\",\n  \"reason\": \"NotAcceptable\",\n  \"code\": 406\n}

Commenting out that header makes it work again. However, when it proceeds it'll segfault on the strdup line if there aren't any pod logs (null pointer).

I moved the strdup into the null pointer guard and it works now for pods both with and without logs.

    char* elementToReturn = NULL;

    if (apiClient->dataReceived) {
        elementToReturn = strdup((char*)apiClient->dataReceived);
        free(apiClient->dataReceived);
        apiClient->dataReceived = NULL;
        apiClient->dataReceivedLen = 0;
    }
    list_freeList(localVarQueryParameters);
brendandburns commented 4 months ago

read pod logs is a non-restful compliant API, I suspect that we will need to write custom code to correctly handle it.

homer6 commented 4 months ago

It works after the code change. I'll submit a PR.

I'm writing a c++ client that wraps this library: https://github.com/homer6/kubepp

brendandburns commented 4 months ago

Unfortunately, that code is generated. If we want to make changes, we need to change the upstream generator (and validate that it doesn't break other API calls)

cc @ityuhui

brendandburns commented 4 months ago

Also, for your C++ client, I would also recommend you take a code generation approach, since it is basically impossible to keep up with the breadth of the Kubernetes API without code generation.

homer6 commented 4 months ago

That makes sense. However, I'm finding that a number of function calls are not working as expected. By implementing each call individually, I'm able to validate that the calls are working as expected.

So far, I've only implemented a handful of methods and most of them have failed in different ways.

Sorry for the poor feedback. I'm actually really excited to keep going with wrapping this library.

ityuhui commented 4 months ago

As @brendandburns said, the code in this library is generated by openapi-generator/libcurl https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/C-libcurl

Code changes you commit to this repository will be removed on the next generating.

Feel free to submit your PR here and we can review the code changes and suggest changes to openapi-generator/libcurl.

Don't wait for all changes to be done to submit your PR as your PR is just for review. Only 1 or 2 changes are OK.

homer6 commented 4 months ago

Thanks @ityuhui, I've created #227 to review for changes. This change should allow pods logs to be retrieved again.

k8s-triage-robot commented 1 month ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 1 day ago

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:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten