-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathpatchOptions.ts
More file actions
51 lines (47 loc) · 1.74 KB
/
patchOptions.ts
File metadata and controls
51 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright (c) 2018-2025 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
import { PatchStrategy } from '@kubernetes/client-node';
import {
ConfigurationOptions,
RequestContext,
ResponseContext,
} from '@kubernetes/client-node/dist/gen';
import { wrapOptions } from '@kubernetes/client-node/dist/gen/configuration';
/**
* Creates a middleware that explicitly sets the Content-Type header for patch requests.
* This ensures consistent behavior regardless of @kubernetes/client-node defaults.
*/
function createPatchMiddleware(contentType: string) {
return {
pre: async (context: RequestContext): Promise<RequestContext> => {
context.setHeaderParam('Content-Type', contentType);
return context;
},
post: async (context: ResponseContext): Promise<ResponseContext> => {
return context;
},
};
}
/**
* Configuration options for patch operations on built-in Kubernetes resources (ConfigMaps, etc.).
* Uses strategic-merge-patch for merge patch format: { data: { key: value } }
*/
export const STRATEGIC_MERGE_PATCH_OPTIONS: ConfigurationOptions = wrapOptions({
middleware: [createPatchMiddleware(PatchStrategy.StrategicMergePatch)],
})!;
/**
* Configuration options for patch operations on Custom Resources (DevWorkspaces, etc.).
* Uses json-patch for JSON Patch array format: [{ op: 'replace', path: '...', value: '...' }]
*/
export const JSON_PATCH_OPTIONS: ConfigurationOptions = wrapOptions({
middleware: [createPatchMiddleware(PatchStrategy.JsonPatch)],
})!;