Skip to content

Commit

Permalink
fix(import): avoid stopping if cdq deletion fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rottencandy committed Dec 7, 2023
1 parent 2900fc0 commit 412de8c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
13 changes: 9 additions & 4 deletions src/components/ImportForm/utils/cdq-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,15 @@ export const detectComponents = async (
throw new Error(completeCondition.message);
}
} finally {
await k8sDeleteResource({
model: ComponentDetectionQueryModel,
queryOptions: { name: cdq.metadata.name, ns: namespace },
});
try {
await k8sDeleteResource({
model: ComponentDetectionQueryModel,
queryOptions: { name: cdq.metadata.name, ns: namespace },
});
} catch (e) {
// eslint-disable-next-line no-console
console.error(`Unable to delete CDQ ${cdq.metadata.name}: `, e);

Check warning on line 158 in src/components/ImportForm/utils/cdq-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/components/ImportForm/utils/cdq-utils.ts#L158

Added line #L158 was not covered by tests
}
}

return cdq.status.componentDetected;
Expand Down
22 changes: 16 additions & 6 deletions src/components/Overview/IntroBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,31 @@ import {
} from '@patternfly/react-core';
import { FULL_APPLICATION_TITLE } from '../../consts/labels';
import { useSignupStatus } from '../../hooks/useSignupStatus';
import { ApplicationGroupVersionKind, ApplicationModel, ComponentModel } from '../../models';
import {
ApplicationGroupVersionKind,
ApplicationModel,
ComponentDetectionQueryModel,
ComponentModel,
} from '../../models';
import ExternalLink from '../../shared/components/links/ExternalLink';
import { ApplicationKind } from '../../types';
import { useAccessReviewForModel } from '../../utils/rbac';
import { AccessReviewResources, ApplicationKind } from '../../types';
import { useAccessReviewForModels } from '../../utils/rbac';
import { SignupStatus } from '../../utils/signup-utils';
import { useWorkspaceInfo } from '../../utils/workspace-context-utils';
import { ButtonWithAccessTooltip } from '../ButtonWithAccessTooltip';
import SignupButton from './SignupButton';

import './IntroBanner.scss';

const accessReviewResources: AccessReviewResources = [
{ model: ApplicationModel, verb: 'create' },
{ model: ComponentModel, verb: 'create' },
{ model: ComponentDetectionQueryModel, verb: 'create' },
];

const IntroBanner: React.FC<React.PropsWithChildren<unknown>> = () => {
const { namespace, workspace } = useWorkspaceInfo();
const [canCreateApplication] = useAccessReviewForModel(ApplicationModel, 'create');
const [canCreateComponent] = useAccessReviewForModel(ComponentModel, 'create');
const [canCreate] = useAccessReviewForModels(accessReviewResources);

const signupStatus = useSignupStatus();

Expand Down Expand Up @@ -69,7 +79,7 @@ const IntroBanner: React.FC<React.PropsWithChildren<unknown>> = () => {
)}
variant="primary"
data-test="create-application"
isDisabled={!(canCreateApplication && canCreateComponent)}
isDisabled={!canCreate}
tooltip="You don't have access to create an application"
size="lg"
analytics={{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Overview/__tests__/IntroBanner.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jest.mock('react-router-dom', () => {
});

jest.mock('../../../utils/rbac', () => ({
useAccessReviewForModel: jest.fn(() => [true, true]),
useAccessReviewForModels: jest.fn(() => [true, true]),
}));

const useK8sWatchResourceMock = useK8sWatchResource as jest.Mock;
Expand Down
8 changes: 6 additions & 2 deletions src/pages/ImportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ImportForm from '../components/ImportForm/ImportForm';
import NamespacedPage from '../components/NamespacedPage/NamespacedPage';
import PageAccessCheck from '../components/PageAccess/PageAccessCheck';
import { useQuickstartCloseOnUnmount } from '../hooks/useQuickstartCloseOnUnmount';
import { ApplicationModel, ComponentModel } from '../models';
import { ApplicationModel, ComponentDetectionQueryModel, ComponentModel } from '../models';
import { getQueryArgument } from '../shared/utils';
import { AccessReviewResources } from '../types';

Expand All @@ -13,10 +13,14 @@ const ImportPage: React.FunctionComponent<React.PropsWithChildren<unknown>> = ()
const applicationName = getQueryArgument('application');

const accessReviewResources: AccessReviewResources = applicationName
? [{ model: ComponentModel, verb: 'create' }]
? [
{ model: ComponentModel, verb: 'create' },
{ model: ComponentDetectionQueryModel, verb: 'create' },
]
: [
{ model: ApplicationModel, verb: 'create' },
{ model: ComponentModel, verb: 'create' },
{ model: ComponentDetectionQueryModel, verb: 'create' },
];

return (
Expand Down

0 comments on commit 412de8c

Please sign in to comment.