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

@fireblink/k8s-api-client

v1.2.0

Published

[![CircleCI](https://circleci.com/gh/FireBlinkLTD/k8s-api-client.svg?style=svg)](https://circleci.com/gh/FireBlinkLTD/k8s-api-client) [![codecov](https://codecov.io/gh/FireBlinkLTD/k8s-api-client/branch/master/graph/badge.svg)](https://codecov.io/gh/FireB

Downloads

5

Readme

K8s API Client

CircleCI codecov

Yet another K8s client that is NOT generated from OpenAPI spec and doesn't provide resource specific methods.

Instead this module allows to interact with K8s API by providing exact URN (URL path). While it may sound limited to what other modules provide - it is in fact more powerful.

Installation

If you're NPM user:

npm i --save @fireblink/k8s-api-client

If you're YARN user:

yarn add @fireblink/k8s-api-client

Usage

Make GET request(s)

Make GET request:

import { APIRequestProcessor } from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const resource = await processor.get('/apis/fireblink.com/v1/namespaces/default/customresources/resource-name');

Sometimes you may need to get all stored records and don't mess with pagination on your own. To do that use following helper function:

import { APIRequestProcessor } from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const response = await processor.getAll(
  '/apis/fireblink.com/v1/namespaces/default/customresources',
  // optionaly provide query parameters to pass with custom limit value, default one is 100
  {
    limit: 200,
  },
);

// Response contains all items:
console.log(response.items);

// and resourceVersion that might be handy to be used with "watch" action (see below)

Make POST request

import {APIRequestProcessor} from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const resource = await processor.post(
    '/apis/fireblink.com/v1/namespaces/default/customresources',
    // JSON request body:
    {
        apiVersion: 'fireblink.com/v1'
        kind: 'FTPO'
        metadata: {
            name: 'test'
        }
    },
     // optional query parameters:
    {}
);

Make PUT request

import {APIRequestProcessor} from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const resource = await processor.put(
    '/apis/fireblink.com/v1/namespaces/default/customresources/test',
    // JSON request body:
    {
        apiVersion: 'fireblink.com/v1'
        kind: 'FTPO'
        metadata: {
            resourceVersion: 1, // <- this is important for update operation
            name: 'test'
        }
    },
     // optional query parameters:
    {}
);

Make DELETE request

import { APIRequestProcessor } from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const resource = await processor.delete('/apis/fireblink.com/v1/namespaces/default/customresources/test');

Make PATCH request(s)

JSON Merge

The simpliest solution on how you may want to change existing resource. Please refer to RFC 7386 for more information on how merging is working.

import { APIRequestProcessor } from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const resource = await processor.merge('/apis/fireblink.com/v1/namespaces/default/customresources/test', {
  spec: {
    newField: 'yes',
    removeOld: null,
  },
});

JSON Patch

This is a more advanced version of how existing resources can be updated. Please refer to RFC 6902 for more information on how patching is working.

import { APIRequestProcessor } from '@fireblink/k8s-api-client';

const processor = new APIRequestProcessor();
const resource = await processor.merge('/apis/fireblink.com/v1/namespaces/default/customresources/test', [
  { op: 'add', path: '/spec/newItem', value: 'yes' },
  { op: 'remove', path: '/spec/removeOld' },
]);

Watch

Another common usecase is to have a listener to track K8s resource changes.

import { WatchRequestProcessor } from '@fireblink/k8s-api-client';

const processor = new WatchRequestProcessor();

await processor.watch(
  '/apis/fireblink.com/v1/namespaces/default/customresources',
  {
    // called when object is added
    added: async (obj: any) => {},

    // called when object get changed
    modified: async (obj: any) => {},

    // called when object get removed
    deleted: async (obj: any) => {},
  },
  // optionally provide resourceVersion as a third parameter
);

Note: Request may fail with 410 HTTP status code (GONE). When this happens you generally need to refetch the list of records and start watching resource again with a fresh resourceVersion (see getAll method above).