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

Merge upstream to browser #4

Draft
wants to merge 159 commits into
base: browser
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
fb1ee0c
openid token management implementation
Aug 26, 2019
74ed0f5
Merge pull request #335 from louis-murray/oidc
k8s-ci-robot Sep 2, 2019
2800e12
Update to 1.15 API.
brendandburns Sep 25, 2019
f134596
Fix packaging.
brendandburns Sep 16, 2019
339ed1f
Merge pull request #346 from brendandburns/package
k8s-ci-robot Sep 25, 2019
f4975ce
Merge pull request #347 from brendandburns/rev
k8s-ci-robot Sep 26, 2019
a22e29f
Rev diff dependency to handle security update.
brendandburns Sep 26, 2019
a5e4aab
Merge pull request #348 from brendandburns/rev
k8s-ci-robot Sep 26, 2019
ca523c1
use command as quoted string in CloudAuth
jnummelin Oct 10, 2019
2e9dbfa
use test script with spaces in the name for echoing the token json
jnummelin Oct 11, 2019
9e10c20
Merge pull request #352 from jnummelin/fix/whitespace-in-commands-for…
k8s-ci-robot Oct 13, 2019
6bf2b75
Fix a bug if the headers array is null or undefined in exec auth.
brendandburns Oct 13, 2019
ae1c897
Merge pull request #354 from brendandburns/headers
k8s-ci-robot Oct 13, 2019
e3a23fe
Update to version 0.11.0
brendandburns Oct 14, 2019
dee4f8a
Merge pull request #355 from brendandburns/rev
k8s-ci-robot Oct 14, 2019
d5db5ac
fix OIDC refresh token storage with user auth config
jnummelin Oct 16, 2019
9d5757e
Merge pull request #357 from jnummelin/fix/refresh-token-storing
k8s-ci-robot Oct 17, 2019
00a7166
Remove unused package
Leo7654 Nov 12, 2019
caa7130
update openapi generator to v4.1.3
b1zzu Nov 13, 2019
b9a90a5
Merge pull request #366 from b1zzu/master
k8s-ci-robot Nov 14, 2019
cf6c628
Fix bugs in programatic cluster config. Add unit test.
brendandburns Nov 15, 2019
2109605
Merge pull request #363 from Leo7654/patch-1
k8s-ci-robot Nov 19, 2019
ca55c20
Don't require client-secret in OIDC authentication.
brendandburns Nov 19, 2019
c7892e3
Fix error handling for watches. Add unit tests.
brendandburns Nov 19, 2019
6da9a88
Add an export function.
brendandburns Nov 19, 2019
34cfa68
Merge pull request #368 from brendandburns/configit
k8s-ci-robot Nov 19, 2019
36c9095
Merge pull request #369 from brendandburns/watch
k8s-ci-robot Nov 19, 2019
ef592cf
Merge pull request #371 from brendandburns/oidc
k8s-ci-robot Nov 19, 2019
d262aff
Merge pull request #372 from brendandburns/export
k8s-ci-robot Nov 22, 2019
d46b16c
Fix example to only list from one namespace.
brendandburns Dec 11, 2019
2bcb2e1
Merge pull request #378 from brendandburns/fix
k8s-ci-robot Dec 11, 2019
2f9b7c7
Add ipv6 support.
brendandburns Dec 21, 2019
da9f3d8
Merge pull request #381 from brendandburns/fix
k8s-ci-robot Dec 22, 2019
50b6e63
Update handlebars dependency.
brendandburns Jan 7, 2020
58aa674
Merge pull request #387 from brendandburns/fix
k8s-ci-robot Jan 7, 2020
03b39df
Improve the OIDC auth to pull the expiration date from the token.
brendandburns Jan 8, 2020
701b524
Fix oidc implementation, add more extensive tests.
brendanburns Jan 11, 2020
4b8d5ac
Remove a requirement that `apiVersion` be present in the config.
brendanburns Jan 11, 2020
a7f33ef
Remove requirement that apiVersion be specified.
brendanburns Jan 11, 2020
aa0b274
Merge pull request #391 from brendandburns/validate
k8s-ci-robot Jan 11, 2020
632b3f9
Merge pull request #388 from brendandburns/oidc
k8s-ci-robot Jan 11, 2020
f2da2e8
Fix issue with authentication on watch due to async not being awaited
kellycampbell Jan 15, 2020
ced85fc
Add error handling to informer
kellycampbell Jan 15, 2020
8a130da
Merge pull request #393 from kellycampbell/add-error-handling
k8s-ci-robot Jan 15, 2020
fbd3c1f
Merge pull request #394 from kellycampbell/fix-watch-auth
k8s-ci-robot Jan 15, 2020
e4ac479
Fix watch to emit an error twice on error. Add tests.
brendanburns Jan 22, 2020
568a853
Merge pull request #396 from brendandburns/validate
k8s-ci-robot Jan 24, 2020
db42c66
Update to version 0.11.1
brendanburns Feb 1, 2020
f7d046f
Merge pull request #407 from brendandburns/rev
k8s-ci-robot Feb 1, 2020
96bb098
Headers should be an object
inikolaev Feb 2, 2020
35c50ae
Await for authentication to be applied to request
inikolaev Feb 2, 2020
22419a7
Merge pull request #408 from inikolaev/405-log-authentication
k8s-ci-robot Feb 4, 2020
ba0dc1a
Fixed missing variable initialization
runi95 Feb 5, 2020
36d6774
Merge pull request #410 from runi95/patch-1
k8s-ci-robot Feb 10, 2020
77bd5e6
Update coverage. Add more tests.
brendandburns Nov 20, 2019
84e9bb6
Merge pull request #412 from brendandburns/coverage
k8s-ci-robot Feb 13, 2020
728f852
Initial implementation of top for nodes.
brendandburns Feb 13, 2020
0ba4d5d
Add tests.
brendandburns Feb 14, 2020
c4cb511
Improve test coverage.
brendandburns Feb 23, 2020
e4e34dd
Merge pull request #417 from brendandburns/coverage
k8s-ci-robot Feb 25, 2020
ba4423e
Merge pull request #415 from brendandburns/top
k8s-ci-robot Feb 27, 2020
b3e748c
Update openapi generator v4.2.3
sheldonkwok Feb 27, 2020
9fd4d76
Regenerate api with openapi generator v4.2.3
sheldonkwok Feb 28, 2020
fe9bfd1
Merge pull request #418 from sheldonkwok/feature/update-openapi-gener…
k8s-ci-robot Mar 3, 2020
e588799
fix: add defaultHeaders field to ApiType interface
brandonc Mar 24, 2020
76d8776
Merge pull request #424 from brandonc/master
k8s-ci-robot Apr 9, 2020
c3e5aeb
Add a test for exec token caching and fix the implementation.
brendanburns Apr 16, 2020
71f310c
Merge pull request #431 from brendandburns/oidc
k8s-ci-robot Apr 17, 2020
8382339
add github action.
brendandburns Apr 20, 2020
7d1c65a
Merge pull request #433 from brendandburns/deps
k8s-ci-robot Apr 20, 2020
9aa60b4
Fix lint action, fix lint error.
brendandburns Apr 20, 2020
d645727
Merge pull request #434 from brendandburns/coverage
k8s-ci-robot Apr 20, 2020
c1594c3
Update package version.
brendandburns Apr 21, 2020
3ef3738
Merge pull request #436 from brendandburns/coverage
k8s-ci-robot Apr 21, 2020
d6234f5
[DOC] Show an example of creating an ingress
FossPrime Apr 25, 2020
ba38464
Shortened PR
FossPrime Apr 25, 2020
333732b
Merge pull request #437 from rayfoss/patch-1
k8s-ci-robot Apr 26, 2020
2c06552
Bump jquery from 3.4.1 to 3.5.0
dependabot[bot] Apr 30, 2020
2282ec8
Merge pull request #439 from kubernetes-client/dependabot/npm_and_yar…
k8s-ci-robot May 1, 2020
33d2aff
Update generator settings
tux-rampage May 12, 2020
a2e0c3e
Regenerate api from Kubernetes 1.18 OpenAPI specs
tux-rampage May 12, 2020
a00b451
Remove unused import of removed api type
tux-rampage May 12, 2020
e150480
Merge pull request #445 from tux-rampage/k8s-api-1.18
k8s-ci-robot May 14, 2020
d292a4d
Add KubernetesObjectApi
May 11, 2020
bb63943
Address PR #446 reviewer comments
May 14, 2020
9aeafe2
Merge pull request #446 from ddgenome/object-api
k8s-ci-robot May 18, 2020
7a070c2
Update to version 0.12.0
brendandburns May 19, 2020
7590f31
Merge pull request #452 from brendandburns/master
k8s-ci-robot May 19, 2020
5fa7604
Add initial support for the BOOKMARK message in watch.
brendandburns Jun 4, 2020
79736b9
Merge pull request #460 from brendandburns/watch
k8s-ci-robot Jun 5, 2020
9f5785b
Upgrade dependencies.
brendanburns Jun 6, 2020
932c2fb
Merge pull request #462 from brendandburns/deps
k8s-ci-robot Jun 8, 2020
33853a4
Create examples/scale-deployment.js
phantomlsh Jul 14, 2020
c299acf
Update scale-deployment.js
phantomlsh Jul 15, 2020
a93f9c6
Merge pull request #476 from phantomlsh/patch-1
k8s-ci-robot Jul 16, 2020
81d6fee
Remove unnecessary assignment in constructor
jvassev Jul 20, 2020
24aec77
Merge pull request #477 from jvassev/remove-assignment
k8s-ci-robot Jul 23, 2020
3e89292
Rev the commit for the kubernetes gen repo.
brendandburns Jul 23, 2020
6682421
Update generated code.
brendandburns Jul 23, 2020
3b8cc30
feat: add cp command and test
vip30 Jul 27, 2020
598796f
Merge pull request #482 from vip30/master
k8s-ci-robot Jul 28, 2020
5b8c30d
Make watch path match listFn
chriskinsman Jul 28, 2020
6565f66
Merge pull request #483 from chriskinsman/master
k8s-ci-robot Jul 29, 2020
b218eb9
Merge pull request #480 from brendandburns/gen
k8s-ci-robot Jul 29, 2020
05f39ff
update ws
si458 Aug 31, 2020
a162209
Merge pull request #493 from si458/master
k8s-ci-robot Sep 1, 2020
5762d5f
Add option to filter invalid items when loading a config
Nokel81 Sep 16, 2020
ce450c8
revert unnecessary dep ver bump
Nokel81 Sep 16, 2020
ef0c2f3
Merge pull request #500 from Nokel81/config-load-filter
k8s-ci-robot Sep 17, 2020
eff84f4
Update to version 0.12.2
brendandburns Sep 17, 2020
0047bb0
Update the build status sticker to GH actions.
brendandburns Sep 17, 2020
c8ee5ae
Merge pull request #501 from brendandburns/release
k8s-ci-robot Sep 17, 2020
d95e847
Merge pull request #502 from brendandburns/travis
k8s-ci-robot Sep 17, 2020
d57b321
Move stream-buffers from devDependencies to dependencies
jc-roman Sep 18, 2020
af4909a
Merge pull request #506 from TheWeatherCompany/hotfix/503-stream-buff…
k8s-ci-robot Sep 19, 2020
592ea49
Add some constants and an example of patching resources.
brendanburns Sep 20, 2020
dfd12b1
Require typedef in the style. Add some missing return types.
brendanburns Sep 20, 2020
db9d94d
Update openid-client version to 4.1.1
NicolasFloquet Sep 22, 2020
931509a
Merge pull request #510 from NicolasFloquet/openid-client-upgrade
k8s-ci-robot Sep 22, 2020
daf505a
Add node v14 to github actions tests
jc-roman Oct 4, 2020
ff1d099
Merge pull request #520 from TheWeatherCompany/support-node-14
k8s-ci-robot Oct 4, 2020
5a476fb
Update cp.ts
Nebojsa92 Oct 6, 2020
9472154
Update cp_test.ts
Nebojsa92 Oct 11, 2020
4d40e96
Merge pull request #521 from Nebojsa92/master
k8s-ci-robot Oct 11, 2020
182b886
Merge pull request #507 from brendandburns/types
k8s-ci-robot Oct 12, 2020
906d227
Merge pull request #508 from brendandburns/patch
k8s-ci-robot Oct 12, 2020
1b313ce
Fix timeout on watch.js requestOptions
jhagestedt Oct 15, 2020
d83eeb4
Fix lint.
brendanburns Oct 22, 2020
599bba7
Merge pull request #531 from brendandburns/fix
k8s-ci-robot Oct 22, 2020
ae158e6
Fix badge image.
brendandburns Oct 22, 2020
dd46111
Update to version 0.12.3
brendanburns Sep 22, 2020
a3ddcae
Merge pull request #532 from brendandburns/master
k8s-ci-robot Oct 22, 2020
963e657
Update owners file to move mbohlool to emeritus
brendanburns Oct 22, 2020
9433c0f
Merge pull request #533 from brendandburns/owners
k8s-ci-robot Oct 23, 2020
f000f0a
Upgrade to 1.19 API
weikinhuang Oct 23, 2020
cdc5814
Update to version 0.12.3
brendanburns Oct 23, 2020
61f8d36
Merge pull request #534 from weikinhuang/k8s-v1.19.0
k8s-ci-robot Oct 23, 2020
2dac326
Merge pull request #535 from brendandburns/version
k8s-ci-robot Oct 31, 2020
65646ba
Rev to 0.13.0
brendanburns Oct 31, 2020
890d1c4
Update README.md
brendandburns Nov 1, 2020
6d53ddc
Merge pull request #538 from brendandburns/version
k8s-ci-robot Nov 1, 2020
e7d4891
Update to version 0.13.1
brendanburns Nov 3, 2020
a095e3a
fix tests on windows.
brendandburns Nov 3, 2020
5e82fb3
Create codeql-analysis.yml
brendandburns Nov 10, 2020
9146f8e
Merge pull request #553 from kubernetes-client/brendandburns-patch-1
k8s-ci-robot Nov 11, 2020
b472c36
Merge pull request #543 from brendandburns/version
k8s-ci-robot Nov 12, 2020
8b38f89
Bump lodash from 4.17.14 to 4.17.20
dependabot[bot] Nov 12, 2020
f2de5e7
Merge pull request #546 from brendandburns/windows
k8s-ci-robot Nov 12, 2020
be4ecd1
Merge pull request #554 from kubernetes-client/dependabot/npm_and_yar…
k8s-ci-robot Nov 12, 2020
9e175e8
split watch error and watch done handlers.
brendandburns Nov 13, 2020
437218d
Merge pull request #555 from brendandburns/informer
k8s-ci-robot Nov 16, 2020
4484540
Bump highlight.js from 9.15.10 to 9.18.5
dependabot[bot] Nov 25, 2020
3eded58
Merge pull request #526 from jhagestedt/patch-1
k8s-ci-robot Nov 25, 2020
a6b0d4b
Merge pull request #560 from kubernetes-client/dependabot/npm_and_yar…
k8s-ci-robot Nov 25, 2020
2de5a09
Fix a typo
paolomainardi Dec 9, 2020
80cd74d
Merge pull request #565 from paolomainardi/patch-2
k8s-ci-robot Dec 9, 2020
a4a6c03
Update to version 0.13.2
brendanburns Dec 19, 2020
a14b1d3
Merge pull request #571 from brendandburns/master
k8s-ci-robot Dec 19, 2020
991fd87
Merge origin/master into browser (using imerge)
NicolasT Dec 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
68 changes: 68 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
# ******** NOTE ********

