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

@operate-first/probot-kubernetes

v1.0.3

Published

Probot extension to interact with Kubernetes

Downloads

24

Readme

Probot on Kubernetes

This extension enables you to interface Kubernetes from Probot with ease. It's a simple wrapper on top of @kubernetes/client-node.

Installation

npm install --save @operate-first/probot-kubernetes

Overview

  • useApi(<API>): Instantiate any Kubernetes Api from within current context, using credentials available either locally or passed down by a Service Account.
  • getNamespace(): Fetch current active namespace available from current context.
  • APIS: Re-export of @kubernetes/client-node for easy access to Kubernetes APIs.
  • useK8sTokenStore(probotInstance): Full lifecycle management extending your Probot instance to store access tokens in Kubernetes Secrets. Secret is created on installation.created event, deleted on installation.deleted event and continously updated on any event received. The secret is named probot-<INSTALLATION_ID> and stored in current active namespace.

Additionally this library offers CRUD methods for the secret management allowing more granular control:

  • createTokenSecret(context): Promise which creates the token secret.
  • getTokenSecretName(context): Returns secret name relevant to current context.
  • updateTokenSecret(context): Promise which updates the token secret.
  • deleteTokenSecret(context): Promise which deletes the token secret.

Usage

Using useK8sTokenStore(probotInstance) middleware

const kubernetes = require('@operate-first/probot-kubernetes');

module.exports = app => {
    kubernetes.useK8sTokenStore(app);

    app.on('push', (context) => {
        const jobPayload = {
            apiVersion: 'batch/v1',
            kind: 'Job',
            metadata: {
                generateName: 'hello-world-'
            },
            spec: {
                template: {
                    spec: {
                        containers: [
                            {
                                name: 'default',
                                image: 'alpine:latest',
                                command: ['/bin/sh', '-c', 'echo "$ORG_NAME: ${GITHUB_TOKEN:0:2}..."'],
                                env: [
                                    {
                                        name: 'ORG_NAME',
                                        valueFrom: {
                                            secretKeyRef: {
                                                name: kubernetes.getTokenSecretName(context),
                                                key: 'orgName'
                                            }
                                        }
                                    },
                                    {
                                        name: 'GITHUB_TOKEN',
                                        valueFrom: {
                                            secretKeyRef: {
                                                name: kubernetes.getTokenSecretName(context),
                                                key: 'token'
                                            }
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            }
        }

        await kubernetes.useApi(kubernetes.APIS.BatchV1Api).createNamespacedJob(kubernetes.getNamespace(), jobPayload);
    });
}

Using individual methods

In case you want to wrap the lifecycle methods in any additional logic, it is possible to call each CRUD method individually.

const kubernetes = require('@operate-first/probot-kubernetes');

module.exports = app => {
    app.on('installation.created', async (context) => {
        await kubernetes.createTokenSecret(context);
    });

    app.on('installation.deleted', async (context) => {
        await kubernetes.deleteTokenSecret(context);
    });

    app.onAny(async (context) => {
        await kubernetes.updateTokenSecret(context);
    });

    app.on('push', (context) => {
        const jobPayload = {
            // see above
            // ...
        }

        await kubernetes.useApi(kubernetes.APIS.BatchV1Api).createNamespacedJob(kubernetes.getNamespace(), jobPayload);
    });
};