c icon indicating copy to clipboard operation
c copied to clipboard

v1_daemon_set_convertToJSON is returning NULL cJSON object

Open hirishh opened this issue 2 years ago • 16 comments

Hello,

I've debugged this and this function is returning null while parsing the status. I have a simple Daemonset with this status:

status:
  currentNumberScheduled: 1
  numberMisscheduled: 0
  desiredNumberScheduled: 1
  numberReady: 1
  observedGeneration: 1
  updatedNumberScheduled: 1
  numberAvailable: 1

The conversion is failing here: https://github.com/kubernetes-client/c/blob/master/kubernetes/model/v1_daemon_set_status.c#L113

Is there any reason why this code must check the value of the int and fail if it's zero? I don't understand the logic here.

Best,

hirishh

hirishh avatar Jun 06 '23 09:06 hirishh

I think this is a defect that has never been raised before. Thank you for reporting this.

ityuhui avatar Jun 06 '23 13:06 ityuhui

If you want to fix this issue, please note that the code is generated by openapi-generator from here: https://github.com/OpenAPITools/openapi-generator/blob/59ba00e1f3ddb1efa5ae064987cb4e5a6286e8d5/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache#L357

ityuhui avatar Jun 07 '23 02:06 ityuhui

If you want to fix this issue, please note that the code is generated by openapi-generator from here: https://github.com/OpenAPITools/openapi-generator/blob/59ba00e1f3ddb1efa5ae064987cb4e5a6286e8d5/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache#L357

Thank you for pointing me out. I tried to had a look. As far as I understand the problem is when a field is an int and also required, indeed the same issue is present for currentNumberScheduled, desiredNumberScheduled and numberReady that are required fields in the deamonset status object.

But I have zero experience with openapi-generator and I'm struggling with the syntax there (for example I don't understand the difference between {{#required}} and {{^required}}, maybe # -> is and ^-> is not) ?

hirishh avatar Jun 07 '23 10:06 hirishh

Maybe this is enough to fix the issue? (L333 - L344)

    {{#required}}
    {{^isEnum}}
    {{^isNumeric}}
    if (!{{{classname}}}->{{{name}}}) {
        goto fail;
    }
    {{/isNumeric}}
    {{/isEnum}}
    {{#isEnum}}
    if ({{projectName}}_{{classVarName}}_{{enumName}}_NULL == {{{classname}}}->{{{name}}}) {
        goto fail;
    }
    {{/isEnum}}
    {{/required}}

hirishh avatar Jun 07 '23 10:06 hirishh

Your fix is correct. Now it can return a valid cJSON object. We can also add ^isBoolean here to fix boolean type (0).

And for the non-required property, we'd better to add the code too:

    {{^required}}  <-- L345
    {{^isEnum}}
    {{^isNumeric}}
    {{^isBoolean}}
    if({{{classname}}}->{{{name}}}) {
    {{/isBoolean}}
    {{/isNumeric}}
    {{/isEnum}}
    {{#isEnum}}
    if({{{classname}}}->{{{name}}} != {{projectName}}_{{classVarName}}_{{enumName}}_NULL) {
    {{/isEnum}}
    {{/required}}
    {{^required}}  <-- L550
    {{^isNumeric}}
    {{^isBoolean}}
    }
    {{/isBoolean}}
    {{/isNumeric}}
    {{/required}}

ityuhui avatar Jun 07 '23 13:06 ityuhui

Hello @ityuhui, how we should proceed with this issue?

hirishh avatar Jun 12 '23 09:06 hirishh

I'll look at the reviewer's comments and talk with him.

ityuhui avatar Jun 13 '23 01:06 ityuhui

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

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

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Jan 22 '24 10:01 k8s-triage-robot

/remove-lifecycle stale

ityuhui avatar Jan 23 '24 06:01 ityuhui

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

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

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Apr 22 '24 07:04 k8s-triage-robot

Hello @ityuhui, I saw you implemented the int* for the client part in the openapi-generator. Is there any plan to implement it also in the model? I do not want to seem pushy, it is not my intention :)

hirishh avatar Apr 23 '24 13:04 hirishh

This task is on the top of my list. Maybe in a month I'll start.

ityuhui avatar Apr 23 '24 14:04 ityuhui

/remove-lifecycle stale

ityuhui avatar Apr 23 '24 14:04 ityuhui

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

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

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Jul 22 '24 15:07 k8s-triage-robot

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle rotten

k8s-triage-robot avatar Aug 21 '24 16:08 k8s-triage-robot

/remove-lifecycle rotten

ityuhui avatar Aug 22 '24 03:08 ityuhui