Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return strong types in generic client #854

Merged
merged 2 commits into from
Aug 11, 2022

Conversation

schrodit
Copy link
Contributor

@schrodit schrodit commented Aug 1, 2022

  • Also use generics to make the generic client easier usable without casting.
    e.g.
    const client = kc.makeApiClient(k8s.KubernetesObjectApi);
    const pod = (await client.read<V1Pod>({apiVersion: 'v1', kind: 'Pod', metadata: {name: 'test', namespace: 'default'}})).body;
  • The read function is more strongly typed to better represent that only the header (apiVersion, kind, metadata.name) is needed
  • The usage of the client is backwards compatible so all current code should work as before. But some types might change.
    e.g. the following types differ when dealing with pods (or other known types)
const client = kc.makeApiClient(k8s.KubernetesObjectApi);
const pod = (await client.read({apiVersion: 'v1', kind: 'Pod', metadata: {name: 'test', namespace: 'default'}})).body;

// before
pod.metadata.creationTimestamp // --> string
// with this change
pod.metadata.creationTimestamp // --> Date

Issue: #852

⚠️ There is still an issue that custom resources or KubernetesObject is not correctly parsed, due to the current ObjectSerialzer.deserializer implementation. I will provide a separate PR to fix this issue

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 1, 2022
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 1, 2022
@schrodit
Copy link
Contributor Author

schrodit commented Aug 1, 2022

/assign @brendandburns

@brendandburns
Copy link
Contributor

One minor comment, otherwise lgtm.

@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 11, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, schrodit

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 11, 2022
@k8s-ci-robot k8s-ci-robot merged commit eaf1b23 into kubernetes-client:master Aug 11, 2022
@schrodit schrodit deleted the fix-types branch August 11, 2022 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants