Skip to content

Commit 3987e4a

Browse files
authored
Merge pull request #1341 from davidgamero/davidgamero/bump-openapi-for-media-types
bump openapi version to support for k8s media types
2 parents 0d147f3 + 62e5ab1 commit 3987e4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+33498
-7065
lines changed

examples/patch-example.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// in a real program use require('@kubernetes/client-node')
22
const k8s = require('../dist/index');
3+
const { createConfiguration, ServerConfiguration } = require('../dist');
4+
const { PromiseMiddlewareWrapper } = require('../dist/gen/middleware');
35

46
const kc = new k8s.KubeConfig();
57
kc.loadFromDefault();
@@ -18,10 +20,36 @@ k8sApi.listNamespacedPod({ namespace }).then((res) => {
1820
},
1921
},
2022
];
21-
// TODO this method of passing the content type will change when we figure out a way to properly do this
22-
const options = { headers: { 'Content-type': k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH } };
23+
const headerPatchMiddleware = new PromiseMiddlewareWrapper({
24+
pre: async (requestContext) => {
25+
requestContext.setHeaderParam('Content-type', 'application/json-patch+json');
26+
return requestContext;
27+
},
28+
post: async (responseContext) => responseContext,
29+
});
30+
let currentContext = kc.getCurrentContext();
31+
let currentCluster = kc.getCluster(currentContext);
32+
if (currentCluster === undefined || currentCluster === null) {
33+
throw new Error('Cluster is undefined');
34+
}
35+
let server = currentCluster.server;
36+
if (server === undefined) {
37+
throw new Error('Server is undefined');
38+
}
39+
40+
const baseServerConfig = new ServerConfiguration(server, {});
41+
const configuration = createConfiguration({
42+
middleware: [headerPatchMiddleware],
43+
baseServer: baseServerConfig,
44+
authMethods: {
45+
default: kc,
46+
},
47+
});
2348
k8sApi
24-
.patchNamespacedPod({ name: res?.items?.[0].metadata?.name ?? '', namespace, body: patch }, options)
49+
.patchNamespacedPod(
50+
{ name: res?.items?.[0].metadata?.name ?? '', namespace, body: patch },
51+
configuration,
52+
)
2553
.then(() => {
2654
console.log('Patched.');
2755
})
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// in a real program use require('@kubernetes/client-node')
2+
import {
3+
CoreV1Api,
4+
RequestContext,
5+
ResponseContext,
6+
KubeConfig,
7+
createConfiguration,
8+
Configuration,
9+
ServerConfiguration,
10+
} from '../../../dist';
11+
import { PromiseMiddlewareWrapper } from '../../../dist/gen/middleware';
12+
13+
const kc = new KubeConfig();
14+
kc.loadFromDefault();
15+
16+
const k8sApi = kc.makeApiClient(CoreV1Api);
17+
18+
k8sApi
19+
.listNamespacedPod({
20+
namespace: 'default',
21+
})
22+
.then((res) => {
23+
const patch = [
24+
{
25+
op: 'replace',
26+
path: '/metadata/labels',
27+
value: {
28+
foo: 'bar',
29+
},
30+
},
31+
];
32+
const options = { headers: { 'Content-type': 'application/json-patch+json' } };
33+
const headerPatchMiddleware = new PromiseMiddlewareWrapper({
34+
pre: async (requestContext: RequestContext) => {
35+
requestContext.setHeaderParam('Content-type', 'application/json-patch+json');
36+
return requestContext;
37+
},
38+
post: async (responseContext: ResponseContext) => responseContext,
39+
});
40+
const currentContext = kc.getCurrentContext();
41+
const currentCluster = kc.getCluster(currentContext);
42+
if (currentCluster === undefined || currentCluster === null) {
43+
throw new Error('Cluster is undefined');
44+
}
45+
const server = currentCluster.server;
46+
if (server === undefined) {
47+
throw new Error('Server is undefined');
48+
}
49+
50+
const baseServerConfig: ServerConfiguration<{}> = new ServerConfiguration<{}>(server, {});
51+
const configuration: Configuration = createConfiguration({
52+
middleware: [headerPatchMiddleware],
53+
baseServer: baseServerConfig,
54+
authMethods: {
55+
default: kc,
56+
},
57+
});
58+
59+
const podName = res.items[0].metadata?.name;
60+
if (podName === undefined) {
61+
throw new Error('Pod name is undefined');
62+
}
63+
k8sApi
64+
.patchNamespacedPod(
65+
{
66+
name: podName,
67+
namespace: 'default',
68+
body: patch,
69+
},
70+
configuration,
71+
)
72+
.then(() => {
73+
// tslint:disable-next-line:no-console
74+
console.log('Patched.');
75+
})
76+
.catch((err) => {
77+
// tslint:disable-next-line:no-console
78+
console.log('Error: ', err);
79+
});
80+
});

package-lock.json

+23-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"prettier": "^3.0.0",
9595
"source-map-support": "^0.5.9",
9696
"ts-mockito": "^2.3.1",
97-
"ts-node": "^8.2.0",
97+
"ts-node": "^8.10.2",
9898
"tslint": "^6.1.3",
9999
"typedoc": "^0.25.0",
100100
"typescript": "~5.2.2"

settings

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ export CLIENT_VERSION="0.8-SNAPSHOT"
3030
# Name of the release package
3131
export PACKAGE_NAME="@kubernetes/node-client"
3232

33-
export OPENAPI_GENERATOR_COMMIT=5555137b7926de2f501e091718ff72429b808220
33+
export OPENAPI_GENERATOR_COMMIT=53289263d921e627cb05894c8477238dff48d62f

src/gen/.openapi-generator/COMMIT

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Requested Commit: 5555137b7926de2f501e091718ff72429b808220
2-
Actual Commit: 5555137b7926de2f501e091718ff72429b808220
1+
Requested Commit: 53289263d921e627cb05894c8477238dff48d62f
2+
Actual Commit: 53289263d921e627cb05894c8477238dff48d62f

src/gen/.openapi-generator/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.0.0-SNAPSHOT
1+
7.2.0-SNAPSHOT

src/gen/apis/AdmissionregistrationApi.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO: better import syntax?
22
import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi';
33
import {Configuration} from '../configuration';
4-
import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http';
4+
import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http';
55
import FormData from "form-data";
66
import { URLSearchParams } from 'url';
77
import {ObjectSerializer} from '../models/ObjectSerializer';
@@ -57,14 +57,14 @@ export class AdmissionregistrationApiResponseProcessor {
5757
* @params response Response returned by the server for a request to getAPIGroup
5858
* @throws ApiException if the response code was not in [200, 299]
5959
*/
60-
public async getAPIGroup(response: ResponseContext): Promise<V1APIGroup > {
60+
public async getAPIGroupWithHttpInfo(response: ResponseContext): Promise<HttpInfo<V1APIGroup >> {
6161
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
6262
if (isCodeInRange("200", response.httpStatusCode)) {
6363
const body: V1APIGroup = ObjectSerializer.deserialize(
6464
ObjectSerializer.parse(await response.body.text(), contentType),
6565
"V1APIGroup", ""
6666
) as V1APIGroup;
67-
return body;
67+
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
6868
}
6969
if (isCodeInRange("401", response.httpStatusCode)) {
7070
throw new ApiException<undefined>(response.httpStatusCode, "Unauthorized", undefined, response.headers);
@@ -76,7 +76,7 @@ export class AdmissionregistrationApiResponseProcessor {
7676
ObjectSerializer.parse(await response.body.text(), contentType),
7777
"V1APIGroup", ""
7878
) as V1APIGroup;
79-
return body;
79+
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
8080
}
8181

8282
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);

0 commit comments

Comments
 (0)