@depup/kubernetes-client 9.0.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/backends/kubernetes-client-node.js +153 -0
- package/backends/request/auth-providers/cmd.js +62 -0
- package/backends/request/auth-providers/openid.js +27 -0
- package/backends/request/client.js +243 -0
- package/backends/request/config.js +344 -0
- package/backends/request/index.js +5 -0
- package/changes.json +42 -0
- package/lib/alias.js +71 -0
- package/lib/config.js +3 -0
- package/lib/index.js +15 -0
- package/lib/specs/swagger-1.10.json.gz +0 -0
- package/lib/specs/swagger-1.11.json.gz +0 -0
- package/lib/specs/swagger-1.12.json.gz +0 -0
- package/lib/specs/swagger-1.13.json.gz +0 -0
- package/lib/swagger-client.js +233 -0
- package/package.json +119 -0
- package/typings/index.d.ts +7022 -0
- package/typings/tsconfig.json +11 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
/* eslint-disable no-sync */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file Convert a Swagger specification into a kubernetes-client API client.
|
|
6
|
+
*
|
|
7
|
+
* Represent Swagger a Path Item Object [1] with chains of objects:
|
|
8
|
+
*
|
|
9
|
+
* /api/v1/namespaces -> api.v1.namespaces
|
|
10
|
+
*
|
|
11
|
+
* Associate operations on a Path Item Object with functions:
|
|
12
|
+
*
|
|
13
|
+
* GET /api/v1/namespaces -> api.v1.namespaces.get()
|
|
14
|
+
*
|
|
15
|
+
* Represent Path Templating [2] with function calls:
|
|
16
|
+
*
|
|
17
|
+
* /api/v1/namespaces/{namespace}/pods -> api.v1.namespaces(namespace).pods
|
|
18
|
+
*
|
|
19
|
+
* Iterate over a Paths Object [3] to generate whole API client.
|
|
20
|
+
*
|
|
21
|
+
* [1]: https://swagger.io/specification/#pathItemObject
|
|
22
|
+
* [2]: https://swagger.io/specification/#pathTemplating
|
|
23
|
+
* [3]: https://swagger.io/specification/#pathsObject
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const Component = require('swagger-fluent').Component
|
|
27
|
+
const deprecate = require('depd')('kubernetes-client')
|
|
28
|
+
const fs = require('fs')
|
|
29
|
+
const KubeConfig = require('./config')
|
|
30
|
+
const path = require('path')
|
|
31
|
+
const zlib = require('zlib')
|
|
32
|
+
|
|
33
|
+
const getAliases = require('./alias')
|
|
34
|
+
const Request = require('../backends/request')
|
|
35
|
+
|
|
36
|
+
class Root extends Component {
|
|
37
|
+
_getSpec (pathname) {
|
|
38
|
+
return this.backend.http({ method: 'GET', pathname })
|
|
39
|
+
.then(res => {
|
|
40
|
+
return res.body
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Load swagger.json from kube-apiserver.
|
|
46
|
+
* @returns {Promise} Promise
|
|
47
|
+
*/
|
|
48
|
+
loadSpec () {
|
|
49
|
+
return this._getSpec('/openapi/v2')
|
|
50
|
+
.catch(() => {
|
|
51
|
+
return this._getSpec('/swagger.json')
|
|
52
|
+
})
|
|
53
|
+
.then(res => {
|
|
54
|
+
this._addSpec(res)
|
|
55
|
+
return this
|
|
56
|
+
})
|
|
57
|
+
.catch(err => {
|
|
58
|
+
throw new Error(`Failed to get /openapi/v2 and /swagger.json: ${err.message}`)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_getLogByteStream (options) {
|
|
63
|
+
return this.backend.getLogByteStream(Object.assign({
|
|
64
|
+
method: 'GET',
|
|
65
|
+
pathItemObject: this.pathItemObject,
|
|
66
|
+
pathname: this.getPath(),
|
|
67
|
+
pathnameParameters: this.getPathnameParameters()
|
|
68
|
+
}, options))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async _getWatchObjectStream (options) {
|
|
72
|
+
return this.backend.getWatchObjectStream(Object.assign({
|
|
73
|
+
method: 'GET',
|
|
74
|
+
pathItemObject: this.pathItemObject,
|
|
75
|
+
pathname: this.getPath(),
|
|
76
|
+
pathnameParameters: this.getPathnameParameters()
|
|
77
|
+
}, options))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_addEndpoint (endpoint) {
|
|
81
|
+
const component = super._addEndpoint(endpoint)
|
|
82
|
+
if (!component) return component
|
|
83
|
+
|
|
84
|
+
//
|
|
85
|
+
// Deprecate stream API.
|
|
86
|
+
//
|
|
87
|
+
if (endpoint.pathItem.get) {
|
|
88
|
+
const action = endpoint.pathItem.get['x-kubernetes-action']
|
|
89
|
+
if (action === 'watch' || action === 'watchlist') {
|
|
90
|
+
component.getStream = deprecate.function(
|
|
91
|
+
component.getStream,
|
|
92
|
+
'.getStream use .getObjectStream, see ' +
|
|
93
|
+
'https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md')
|
|
94
|
+
component.getObjectStream = component._getWatchObjectStream
|
|
95
|
+
} else if (endpoint.name === '/api/v1/namespaces/{namespace}/pods/{name}/log') {
|
|
96
|
+
component.getStream = deprecate.function(
|
|
97
|
+
component.getStream,
|
|
98
|
+
'.getStream use .getByteStream, see ' +
|
|
99
|
+
'https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md')
|
|
100
|
+
component.getByteStream = component._getLogByteStream
|
|
101
|
+
} else {
|
|
102
|
+
component.getStream = deprecate.function(
|
|
103
|
+
component.getStream,
|
|
104
|
+
'.getStream see https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md')
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
addCustomResourceDefinition (manifest) {
|
|
110
|
+
const group = manifest.spec.group
|
|
111
|
+
const name = manifest.spec.names.plural
|
|
112
|
+
const namespace = manifest.spec.scope === 'Cluster' ? '' : '/namespaces/{namespace}'
|
|
113
|
+
|
|
114
|
+
const addSpec = (version) => {
|
|
115
|
+
const spec = { paths: {} }
|
|
116
|
+
//
|
|
117
|
+
// Make just enough of Swagger spec to generate some useful endpoints.
|
|
118
|
+
//
|
|
119
|
+
const templatePath = `/apis/${group}/${version}${namespace}/${name}/{name}`
|
|
120
|
+
spec.paths[templatePath] = ['delete', 'get', 'patch', 'put'].reduce((acc, method) => {
|
|
121
|
+
acc[method] = { operationId: `${method}Template${name}` }
|
|
122
|
+
return acc
|
|
123
|
+
}, {})
|
|
124
|
+
|
|
125
|
+
const resourcePath = `/apis/${group}/${version}${namespace}/${name}`
|
|
126
|
+
spec.paths[resourcePath] = ['get', 'post'].reduce((acc, method) => {
|
|
127
|
+
acc[method] = { operationId: `${method}${name}` }
|
|
128
|
+
return acc
|
|
129
|
+
}, {})
|
|
130
|
+
//
|
|
131
|
+
// Namespaced CRDs get a cluster-level GET endpoint.
|
|
132
|
+
// Similar to GET /api/v1/pods.
|
|
133
|
+
//
|
|
134
|
+
if (manifest.spec.scope === 'Namespaced') {
|
|
135
|
+
const clusterPath = `/apis/${group}/${version}/${name}`
|
|
136
|
+
spec.paths[clusterPath] = {
|
|
137
|
+
get: {
|
|
138
|
+
operationId: `getCluster${name}`
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const watchPaths = {
|
|
144
|
+
watchCluster: `/apis/${group}/${version}/watch/${name}`,
|
|
145
|
+
watchNamespace: `/apis/${group}/${version}/watch${namespace}/${name}`,
|
|
146
|
+
watchResource: `/apis/${group}/${version}/watch${namespace}/${name}/{name}`
|
|
147
|
+
}
|
|
148
|
+
Object.keys(watchPaths).forEach(operationId => {
|
|
149
|
+
const watchPath = watchPaths[operationId]
|
|
150
|
+
spec.paths[watchPath] = {
|
|
151
|
+
get: {
|
|
152
|
+
'x-kubernetes-action': 'watch',
|
|
153
|
+
operationId: `operationId${name}`
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
// Add status endpoint - see https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#customresourcesubresourcestatus-v1beta1-apiextensions-k8s-io
|
|
159
|
+
if (manifest.spec.subresources && manifest.spec.subresources.status) {
|
|
160
|
+
const statusPath = `/apis/${group}/${version}${namespace}/${name}/{name}/status`
|
|
161
|
+
spec.paths[statusPath] = ['get', 'put'].reduce((acc, method) => {
|
|
162
|
+
acc[method] = { operationId: `${method}Template${name}` }
|
|
163
|
+
return acc
|
|
164
|
+
}, {})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Add scale endpoints - see https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#customresourcesubresourcescale-v1beta1-apiextensions-k8s-io
|
|
168
|
+
if (manifest.spec.subresources && manifest.spec.subresources.scale) {
|
|
169
|
+
const statusPath = `/apis/${group}/${version}${namespace}/${name}/{name}/scale`
|
|
170
|
+
spec.paths[statusPath] = ['get', 'put'].reduce((acc, method) => {
|
|
171
|
+
acc[method] = { operationId: `${method}Template${name}` }
|
|
172
|
+
return acc
|
|
173
|
+
}, {})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this._addSpec(spec)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (manifest.spec.version) {
|
|
180
|
+
addSpec(manifest.spec.version)
|
|
181
|
+
} else {
|
|
182
|
+
const versions = manifest.spec.versions || []
|
|
183
|
+
versions.forEach(version => addSpec(version.name))
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
class Client {
|
|
189
|
+
constructor (options) {
|
|
190
|
+
options = options || {}
|
|
191
|
+
|
|
192
|
+
if (options.config) {
|
|
193
|
+
deprecate('Client({ config }), see ' +
|
|
194
|
+
'https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md')
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let backend = options.backend
|
|
198
|
+
if (!backend) {
|
|
199
|
+
if (options.config) {
|
|
200
|
+
backend = new Request(options.config)
|
|
201
|
+
} else {
|
|
202
|
+
const kubeconfig = new KubeConfig()
|
|
203
|
+
kubeconfig.loadFromDefault()
|
|
204
|
+
backend = new Request({ kubeconfig })
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let spec = options.spec
|
|
209
|
+
if (!spec && options.version) {
|
|
210
|
+
const swaggerPath = path.join(
|
|
211
|
+
__dirname,
|
|
212
|
+
'specs',
|
|
213
|
+
`swagger-${options.version}.json.gz`)
|
|
214
|
+
spec = JSON.parse(zlib.gunzipSync(fs.readFileSync(swaggerPath)))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const root = new Root({ splits: [], backend, getNames: options.getNames || getAliases })
|
|
218
|
+
if (spec) root._addSpec(spec)
|
|
219
|
+
return root
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// eslint-disable-next-line camelcase
|
|
224
|
+
class Client1_13 extends Client {
|
|
225
|
+
constructor (options) {
|
|
226
|
+
super(Object.assign({}, options, { version: '1.13' }))
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = {
|
|
231
|
+
Client,
|
|
232
|
+
Client1_13
|
|
233
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/kubernetes-client",
|
|
3
|
+
"version": "9.0.0-depup.0",
|
|
4
|
+
"description": "[DepUp] Simplified Kubernetes API client.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "./typings/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"coverage": "nyc mocha 'lib/**/*.test.js'",
|
|
9
|
+
"docs": "node scripts/docs.js --builtins",
|
|
10
|
+
"typings": "node scripts/typings.js --spec lib/specs/swagger-1.13.json.gz --output typings/index.d.ts",
|
|
11
|
+
"lint": "standard --fix",
|
|
12
|
+
"release": "standard-version --tag-prefix=''",
|
|
13
|
+
"test": "standard && mocha 'lib/**/*.test.js' 'backends/**/*.test.js' && npm run test-typings && npm run test-generated",
|
|
14
|
+
"test-10": "standard && mocha 'lib/**/*.test.js' 'backends/**/*.test.js' && npm run test-typings",
|
|
15
|
+
"test-generated": "scripts/test-generated.sh",
|
|
16
|
+
"test-integration": "integration/run-mocha.sh integration/test --timeout 30000",
|
|
17
|
+
"test-typings": "tsc --project ./typings"
|
|
18
|
+
},
|
|
19
|
+
"repository": "godaddy/kubernetes-client",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"depup",
|
|
22
|
+
"dependency-bumped",
|
|
23
|
+
"updated-deps",
|
|
24
|
+
"kubernetes-client",
|
|
25
|
+
"kubernetes",
|
|
26
|
+
"kubectl",
|
|
27
|
+
"containers"
|
|
28
|
+
],
|
|
29
|
+
"author": "GoDaddy Operating Company, LLC",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=10.13.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"backends",
|
|
36
|
+
"lib",
|
|
37
|
+
"typings",
|
|
38
|
+
"changes.json",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@kubernetes/client-node": "^1.4.0",
|
|
43
|
+
"camelcase": "^9.0.0",
|
|
44
|
+
"deepmerge": "^4.3.1",
|
|
45
|
+
"depd": "^2.0.0",
|
|
46
|
+
"js-yaml": "^4.1.1",
|
|
47
|
+
"json-stream": "^1.0.0",
|
|
48
|
+
"openid-client": "^6.8.2",
|
|
49
|
+
"pump": "^3.0.4",
|
|
50
|
+
"qs": "^6.15.0",
|
|
51
|
+
"request": "^2.88.2",
|
|
52
|
+
"swagger-fluent": "^5.0.3",
|
|
53
|
+
"url-join": "^5.0.0",
|
|
54
|
+
"ws": "^8.19.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "13.13.4",
|
|
58
|
+
"chai": "4.2.0",
|
|
59
|
+
"mocha": "7.1.2",
|
|
60
|
+
"mustache": "4.0.1",
|
|
61
|
+
"nock": "12.0.3",
|
|
62
|
+
"nyc": "15.0.1",
|
|
63
|
+
"sinon": "9.0.2",
|
|
64
|
+
"standard": "14.3.3",
|
|
65
|
+
"standard-version": "7.1.0",
|
|
66
|
+
"typescript": "3.8.3",
|
|
67
|
+
"yargs": "15.3.1"
|
|
68
|
+
},
|
|
69
|
+
"nyc": {
|
|
70
|
+
"check-coverage": true,
|
|
71
|
+
"lines": 80,
|
|
72
|
+
"functions": 70
|
|
73
|
+
},
|
|
74
|
+
"depup": {
|
|
75
|
+
"changes": {
|
|
76
|
+
"@kubernetes/client-node": {
|
|
77
|
+
"from": "0.10.2",
|
|
78
|
+
"to": "^1.4.0"
|
|
79
|
+
},
|
|
80
|
+
"camelcase": {
|
|
81
|
+
"from": "^6.0.0",
|
|
82
|
+
"to": "^9.0.0"
|
|
83
|
+
},
|
|
84
|
+
"deepmerge": {
|
|
85
|
+
"from": "^4.2.2",
|
|
86
|
+
"to": "^4.3.1"
|
|
87
|
+
},
|
|
88
|
+
"js-yaml": {
|
|
89
|
+
"from": "^3.13.1",
|
|
90
|
+
"to": "^4.1.1"
|
|
91
|
+
},
|
|
92
|
+
"openid-client": {
|
|
93
|
+
"from": "^3.14.0",
|
|
94
|
+
"to": "^6.8.2"
|
|
95
|
+
},
|
|
96
|
+
"pump": {
|
|
97
|
+
"from": "^3.0.0",
|
|
98
|
+
"to": "^3.0.4"
|
|
99
|
+
},
|
|
100
|
+
"qs": {
|
|
101
|
+
"from": "^6.9.0",
|
|
102
|
+
"to": "^6.15.0"
|
|
103
|
+
},
|
|
104
|
+
"url-join": {
|
|
105
|
+
"from": "^4.0.1",
|
|
106
|
+
"to": "^5.0.0"
|
|
107
|
+
},
|
|
108
|
+
"ws": {
|
|
109
|
+
"from": "^7.2.3",
|
|
110
|
+
"to": "^8.19.0"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"depsUpdated": 9,
|
|
114
|
+
"originalPackage": "kubernetes-client",
|
|
115
|
+
"originalVersion": "9.0.0",
|
|
116
|
+
"processedAt": "2026-03-17T22:56:52.656Z",
|
|
117
|
+
"smokeTest": "passed"
|
|
118
|
+
}
|
|
119
|
+
}
|