fix(kube): patching stateful service [EE-6523] (#10948)

pull/10956/head
Prabhat Khera 2024-01-15 13:30:45 +13:00 committed by GitHub
parent 6d71a28584
commit b3b7cfa77f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 10 deletions

View File

@ -121,7 +121,14 @@ export function RollbackApplicationButton({
try {
const patch = getRollbackPatchPayload(app, appRevisionList);
patchAppMutation.mutateAsync(
{ appKind: app.kind, patch },
{
appKind: app.kind,
patch,
contentType:
app.kind === 'Deployment'
? 'application/json-patch+json'
: 'application/strategic-merge-patch+json',
},
{
onSuccess: () => {
notifySuccess('Success', 'Application successfully rolled back');

View File

@ -309,8 +309,23 @@ export function usePatchApplicationMutation(
name: string
) {
return useMutation(
({ appKind, patch }: { appKind: AppKind; patch: ApplicationPatch }) =>
patchApplication(environmentId, namespace, appKind, name, patch),
({
appKind,
patch,
contentType = 'application/json-patch+json',
}: {
appKind: AppKind;
patch: ApplicationPatch;
contentType?: string;
}) =>
patchApplication(
environmentId,
namespace,
appKind,
name,
patch,
contentType
),
{
onSuccess: () => {
queryClient.invalidateQueries(

View File

@ -142,7 +142,8 @@ export async function patchApplication(
namespace: string,
appKind: AppKind,
name: string,
patch: ApplicationPatch
patch: ApplicationPatch,
contentType: string = 'application/json-patch+json'
) {
switch (appKind) {
case 'Deployment':
@ -151,7 +152,8 @@ export async function patchApplication(
namespace,
appKind,
name,
patch
patch,
contentType
);
case 'DaemonSet':
return patchApplicationByKind<DaemonSet>(
@ -160,7 +162,7 @@ export async function patchApplication(
appKind,
name,
patch,
'application/strategic-merge-patch+json'
contentType
);
case 'StatefulSet':
return patchApplicationByKind<StatefulSet>(
@ -169,7 +171,7 @@ export async function patchApplication(
appKind,
name,
patch,
'application/strategic-merge-patch+json'
contentType
);
case 'Pod':
return patchPod(environmentId, namespace, name, patch);

View File

@ -216,6 +216,7 @@ export function getRollbackPatchPayload(
if (!previousRevision.data) {
throw new Error('No data found in the previous revision.');
}
// payload matches the strategic merge patch format for a StatefulSet and DaemonSet
return previousRevision.data;
}
case 'ReplicaSetList': {
@ -277,7 +278,7 @@ export function getRollbackPatchPayload(
value: patchAnnotations,
},
].filter((p) => !!p.value); // remove any patch that has no value
// payload matches the json patch format for a Deployment
return deploymentRollbackPatch;
}
default:

View File

@ -10,8 +10,8 @@ export function parseCpu(cpu: string) {
return res;
}
export function prepareAnnotations(annotations: Annotation[]) {
const result = annotations.reduce(
export function prepareAnnotations(annotations?: Annotation[]) {
const result = annotations?.reduce(
(acc, a) => {
acc[a.Key] = a.Value;
return acc;