javascript icon indicating copy to clipboard operation
javascript copied to clipboard

`read` returns wrong struct for custom k8s objects, if name matches core API object

Open gnarlex opened this issue 8 months ago • 3 comments

Describe the bug When read()ing a custom k8s object, whose kind matches one of the core API object kinds, it constructs an object matching the core v1 type.

Example: monitoring.coreos.com/v1:Probe matches core/v1:Probe

Client Version 0.21.0

Server Version v1.28.4

To Reproduce Steps to reproduce the behavior:

  • Keep a custom k8s object in your cluster, with apiVersion monitoring.coreos.com/v1, and kind Probe, metadata.name="foo".
  • read probe "foo".

Expected behavior The correct, entire monitoring../v1:Probe object is returned.

Example Code

const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const client = kc.makeApiClient(k8s.KubernetesObjectApi);

const main = async () => {
    let {body: listRes} = await client
        .list('monitoring.coreos.com/v1', 'Probe', 'default');
    console.log(Object.entries(listRes.items[0]));
    /* monitoring.coreos.com/v1:Probe ✅
    [
      [ 'apiVersion', 'monitoring.coreos.com/v1' ],
      [ 'kind', 'Probe' ],
      [ 'metadata', {...} ],
      [ 'spec', {...} ],
    ]
    */

    let {body: readRes} = await client.read({
        apiVersion: 'monitoring.coreos.com/v1',
        kind: 'Probe',
        metadata: {
            name: 'foo',
            namespace: 'default'
        },
    });
    console.log(Object.entries(readRes));
    /* core/v1:Probe ❌
    [
      [ 'exec', undefined ],
      [ 'failureThreshold', undefined ],
      [ 'grpc', undefined ],
      [ 'httpGet', undefined ],
      [ 'initialDelaySeconds', undefined ],
      [ 'periodSeconds', undefined ],
      [ 'successThreshold', undefined ],
      [ 'tcpSocket', undefined ],
      [ 'terminationGracePeriodSeconds', undefined ],
      [ 'timeoutSeconds', undefined ]
    ]
    */
}

main();

Environment (please complete the following information):

  • OS: MacOs
  • NodeJS Version: 18.5.0

Additional context list() correctly returns the object as-is for custom object types. I suppose it matches the full version string, instead of just the v1 part.

gnarlex avatar Jun 23 '24 09:06 gnarlex