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 { try {
const patch = getRollbackPatchPayload(app, appRevisionList); const patch = getRollbackPatchPayload(app, appRevisionList);
patchAppMutation.mutateAsync( patchAppMutation.mutateAsync(
{ appKind: app.kind, patch }, {
appKind: app.kind,
patch,
contentType:
app.kind === 'Deployment'
? 'application/json-patch+json'
: 'application/strategic-merge-patch+json',
},
{ {
onSuccess: () => { onSuccess: () => {
notifySuccess('Success', 'Application successfully rolled back'); notifySuccess('Success', 'Application successfully rolled back');

View File

@ -309,8 +309,23 @@ export function usePatchApplicationMutation(
name: string name: string
) { ) {
return useMutation( 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: () => { onSuccess: () => {
queryClient.invalidateQueries( queryClient.invalidateQueries(

View File

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

View File

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

View File

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