npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

k8s-job-trace

v1.0.1

Published

Track Kubernetes Job completion with JavaScript

Downloads

5

Readme

k8s-job-trace

This script tracks the execution of Kubernetes Jobs and report their completion success/failure. It requires kubectl to communicate with k8s cluster and wait for the job to complete. Logs generated from pod(s) running the job are piped to stdout/stderr in the current process, it's mean to shield off the details of which pods are running this job. When all you care about is a run to completion process.

Installing

npm install k8s-job-trace

Prerequisites

You will need to [install] kubectl on the system where this script is to run.

Also make sure your kubectl have been setup to access the desired cluster(s), this might need contacting the admin of your cluster if it's not managed by you.

You should have at least the permissions to view the jobs running in the cluster, verify by kubectl get jobs -n <namespace>, it should give a list of jobs (if any has created) like the following example:

$ kubectl get jobs
NAME        DESIRED   SUCCESSFUL   AGE
my-job           1             0            5s

Getting Started

First, we should have a deployment of the job desired to run in someway, being it's deployed via kubectl or installed via helm isn't really important. As soon as you have permission to run the deploy and is acknowledged about it's successful deployment.

Generally you should run this script immediately following the deployment/helm install/helm upgrade, specifying the job name as argument:

# This is the command that deploys the job to cluster... 

# Trace job run to completion 
k8s-job-trace $YOUR_JOB_NAME

# The exit code should reflect success/failure
if [ $? -eq 0 ]
then
  echo "The job ran ok"
  exit 0
else
  echo "The job failed" >&2
  exit 1
fi

Running the tests

To run test you need a (local) Kubernetes cluster where you have permission to deploy arbitrary job.

npm run test

This has been tested by running the script against different types of job specs, currently tested with the following cases:

  • success job run
  • failed job run
  • job pod timed out (specified in activeDeadlineSeconds)
  • job pod has image pull-error: (either ImagePullBackOff or ErrImagePull)

If you find a case not working for you, create an new issue and leave comments on how to reproduce it.

Code Style

JavaScript source are lint checked with ESLint & formatted by Prettier

npm run lint

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc