From b3b7cfa77f5f57567684bff21396e0f8992a362b Mon Sep 17 00:00:00 2001 From: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com> Date: Mon, 15 Jan 2024 13:30:45 +1300 Subject: [PATCH] fix(kube): patching stateful service [EE-6523] (#10948) --- .../RollbackApplicationButton.tsx | 9 ++++++++- .../applications/application.queries.ts | 19 +++++++++++++++++-- .../applications/application.service.ts | 10 ++++++---- app/react/kubernetes/applications/utils.ts | 3 ++- app/react/kubernetes/utils.ts | 4 ++-- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/RollbackApplicationButton.tsx b/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/RollbackApplicationButton.tsx index 4e362ee22..2b11799ff 100644 --- a/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/RollbackApplicationButton.tsx +++ b/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/RollbackApplicationButton.tsx @@ -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'); diff --git a/app/react/kubernetes/applications/application.queries.ts b/app/react/kubernetes/applications/application.queries.ts index f64354acd..118bc02af 100644 --- a/app/react/kubernetes/applications/application.queries.ts +++ b/app/react/kubernetes/applications/application.queries.ts @@ -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( diff --git a/app/react/kubernetes/applications/application.service.ts b/app/react/kubernetes/applications/application.service.ts index 2cc6c934f..ba643a230 100644 --- a/app/react/kubernetes/applications/application.service.ts +++ b/app/react/kubernetes/applications/application.service.ts @@ -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( @@ -160,7 +162,7 @@ export async function patchApplication( appKind, name, patch, - 'application/strategic-merge-patch+json' + contentType ); case 'StatefulSet': return patchApplicationByKind( @@ -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); diff --git a/app/react/kubernetes/applications/utils.ts b/app/react/kubernetes/applications/utils.ts index b5f62e0c0..29b6e0e1f 100644 --- a/app/react/kubernetes/applications/utils.ts +++ b/app/react/kubernetes/applications/utils.ts @@ -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: diff --git a/app/react/kubernetes/utils.ts b/app/react/kubernetes/utils.ts index 009e8b3a2..97805cf79 100644 --- a/app/react/kubernetes/utils.ts +++ b/app/react/kubernetes/utils.ts @@ -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;