Skip to content

Commit

Permalink
feat: Make EDP-gitops repository unique per edp tenant (#52)
Browse files Browse the repository at this point in the history
Jira: EPMDEDP-12643
Related: #52
Change-Id: I7db8fe31d7a4eb5e53337692a59c2bb48e25a9bb
  • Loading branch information
callmevladik committed Sep 21, 2023
1 parent d523557 commit e900a47
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 84 deletions.
5 changes: 1 addition & 4 deletions src/hooks/useDetectNamespaces/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useDetectNamespaces = () => {
const history = useHistory();

React.useEffect(() => {
closeSnackbar();
const lsNamespaceObject = JSON.parse(
localStorage.getItem(`cluster_settings.${clusterName}`) || '{}'
);
Expand All @@ -28,7 +29,6 @@ export const useDetectNamespaces = () => {
}

if (!lsNamespaceObject?.defaultNamespace) {
closeSnackbar();
enqueueSnackbar(
<Typography>
<span>Default namespace is unset. Navigate to </span>
Expand All @@ -47,7 +47,6 @@ export const useDetectNamespaces = () => {
</Typography>,
{
autoHideDuration: null,
variant: 'warning',
anchorOrigin: {
vertical: 'bottom',
horizontal: 'left',
Expand All @@ -63,7 +62,6 @@ export const useDetectNamespaces = () => {
!lsNamespaceObject?.allowedNamespaces ||
!lsNamespaceObject?.allowedNamespaces.length
) {
closeSnackbar();
enqueueSnackbar(
<Typography>
<span>Allowed namespaces are unset. Navigate to </span>
Expand All @@ -82,7 +80,6 @@ export const useDetectNamespaces = () => {
</Typography>,
{
autoHideDuration: null,
variant: 'warning',
anchorOrigin: {
vertical: 'bottom',
horizontal: 'left',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ interface CreateCodebaseProps {
codebaseAuthData: CodebaseAuthData | null;
}

export const useCreateCodebase = ({
interface EditCodebaseProps {
codebaseData: EDPCodebaseKubeObjectInterface;
}

export const useCodebaseCRUD = ({
onSuccess,
onError,
}: {
Expand Down Expand Up @@ -88,6 +92,11 @@ export const useCreateCodebase = ({
CRUD_TYPES.CREATE
>('codebaseSecretCreateMutation', K8s.secret.default, CRUD_TYPES.CREATE);

const codebaseEditMutation = useResourceCRUDMutation<
EDPCodebaseKubeObjectInterface,
CRUD_TYPES.EDIT
>('codebaseEditMutation', EDPCodebaseKubeObject, CRUD_TYPES.EDIT);

const createCodebase = React.useCallback(
async ({ codebaseData, codebaseAuthData }: CreateCodebaseProps) => {
if (codebaseAuthData === null) {
Expand Down Expand Up @@ -142,11 +151,26 @@ export const useCreateCodebase = ({
]
);

const editCodebase = React.useCallback(
async ({ codebaseData }: EditCodebaseProps) => {
codebaseEditMutation.mutate(codebaseData, {
onSuccess: () => {
invokeOnSuccessCallback(codebaseData);
},
onError: () => {
invokeOnErrorCallback();
},
});
},
[codebaseEditMutation, invokeOnErrorCallback, invokeOnSuccessCallback]
);

const mutations = {
codebaseCreateMutation,
codebaseSecretCreateMutation,
codebaseSecretDeleteMutation,
codebaseEditMutation,
};

return { createCodebase, mutations };
return { createCodebase, editCodebase, mutations };
};
45 changes: 0 additions & 45 deletions src/k8s/EDPCodebase/hooks/useEditCodebase.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/k8s/EDPCodebase/labels.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE = 'app.edp.epam.com/codebaseType';
export const CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE = 'app.edp.epam.com/systemType';
15 changes: 14 additions & 1 deletion src/override.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@

.MuiChip-label {
line-height: 1;
}
}

nav[aria-label="Navigation Tabs"] li[class*="linkMainSelected"] {
background-color: #2ccfe2 !important;
}

nav[aria-label="Navigation Tabs"] li[class*="linkSelected"] .Mui-selected * {
color: #2ccfe2 !important;
}

div[class*="SnackbarItem-variantWarning"] {
color: #000;
}

33 changes: 18 additions & 15 deletions src/pages/edp-cdpipeline-list/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { CODEBASE_TYPES } from '../../constants/codebaseTypes';
import { EDP_USER_GUIDE } from '../../constants/urls';
import { ICONS } from '../../icons/iconify-icons-mapping';
import { EDPCDPipelineKubeObject } from '../../k8s/EDPCDPipeline';
import { EDPCodebaseKubeObject } from '../../k8s/EDPCodebase';
import { CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE } from '../../k8s/EDPCodebase/labels';
import { useCodebasesByTypeLabelQuery } from '../../k8s/EDPCodebase/hooks/useCodebasesByTypeLabelQuery';
import { CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE } from '../../k8s/EDPCodebase/labels';
import { useDialogContext } from '../../providers/Dialog/hooks';
import { ResourceActionListContextProvider } from '../../providers/ResourceActionList';
import { FORM_MODES } from '../../types/forms';
Expand All @@ -25,19 +25,22 @@ import { routeEDPGitOpsConfiguration } from '../edp-configuration/pages/edp-gito
import { CDPipelineList } from './components/CDPipelineList';

export const PageView = () => {
const [codebases] = EDPCodebaseKubeObject.useList({
namespace: getDefaultNamespace(),
labelSelector: `${CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE}=${CODEBASE_TYPES.SYSTEM}`,
const { data: gitOpsCodebase, isLoading } = useCodebasesByTypeLabelQuery({
props: {
namespace: getDefaultNamespace(),
codebaseType: CODEBASE_TYPES.SYSTEM,
},
options: {
select: data => {
return data?.items.find(
el =>
el.metadata.labels[CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE] ===
'gitops'
);
},
},
});

const codebasesArray = React.useMemo(
() => (codebases ? codebases.filter(Boolean) : []),
[codebases]
);

const codebasesIsLoading = codebases === null;

const gitOpsCodebase = codebasesArray.find(el => el.metadata.name === 'edp-gitops') ?? null;
const [items, error] = EDPCDPipelineKubeObject.useList();

const { setDialog } = useDialogContext();
Expand Down Expand Up @@ -87,10 +90,10 @@ export const PageView = () => {
headerStyle="label"
/>
<ResourceActionListContextProvider>
<Render condition={codebasesIsLoading || !!gitOpsCodebase}>
<Render condition={isLoading || !!gitOpsCodebase}>
<CDPipelineList CDPipelines={items} error={error} />
</Render>
<Render condition={!codebasesIsLoading && !gitOpsCodebase}>
<Render condition={!isLoading && !gitOpsCodebase}>
<EmptyList
customText={'No GitOps repository configured.'}
linkText={'Click here to add a repository.'}
Expand Down
10 changes: 8 additions & 2 deletions src/pages/edp-configuration/pages/edp-gitops/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { CODEBASE_TYPES } from '../../../../constants/codebaseTypes';
import { CUSTOM_RESOURCE_STATUSES } from '../../../../constants/statuses';
import { ICONS } from '../../../../icons/iconify-icons-mapping';
import { EDPCodebaseKubeObject } from '../../../../k8s/EDPCodebase';
import { CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE } from '../../../../k8s/EDPCodebase/labels';
import {
CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE,
CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE,
} from '../../../../k8s/EDPCodebase/labels';
import { EDPGitServerKubeObject } from '../../../../k8s/EDPGitServer';
import { capitalizeFirstLetter } from '../../../../utils/format/capitalizeFirstLetter';
import { getDefaultNamespace } from '../../../../utils/getDefaultNamespace';
Expand All @@ -28,7 +31,10 @@ export const PageView = () => {

const itemsArray = React.useMemo(() => (items ? items.filter(Boolean) : []), [items]);

const gitOpsCodebase = itemsArray.find(el => el.metadata.name === 'edp-gitops') ?? null;
const gitOpsCodebase =
itemsArray.find(
el => el.metadata.labels[CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE] === 'gitops'
) ?? null;

const status = gitOpsCodebase?.status?.status ?? CUSTOM_RESOURCE_STATUSES.UNKNOWN;

Expand Down
6 changes: 5 additions & 1 deletion src/pages/edp-stage-details/providers/Data/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useCDPipelineByNameQuery } from '../../../../k8s/EDPCDPipeline/hooks/us
import { useCDPipelineStageListByCDPipelineNameQuery } from '../../../../k8s/EDPCDPipelineStage/hooks/useCDPipelineStageListByCDPipelineNameQuery';
import { useCodebasesByTypeLabelQuery } from '../../../../k8s/EDPCodebase/hooks/useCodebasesByTypeLabelQuery';
import { useEnrichedApplicationsWithImageStreamsQuery } from '../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE } from '../../../../k8s/EDPCodebase/labels';
import { EDPStageDetailsRouteParams } from '../../types';
import { DataContext } from './context';

Expand Down Expand Up @@ -47,7 +48,10 @@ export const DataContextProvider: React.FC = ({ children }) => {
},
});

const gitOpsCodebase = codebases?.items.find(el => el.metadata.name === 'edp-gitops') ?? null;
const gitOpsCodebase =
codebases?.items.find(
el => el.metadata.labels[CODEBASE_LABEL_SELECTOR_CODEBASE_TYPE_SYSTEM_TYPE] === 'gitops'
) ?? null;

const DataContextValue = React.useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { useCreateCodebase } from '../../../../k8s/EDPCodebase/hooks/useCreateCodebase';
import { useCodebaseCRUD } from '../../../../k8s/EDPCodebase/hooks/useCodebaseCRUD';
import { EDPCodebaseKubeObjectInterface } from '../../../../k8s/EDPCodebase/types';
import { createCodebaseInstance } from '../../../../k8s/EDPCodebase/utils/createCodebaseInstance';
import { useDefaultCIToolQuery } from '../../../../k8s/EDPComponent/hooks/useDefaultCIToolQuery';
Expand Down Expand Up @@ -29,7 +29,7 @@ export const FormActions = () => {
const {
createCodebase,
mutations: { codebaseCreateMutation },
} = useCreateCodebase({
} = useCodebaseCRUD({
onSuccess: () => {
closeDialog();
reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { Render } from '../../../../../../../../components/Render';
import { useCreateCodebase } from '../../../../../../../../k8s/EDPCodebase/hooks/useCreateCodebase';
import { useCodebaseCRUD } from '../../../../../../../../k8s/EDPCodebase/hooks/useCodebaseCRUD';
import { createCodebaseInstance } from '../../../../../../../../k8s/EDPCodebase/utils/createCodebaseInstance';
import { useSpecificDialogContext } from '../../../../../../../../providers/Dialog/hooks';
import { getUsedValues } from '../../../../../../../../utils/forms/getUsedValues';
Expand Down Expand Up @@ -102,7 +102,7 @@ export const FormActions = ({
codebaseSecretCreateMutation,
codebaseSecretDeleteMutation,
},
} = useCreateCodebase({
} = useCodebaseCRUD({
onSuccess: handleClose,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { useEditCodebase } from '../../../../../../k8s/EDPCodebase/hooks/useEditCodebase';
import { useCodebaseCRUD } from '../../../../../../k8s/EDPCodebase/hooks/useCodebaseCRUD';
import { editCodebaseInstance } from '../../../../../../k8s/EDPCodebase/utils/editCodebaseInstance';
import { useSpecificDialogContext } from '../../../../../../providers/Dialog/hooks';
import { getUsedValues } from '../../../../../../utils/forms/getUsedValues';
Expand Down Expand Up @@ -33,7 +33,7 @@ export const FormActions = () => {
reset();
}, [closeDialog, reset]);

const { editCodebase } = useEditCodebase({
const { editCodebase } = useCodebaseCRUD({
onSuccess: handleClose,
});

Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ManageGitOps/components/FormActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, Grid } from '@material-ui/core';
import React from 'react';
import { useFormContext as useReactHookFormContext } from 'react-hook-form';
import { Render } from '../../../../components/Render';
import { useCreateCodebase } from '../../../../k8s/EDPCodebase/hooks/useCreateCodebase';
import { useCodebaseCRUD } from '../../../../k8s/EDPCodebase/hooks/useCodebaseCRUD';
import { createCodebaseInstance } from '../../../../k8s/EDPCodebase/utils/createCodebaseInstance';
import { useFormContext } from '../../../../providers/Form/hooks';
import { FORM_MODES } from '../../../../types/forms';
Expand Down Expand Up @@ -35,7 +35,7 @@ export const FormActions = () => {
codebaseSecretCreateMutation,
codebaseSecretDeleteMutation,
},
} = useCreateCodebase({
} = useCodebaseCRUD({
onSuccess: handleClose,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { GIT_SERVERS } from '../../../../../constants/gitServers';
import { FormTextField } from '../../../../../providers/Form/components/FormTextField';
import { useFormContext } from '../../../../../providers/Form/hooks';
import { FieldEvent } from '../../../../../types/forms';
import { GIT_OPS_CODEBASE_NAME } from '../../../constants';
import { CODEBASE_FORM_NAMES } from '../../../names';
import { ManageGitOpsDataContext, ManageGitOpsValues } from '../../../types';
// relative path should always start with slash
Expand All @@ -26,6 +25,7 @@ export const GitRepoPath = () => {
} = useFormContext<ManageGitOpsDataContext>();

const gitServerFieldValue = watch(CODEBASE_FORM_NAMES.gitRepoPath.name);
const nameFieldValue = watch(CODEBASE_FORM_NAMES.name.name);

return (
<FormTextField
Expand All @@ -40,7 +40,7 @@ export const GitRepoPath = () => {

setValue(
CODEBASE_FORM_NAMES.gitUrlPath.name,
isGerrit ? `/${GIT_OPS_CODEBASE_NAME}` : `${value}/${GIT_OPS_CODEBASE_NAME}`
isGerrit ? `/${nameFieldValue}` : `${value}/${nameFieldValue}`
);
},
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useGitServerListQuery } from '../../../../../k8s/EDPGitServer/hooks/use
import { FormSelect } from '../../../../../providers/Form/components/FormSelect';
import { useFormContext } from '../../../../../providers/Form/hooks';
import { FieldEvent } from '../../../../../types/forms';
import { GIT_OPS_CODEBASE_NAME } from '../../../constants';
import { CODEBASE_FORM_NAMES } from '../../../names';
import { ManageGitOpsDataContext, ManageGitOpsValues } from '../../../types';

Expand All @@ -29,6 +28,7 @@ export const GitServer = () => {
} = useFormContext<ManageGitOpsDataContext>();

const gitRepoPathFieldValue = watch(CODEBASE_FORM_NAMES.gitRepoPath.name);
const nameFieldValue = watch(CODEBASE_FORM_NAMES.name.name);

return (
<FormSelect
Expand All @@ -40,8 +40,8 @@ export const GitServer = () => {
setValue(
CODEBASE_FORM_NAMES.gitUrlPath.name,
isGerrit
? `/${GIT_OPS_CODEBASE_NAME}`
: `${gitRepoPathFieldValue}/${GIT_OPS_CODEBASE_NAME}`
? `/${nameFieldValue}`
: `${gitRepoPathFieldValue}/${nameFieldValue}`
);
},
})}
Expand Down
Loading

0 comments on commit e900a47

Please sign in to comment.