Skip to content

call time middleware support #2275

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

Merged
merged 10 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 2 additions & 26 deletions examples/patch-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as k8s from '@kubernetes/client-node';
import { PromiseMiddlewareWrapper } from '@kubernetes/client-node/dist/gen/middleware.js';

const kc = new k8s.KubeConfig();
kc.loadFromDefault();
Expand All @@ -18,35 +17,12 @@ try {
},
},
];
const headerPatchMiddleware = new PromiseMiddlewareWrapper({
pre: async (requestContext) => {
requestContext.setHeaderParam('Content-type', 'application/json-patch+json');
return requestContext;
},
post: async (responseContext) => responseContext,
});
let currentCluster = kc.getCurrentCluster();
if (currentCluster === null) {
throw new Error('Cluster is undefined');
}
let server = currentCluster.server;
if (server === undefined) {
throw new Error('Server is undefined');
}

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

await k8sApi.patchNamespacedPod(
{ name: res?.items?.[0]?.metadata?.name ?? '', namespace, body: patch },
configuration,
k8s.setHeaderOptions('Content-Type', k8s.JsonPatch),
);

console.log('Patched.');
} catch (err) {
console.error('Error: ');
Expand Down
36 changes: 2 additions & 34 deletions examples/typescript/patch/patch-example.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
CoreV1Api,
RequestContext,
ResponseContext,
KubeConfig,
createConfiguration,
type Configuration,
ServerConfiguration,
} from '@kubernetes/client-node';
import { PromiseMiddlewareWrapper } from '@kubernetes/client-node/dist/gen/middleware.js';
import { CoreV1Api, KubeConfig, setHeaderOptions, JsonPatch } from '@kubernetes/client-node';

const kc = new KubeConfig();
kc.loadFromDefault();
Expand All @@ -25,30 +16,7 @@ try {
},
},
];
const headerPatchMiddleware = new PromiseMiddlewareWrapper({
pre: async (requestContext: RequestContext) => {
requestContext.setHeaderParam('Content-type', 'application/json-patch+json');
return requestContext;
},
post: async (responseContext: ResponseContext) => responseContext,
});
const currentCluster = kc.getCurrentCluster();
if (currentCluster === null) {
throw new Error('Cluster is undefined');
}
const 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,
},
});
const podName = res.items[0]?.metadata?.name;
if (podName === undefined) {
throw new Error('Pod name is undefined');
Expand All @@ -60,7 +28,7 @@ try {
namespace: 'default',
body: patch,
},
configuration,
setHeaderOptions('Content-Type', JsonPatch),
);

console.log('Patched.');
Expand Down
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=06f0b68eeecf61f0a78e1a1db6f7db67c2872e4b
export OPENAPI_GENERATOR_COMMIT=fc00a663e1688c99d6e8917b6fb222cf83141d4c
4 changes: 2 additions & 2 deletions src/gen/.openapi-generator/COMMIT

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/gen/.openapi-generator/VERSION

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/gen/apis/AdmissionregistrationApi.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 32 additions & 32 deletions src/gen/apis/AdmissionregistrationV1Api.ts

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions src/gen/apis/AdmissionregistrationV1alpha1Api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading