From 925abcc9e2125cd721ae44cedf866f22def30f7d Mon Sep 17 00:00:00 2001 From: Robb Hamilton Date: Tue, 3 Oct 2023 17:15:03 -0400 Subject: [PATCH] OCPBUGS-10562: fix operator uninstall test --- .../tests/operator-uninstall.cy.ts | 2 +- .../modals/uninstall-operator-modal.tsx | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/packages/operator-lifecycle-manager/integration-tests-cypress/tests/operator-uninstall.cy.ts b/frontend/packages/operator-lifecycle-manager/integration-tests-cypress/tests/operator-uninstall.cy.ts index 5c66d6817162..78bb918caf28 100644 --- a/frontend/packages/operator-lifecycle-manager/integration-tests-cypress/tests/operator-uninstall.cy.ts +++ b/frontend/packages/operator-lifecycle-manager/integration-tests-cypress/tests/operator-uninstall.cy.ts @@ -88,7 +88,7 @@ describe(`Testing uninstall of ${testOperator.name} Operator`, () => { modal.shouldBeClosed(); }); - xit(`attempts to uninstall the Operator, shows 'Error uninstalling Operator' alert`, () => { + it(`attempts to uninstall the Operator, shows 'Error uninstalling Operator' alert`, () => { // invalidate the request so operator doesn't get uninstalled cy.intercept( 'DELETE', diff --git a/frontend/packages/operator-lifecycle-manager/src/components/modals/uninstall-operator-modal.tsx b/frontend/packages/operator-lifecycle-manager/src/components/modals/uninstall-operator-modal.tsx index 73221d8f3fbe..10382d31e2f5 100644 --- a/frontend/packages/operator-lifecycle-manager/src/components/modals/uninstall-operator-modal.tsx +++ b/frontend/packages/operator-lifecycle-manager/src/components/modals/uninstall-operator-modal.tsx @@ -76,6 +76,7 @@ export const UninstallOperatorModal: React.FC = ({ const [operandDeletionVerificationError, setOperandDeletionVerificationError] = React.useState( false, ); + const [subscriptionExistsError, setSubscriptionExistsError] = React.useState(''); const [clusterServiceVersionExistsError, setClusterServiceVersionExistsError] = React.useState( '', ); @@ -135,6 +136,21 @@ export const UninstallOperatorModal: React.FC = ({ ? getPatchForRemovingPlugins(consoleOperatorConfig, enabledPlugins) : null; + const subscriptionExists = async () => { + try { + await k8sGetResource({ + model: SubscriptionModel, + name: subscription?.metadata?.name, + }); + return true; + } catch (err) { + if (err.response.status !== 404) { + setSubscriptionExistsError(err.message); + } + return false; + } + }; + const clusterServiceVersionExists = async () => { try { await k8sGetResource({ @@ -144,7 +160,7 @@ export const UninstallOperatorModal: React.FC = ({ }); return true; } catch (err) { - if (err.json.code !== 404) { + if (err.response.status !== 404) { setClusterServiceVersionExistsError(err.message); } return false; @@ -152,7 +168,9 @@ export const UninstallOperatorModal: React.FC = ({ }; const operatorUninstallPromises = [ - k8sKill(SubscriptionModel, subscription, {}, deleteOptions), + ...((await subscriptionExists()) + ? [k8sKill(SubscriptionModel, subscription, {}, deleteOptions)] + : []), ...(subscription?.status?.installedCSV && (await clusterServiceVersionExists()) ? [ k8sKill( @@ -363,6 +381,7 @@ export const UninstallOperatorModal: React.FC = ({ <>