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

Add new function readNamespacedJobLog in the BatchV1Api #1663

Open
dalejo96 opened this issue Apr 25, 2024 · 2 comments
Open

Add new function readNamespacedJobLog in the BatchV1Api #1663

dalejo96 opened this issue Apr 25, 2024 · 2 comments

Comments

@dalejo96
Copy link

I want to get the logs from a certain job, but I am not sure about the right API to use, since on the terminal I do:

kubectl logs job.batch/my-job

I was expecting to find the function readNamespacedJobLog but it is not present in the BatchV1Api

How could I achieve this?

I can work on the PR if you provide some guidance.

Let me know what do you think

@brendandburns
Copy link
Contributor

In general this client tries to stay true to the Kubernetes RESTful API, and the logs call is associated with a Pod, not a Job.

The kubectl command is a short cut which looks up the Job and then finds the right pod (and then finds the logs)

We do have a hand-written logs client here:

https://github.com/kubernetes-client/javascript/blob/master/src/log.ts

If you wanted to add additional functionality there which got logs for Jobs (and other resources if you feel like it) that would be the best place to add it.

Thanks!

@dalejo96
Copy link
Author

dalejo96 commented May 6, 2024

Here is my workaroud using "@kubernetes/client-node": "^0.18.1"

    const labelSelector = `${JOB_NAME}=${name}`;
    const podList = await k8sCoreApi.listNamespacedPod(
      namespace,
      undefined,
      undefined,
      undefined,
      undefined,
      labelSelector
    );

    if (!podList.body.items[0]) {
      throw new CustomError('Error getting pod', 404);
    }
    const podName = podList.body.items[0].metadata.name;
    const podRes = await k8sCoreApi.readNamespacedPodLog(podName, namespace);

Where name is the jobName

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

2 participants