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

1.0.0 released - where are the migration docs? #2117

Open
klippx opened this issue Dec 19, 2024 · 8 comments
Open

1.0.0 released - where are the migration docs? #2117

klippx opened this issue Dec 19, 2024 · 8 comments

Comments

@klippx
Copy link

klippx commented Dec 19, 2024

Describe the bug

HttpError is no longer exported in 1.0.0

** Client Version **
1.0.0

To Reproduce
Prior to 1.0.0:

import * as k8s from '@kubernetes/client-node';

try {
  // do something with k8s
} catch (e) {
  if (e instanceof k8s.HttpError) {
    console.error(e.body);
  }
}

Expected behavior
If HttpError is not exported, I would be happy to see any upgrade docs state what the replacement is.

@brendandburns
Copy link
Contributor

1.0.0 marks a major switch in the HTTP backend from request which has been deprecated for years to node-fetch which is still supported.

Unfortunately, there's breaking changes all over the place as a result of this switch. We would definitely love help in authoring a migration guide, at this point the best thing to do is to look at the examples in the release-1.x branch:

https://github.com/kubernetes-client/javascript/tree/release-1.x/examples

@brendandburns
Copy link
Contributor

There's also fairly extensive discussion here:

#414

@cjihrig
Copy link
Contributor

cjihrig commented Dec 19, 2024

HttpError is no longer exported in 1.0.0

It looks like the new generator does have an HttpException class. However, it doesn't appear to actually be used anywhere in the code.

@jportner
Copy link
Contributor

jportner commented Dec 27, 2024

1.0.0 marks a major switch in the HTTP backend from request which has been deprecated for years to node-fetch which is still supported.

Unfortunately, there's breaking changes all over the place as a result of this switch. We would definitely love help in authoring a migration guide, at this point the best thing to do is to look at the examples in the release-1.x branch:

https://github.com/kubernetes-client/javascript/tree/release-1.x/examples

@brendandburns I looked to see if I could start taking a stab at this, but it appears that at least some of the examples might be incorrect/outdated?

I can't find a single updated example that shows how to handle an error and determine if a resource doesn't exist...

@cjihrig
Copy link
Contributor

cjihrig commented Dec 27, 2024

I can't find a single updated example that shows how to handle an error and determine if a resource doesn't exist...

The examples definitely need a refresh. Here is a way of doing that in the new API:

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

try {
  const pod = await k8sApi.readNamespacedPod({ name: 'does-not-exist', namespace: 'default' });
  console.log(pod);
} catch (err) {
  const isNotFoundError = err instanceof k8s.ApiException && err.code === 404;
  console.log(isNotFoundError);
}

The ApiException type also has a .body property that includes more details:

'{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pods \\"does-not-exist\\" not found","reason":"NotFound","details":{"name":"does-not-exist","kind":"pods"},"code":404}\n'

Unfortunately, you currently have to JSON.parse() that field since it is a JSON string instead of an object.

cjihrig added a commit to cjihrig/kubenode that referenced this issue Dec 27, 2024
This is something that changed with v1.0.0 of the K8s client.

Refs: kubernetes-client/javascript#2117
@cjihrig
Copy link
Contributor

cjihrig commented Dec 27, 2024

Shameless plug, but I have been porting some Golang K8s utilities to Node.js. These functions in particular can be used to check error types. I just published an updated version of them that should work with v0.x and v1.x. It would look something like this:

import * as k8s from '@kubernetes/client-node';
import { apimachinery } from '@kubenode/controller-runtime';

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

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
try {
  const pod = await k8sApi.readNamespacedPod({ name: 'does-not-exist', namespace: 'default' });
  console.log(pod);
} catch (err) {
  console.log(apimachinery.errors.isNotFound(err));
}

@brendandburns
Copy link
Contributor

We'd be happy to take PRs updating the examples. A lot of them were ported over and as long as they compiled they were assumed to be "working"

That's clearly not an awesome way to determine if they are correct. Help cleaning them up would be appreciated.

@koooge
Copy link

koooge commented Jan 13, 2025

Hi there, how do we migrate patch APIs? It looks like patch-example.js uses the internal PromiseMiddlewareWrapper as mentioned in #754.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants