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

bump openapi version to support for k8s media types #1341

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions examples/patch-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import cluster from "cluster";
import { CoreV1Api, Middleware, RequestContext, ResponseContext,KubeConfig, PatchUtils, createConfiguration, AuthMethodsConfiguration, Configuration, ServerConfiguration } from "../dist";
import { PromiseMiddlewareWrapper } from "../dist/gen/middleware";

// const k8s = require('@kubernetes/client-node');

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

const k8sApi = kc.makeApiClient(CoreV1Api);

k8sApi.listNamespacedPod({
namespace: 'default'
})
.then((res) => {
const patch = [
{
"op": "replace",
"path":"/metadata/labels",
"value": {
"foo": "bar"
}
}
];
const options = { "headers": { "Content-type": PatchUtils.PATCH_FORMAT_JSON_PATCH}};
const headerPatchMiddleware = new PromiseMiddlewareWrapper({
pre: async (requestContext: RequestContext) => {
requestContext.setHeaderParam("Content-type", PatchUtils.PATCH_FORMAT_JSON_PATCH);
return requestContext;
},
post: async (responseContext: ResponseContext) => responseContext
})
let currentContext = kc.getCurrentContext();
let currentCluster = kc.getCluster(currentContext);
if (currentCluster === undefined || currentCluster === null) {
throw new Error("Cluster is undefined");
}
let server = currentCluster.server ;
if (server === undefined) {
throw new Error("Server is undefined");
}

const baseServerConfig: ServerConfiguration<{}> = new ServerConfiguration<{}>(server, {});
const configuration: Configuration = createConfiguration({
middleware: [headerPatchMiddleware],
baseServer: baseServerConfig,
authMethods: {
default: kc,
},
});

let podName = res.items[0].metadata?.name;
if (podName === undefined) {
throw new Error("Pod name is undefined");
}
k8sApi.patchNamespacedPod({
name: podName,
namespace: 'default',
body: patch,
},
configuration
)
.then(() => { console.log("Patched.")})
.catch((err) => { console.log("Error: "); console.log(err)});
});
2 changes: 1 addition & 1 deletion settings
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export CLIENT_VERSION="0.8-SNAPSHOT"
# Name of the release package
export PACKAGE_NAME="@kubernetes/node-client"

export OPENAPI_GENERATOR_COMMIT=5555137b7926de2f501e091718ff72429b808220
export OPENAPI_GENERATOR_COMMIT=ba367e60e85392a7fd58cdb374c35c3aaaece872
davidgamero marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions src/gen/.openapi-generator/COMMIT
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Requested Commit: 5555137b7926de2f501e091718ff72429b808220
Actual Commit: 5555137b7926de2f501e091718ff72429b808220
Requested Commit: ba367e60e85392a7fd58cdb374c35c3aaaece872
Actual Commit: ba367e60e85392a7fd58cdb374c35c3aaaece872
2 changes: 1 addition & 1 deletion src/gen/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0-SNAPSHOT
7.1.0-SNAPSHOT
8 changes: 4 additions & 4 deletions src/gen/apis/AdmissionregistrationApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: better import syntax?
import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi';
import {Configuration} from '../configuration';
import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http';
import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http';
import FormData from "form-data";
import { URLSearchParams } from 'url';
import {ObjectSerializer} from '../models/ObjectSerializer';
Expand Down Expand Up @@ -57,14 +57,14 @@ export class AdmissionregistrationApiResponseProcessor {
* @params response Response returned by the server for a request to getAPIGroup
* @throws ApiException if the response code was not in [200, 299]
*/
public async getAPIGroup(response: ResponseContext): Promise<V1APIGroup > {
public async getAPIGroupWithHttpInfo(response: ResponseContext): Promise<HttpInfo<V1APIGroup >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: V1APIGroup = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"V1APIGroup", ""
) as V1APIGroup;
return body;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("401", response.httpStatusCode)) {
throw new ApiException<undefined>(response.httpStatusCode, "Unauthorized", undefined, response.headers);
Expand All @@ -76,7 +76,7 @@ export class AdmissionregistrationApiResponseProcessor {
ObjectSerializer.parse(await response.body.text(), contentType),
"V1APIGroup", ""
) as V1APIGroup;
return body;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}

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