k8s-selector

1.0.1 • Public • Published

NPM version Build Status Coverage Status Dependency Status

k8s-selector

Kubernetes selector implementation in node

Implementation of stringify, parse and match for selectors in the Kubernetes API.

Methods

stringify(selector)

Stringifies a selector for use in a query parameter.

import { stringify } from "k8s-selector";
import rp from "request-promise";
 
rp.get({
    uri  : "http://localhost:8080/api/v1/pods",
    json : true,
    qs   : {
        matchLabels : stringify({
            matchLabels : {
                labelA : "a"
            },
            matchExpressions : [{
                operator : "In",
                key      : "labelB",
                values   : ["b", "B"]
            }]
        })
    }
});

parse(string)

Parses a Kubernetes API query param selector.

import assert from "assert";
 
import { parse } from "k8s-selector";
 
assert.deepEqual(parse("labelA = a, labelB != b"), {
    matchLabels : {
        labelA : "a"
    },
    matchExpressions : [{
        operator : "NotIn",
        key      : "labelB",
        values   : ["b"]
    }]
});

Selector(string|selector)

Implementation of Kubernetes selector matching logic.

import assert from "assert";
 
import { Selector } from "k8s-selector";
 
const selector = Selector("labelA = a");
 
assert.strictEqual(selector({ labelA : "a" }), true);

License

MIT License

Readme

Keywords

Package Sidebar

Install

npm i k8s-selector

Weekly Downloads

7

Version

1.0.1

License

MIT

Last publish

Collaborators

  • kjv