name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '35 14 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Kubernetes Javascript Client - Validation

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '12', '10' ]
name: Node ${{ matrix.node }} validation
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
# Pre-check to validate that versions match between package.json
# and package-lock.json. Needs to run before npm install
- run: node version-check.js
- run: npm install
- run: npm test
- run: npm run lint

15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- brendandburns
- mbohlool
reviewers:
- brendandburns
- mbohlool
- drubin
- itowlson
emeritus_approvers:
- mbohlool # 10/22/2020
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Javascript Kubernetes Client information

[![Build Status](https://travis-ci.org/kubernetes-client/javascript.svg?branch=master)](https://travis-ci.org/kubernetes-client/javascript)
[![Build Status](https://github.com/kubernetes-client/javascript/workflows/Kubernetes%20Javascript%20Client%20-%20Validation/badge.svg)](https://github.com/kubernetes-client/javascript/actions)
[![Client Capabilities](https://img.shields.io/badge/Kubernetes%20client-Gold-blue.svg?style=flat&colorB=FFD700&colorA=306CE8)](http://bit.ly/kubernetes-client-capabilities-badge)
[![Client Support Level](https://img.shields.io/badge/kubernetes%20client-beta-green.svg?style=flat&colorA=306CE8)](http://bit.ly/kubernetes-client-support-badge)

Expand Down Expand Up @@ -103,6 +103,33 @@ const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

There are several more examples in the [examples](https://github.com/kubernetes-client/javascript/tree/master/examples) directory.

# Compatibility

Prior to the `0.13.0` release, release versions did not track Kubernetes versions. Starting with the `0.13.0`
release, we will increment the minor version whenever we update the minor Kubernetes API version
(e.g. `1.19.x`) that this library is generated from.

Generally speaking newer clients will work with older Kubernetes, but compatability isn't 100% guaranteed.

| client version | older versions | 1.18 | 1.19 |
|----------------|----------------|------|------|
| 0.12.3 | - | ✓ | x |
| 0.13.0 | - | + | ✓ |

Key:

* `✓` Exactly the same features / API objects in both javascript-client and the Kubernetes
version.
* `+` javascript-client has features or api objects that may not be present in the
Kubernetes cluster, but everything they have in common will work.
* `-` The Kubernetes cluster has features the javascript-client library can't use
(additional API objects, etc).
* `x` The Kubernetes cluster has no guarantees to support the API client of
this version, as it only promises _n_-2 version support. It is not tested,
and operations using API versions that have been deprecated and removed in
later server versions won't function correctly.


# Development

All dependencies of this project are expressed in its
Expand Down
2 changes: 1 addition & 1 deletion examples/cache-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const path = '/api/v1/namespaces/default/pods';
const path = '/api/v1/pods';
const watch = new k8s.Watch(kc);

const listFn = () => k8sApi.listPodForAllNamespaces()
Expand Down
27 changes: 27 additions & 0 deletions examples/ingress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const k8s = require('@kubernetes/client-node')
const kc = new k8s.KubeConfig()
kc.loadFromDefault()

const k8sApi = kc.makeApiClient(k8s.NetworkingV1beta1Api) // before 1.14 use extensions/v1beta1
const clientIdentifier = 'my-subdomain'

k8sApi.createNamespacedIngress('default', {
apiVersions: 'networking.k8s.io/v1beta1',
kind: 'Ingress',
metadata: { name: `production-custom-${clientIdentifier}` },
spec: {
rules: [{
host: `${clientIdentifier}.example.com`,
http: {
paths: [{
backend: {
serviceName: 'production-auto-deploy',
servicePort: 5000
},
path: '/'
}]
}
}],
tls: [{ hosts: [`${clientIdentifier}.example.com`] }]
}
}).catch(e => console.log(e))
23 changes: 23 additions & 0 deletions examples/patch-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

k8sApi.listNamespacedPod('default')
.then((res) => {
const patch = [
{
"op": "replace",
"path":"/metadata/labels",
"value": {
"foo": "bar"
}
}
];
const options = { "headers": { "Content-type": k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH}};
k8sApi.patchNamespacedPod(res.body.items[0].metadata.name, 'default', patch, undefined, undefined, undefined, undefined, options)
.then(() => { console.log("Patched.")})
.catch((err) => { console.log("Error: "); console.log(err)});
});
22 changes: 22 additions & 0 deletions examples/scale-deployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.AppsV1Api);

const targetDeploymentName = 'docker-test-deployment';

async function scale(namespace, name, replicas) {
// find the particular deployment
const res = await k8sApi.readNamespacedDeployment(name, namespace);
let deployment = res.body;

// edit
deployment.spec.replicas = replicas;

// replace
await k8sApi.replaceNamespacedDeployment(name, namespace, deployment);
}

scale('default', 'docker-test-deployment', 3);
8 changes: 8 additions & 0 deletions examples/top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const k8s = require('../dist/index');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

k8s.topNodes(k8sApi).then((obj) => console.log(obj));
43 changes: 43 additions & 0 deletions examples/typescript/apply/apply-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as k8s from '@kubernetes/client-node';
import * as fs from 'fs';
import * as yaml from 'js-yaml';
import { promisify } from 'util';

/**
* Replicate the functionality of `kubectl apply`. That is, create the resources defined in the `specFile` if they do
* not exist, patch them if they do exist.
*
* @param specPath File system path to a YAML Kubernetes spec.
* @return Array of resources created
*/
export async function apply(specPath: string): Promise<k8s.KubernetesObject[]> {
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const client = k8s.KubernetesObjectApi.makeApiClient(kc);
const fsReadFileP = promisify(fs.readFile);
const specString = await fsReadFileP(specPath, 'utf8');
const specs: k8s.KubernetesObject[] = yaml.safeLoadAll(specString);
const validSpecs = specs.filter((s) => s && s.kind && s.metadata);
const created: k8s.KubernetesObject[] = [];
for (const spec of validSpecs) {
// this is to convince the old version of TypeScript that metadata exists even though we already filtered specs
// without metadata out
spec.metadata = spec.metadata || {};
spec.metadata.annotations = spec.metadata.annotations || {};
delete spec.metadata.annotations['kubectl.kubernetes.io/last-applied-configuration'];
spec.metadata.annotations['kubectl.kubernetes.io/last-applied-configuration'] = JSON.stringify(spec);
try {
// try to get the resource, if it does not exist an error will be thrown and we will end up in the catch
// block.
await client.read(spec);
// we got the resource, so it exists, so patch it
const response = await client.patch(spec);
created.push(response.body);
} catch (e) {
// we did not get the resource, so it does not exist, so create it
const response = await client.create(spec);
created.push(response.body);
}
}
return created;
}
7 changes: 7 additions & 0 deletions examples/typescript/cp/cp-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as k8s from '@kubernetes/client-node';

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const cp = new k8s.Cp(kc);
cp.cpFromPod('default', 'nginx-4217019353-9gl4s', 'nginx', './test.txt', '/tmp');
Empty file added examples/typescript/cp/test.txt
Empty file.
9 changes: 8 additions & 1 deletion examples/typescript/informer/informer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const listFn = () => k8sApi.listPodForAllNamespaces();
const listFn = () => k8sApi.listNamespacedPod('default');

const informer = k8s.makeInformer(kc, '/api/v1/namespaces/default/pods', listFn);

informer.on('add', (obj: k8s.V1Pod) => { console.log(`Added: ${obj.metadata!.name}`); });
informer.on('update', (obj: k8s.V1Pod) => { console.log(`Updated: ${obj.metadata!.name}`); });
informer.on('delete', (obj: k8s.V1Pod) => { console.log(`Deleted: ${obj.metadata!.name}`); });
informer.on('error', (err: k8s.V1Pod) => {
console.error(err);
// Restart informer after 5sec
setTimeout(() => {
informer.start();
}, 5000);
});

informer.start();
22 changes: 14 additions & 8 deletions examples/typescript/watch/watch-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const watch = new k8s.Watch(kc);
const req = watch.watch('/api/v1/namespaces',
watch.watch('/api/v1/namespaces',
// optional query parameters can go here.
{},
{
allowWatchBookmarks: true,
},
// callback is called for each received object.
(type, obj) => {
(type, apiObj, watchObj) => {
if (type === 'ADDED') {
// tslint:disable-next-line:no-console
console.log('new object:');
Expand All @@ -18,18 +20,22 @@ const req = watch.watch('/api/v1/namespaces',
} else if (type === 'DELETED') {
// tslint:disable-next-line:no-console
console.log('deleted object:');
} else if (type === 'BOOKMARK') {
// tslint:disable-next-line:no-console
console.log(`bookmark: ${watchObj.metadata.resourceVersion}`);
} else {
// tslint:disable-next-line:no-console
console.log('unknown type: ' + type);
}
// tslint:disable-next-line:no-console
console.log(obj);
console.log(apiObj);
},
// done callback is called if the watch terminates normally
(err) => {
// tslint:disable-next-line:no-console
console.log(err);
});

// watch returns a request object which you can use to abort the watch.
setTimeout(() => { req.abort(); }, 10 * 1000);
})
.then((req) => {
// watch returns a request object which you can use to abort the watch.
setTimeout(() => { req.abort(); }, 10 * 1000);
});
1 change: 0 additions & 1 deletion examples/yaml-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const k8s = require('@kubernetes/client-node');
const fs = require('fs');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();
Expand Down
Loading