Skip to content

Commit

Permalink
feat: Update Application resource creation and update templates with …
Browse files Browse the repository at this point in the history
…gitops codebase custom values (#32)

Jira: EPMDEDP-12496
Resolves: #32
Change-Id: Ib1cf78c8c1ba149eede379a6ae7bdbecc7dca6da
  • Loading branch information
callmevladik committed Sep 6, 2023
1 parent df11f29 commit 0ab33d3
Show file tree
Hide file tree
Showing 29 changed files with 614 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/configs/codebase-mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const CODEBASE_COMMON_FRAMEWORKS = {
OPERATOR_SDK: 'operator-sdk',
GIN: 'gin',
AWS: 'aws',
GIT_OPS: 'gitops',
} as const;

export const CODEBASE_COMMON_BUILD_TOOLS = {
Expand Down
47 changes: 47 additions & 0 deletions src/configs/codebase-mappings/system/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { CI_TOOLS } from '../../../constants/ciTools';
import {
BUILD_TOOL_ICON_MAPPING,
FRAMEWORK_ICON_MAPPING,
LANGUAGE_ICON_MAPPING,
} from '../../icon-mappings';
import {
CODEBASE_COMMON_BUILD_TOOLS,
CODEBASE_COMMON_FRAMEWORKS,
CODEBASE_COMMON_LANGUAGES,
} from '../index';
import { CodebaseInterface, CodebaseMappingKey } from '../types';

export type SystemLanguageKeys = typeof CODEBASE_COMMON_LANGUAGES.HELM;

type SystemMappingKey = Extract<CodebaseMappingKey, SystemLanguageKeys>;

export type SystemMapping = {
[K in SystemMappingKey]: CodebaseInterface;
};

export const SYSTEM_MAPPING: SystemMapping = {
[CODEBASE_COMMON_LANGUAGES.HELM]: {
language: {
name: 'Helm',
value: CODEBASE_COMMON_LANGUAGES.HELM,
icon: LANGUAGE_ICON_MAPPING[CODEBASE_COMMON_LANGUAGES.HELM],
availableCITools: [CI_TOOLS.TEKTON],
},
frameworks: {
[CODEBASE_COMMON_FRAMEWORKS.GIT_OPS]: {
name: 'GitOps',
value: CODEBASE_COMMON_FRAMEWORKS.GIT_OPS,
icon: FRAMEWORK_ICON_MAPPING[CODEBASE_COMMON_FRAMEWORKS.GIT_OPS],
availableCITools: [CI_TOOLS.TEKTON],
},
},
buildTools: {
[CODEBASE_COMMON_BUILD_TOOLS.HELM]: {
name: 'Helm',
value: CODEBASE_COMMON_BUILD_TOOLS.HELM,
icon: BUILD_TOOL_ICON_MAPPING[CODEBASE_COMMON_BUILD_TOOLS.HELM],
availableCITools: [CI_TOOLS.TEKTON],
},
},
},
};
1 change: 1 addition & 0 deletions src/configs/icon-mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const FRAMEWORK_ICON_MAPPING = {
[CODEBASE_COMMON_FRAMEWORKS.AWS]: RESOURCE_ICON_NAMES.AWS,
[CODEBASE_COMMON_FRAMEWORKS.GIN]: RESOURCE_ICON_NAMES.GIN,
[CODEBASE_COMMON_FRAMEWORKS.ANTORA]: RESOURCE_ICON_NAMES.ANTORA,
[CODEBASE_COMMON_FRAMEWORKS.GIT_OPS]: RESOURCE_ICON_NAMES.GIT_OPS,
} as const;

export const BUILD_TOOL_ICON_MAPPING = {
Expand Down
2 changes: 2 additions & 0 deletions src/icons/sprites/Resources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Gin,
Github,
Gitlab,
GitOps,
Go,
Gradle,
Groovy,
Expand Down Expand Up @@ -81,6 +82,7 @@ export const Resources = () => {
<Gin />
<NextJS />
<Antora />
<GitOps />
</svg>
);
};
1 change: 1 addition & 0 deletions src/icons/sprites/Resources/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export const RESOURCE_ICON_NAMES = {
AWS: 'AWS',
GIN: 'GIN',
ANTORA: 'antora',
GIT_OPS: 'gitops',
OTHER: 'other',
} as const;
18 changes: 18 additions & 0 deletions src/icons/sprites/Resources/symbols/GitOps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { RESOURCE_ICON_NAMES } from '../names';

export const GitOps = () => {
return (
<symbol
id={RESOURCE_ICON_NAMES.GIT_OPS}
viewBox="0 0 256 256"
xmlSpace="preserve"
preserveAspectRatio="xMidYMid"
>
<path
d="M251.172 116.594 139.4 4.828c-6.433-6.437-16.873-6.437-23.314 0l-23.21 23.21 29.443 29.443c6.842-2.312 14.688-.761 20.142 4.693 5.48 5.489 7.02 13.402 4.652 20.266l28.375 28.376c6.865-2.365 14.786-.835 20.269 4.657 7.663 7.66 7.663 20.075 0 27.74-7.665 7.666-20.08 7.666-27.749 0-5.764-5.77-7.188-14.235-4.27-21.336l-26.462-26.462-.003 69.637a19.82 19.82 0 0 1 5.188 3.71c7.663 7.66 7.663 20.076 0 27.747-7.665 7.662-20.086 7.662-27.74 0-7.663-7.671-7.663-20.086 0-27.746a19.654 19.654 0 0 1 6.421-4.281V94.196a19.378 19.378 0 0 1-6.421-4.281c-5.806-5.798-7.202-14.317-4.227-21.446L81.47 39.442 4.83 116.077c-6.44 6.443-6.44 16.884 0 23.322l111.774 111.768c6.435 6.438 16.873 6.438 23.316 0l111.251-111.249c6.438-6.44 6.438-16.887 0-23.324"
fill="#DE4C36"
/>
</symbol>
);
};
1 change: 1 addition & 0 deletions src/icons/sprites/Resources/symbols/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export * from './AWS';
export * from './Gin';
export * from './Nextjs';
export * from './Antora';
export * from './GitOps';
25 changes: 25 additions & 0 deletions src/k8s/Application/hooks/useCreateArgoApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ interface CreateArgoApplicationProps {
imageStream: EDPCodebaseImageStreamKubeObjectInterface;
imageTag: string;
valuesOverride: boolean;
gitOpsCodebase: EDPCodebaseKubeObjectInterface;
}

interface EditArgoApplicationProps {
argoApplication: ApplicationKubeObjectInterface;
gitServers: EDPGitServerKubeObjectInterface[];
CDPipeline: EDPCDPipelineKubeObjectInterface;
currentCDPipelineStage: EDPCDPipelineStageKubeObjectInterface;
application: EDPCodebaseKubeObjectInterface;
imageStream: EDPCodebaseImageStreamKubeObjectInterface;
imageTag: string;
valuesOverride: boolean;
gitOpsCodebase: EDPCodebaseKubeObjectInterface;
}

interface DeleteArgoApplicationProps {
Expand Down Expand Up @@ -56,6 +63,7 @@ export const useCreateArgoApplication = () => {
imageStream,
imageTag,
valuesOverride,
gitOpsCodebase,
}: CreateArgoApplicationProps): Promise<void> => {
const [gitServer] = gitServers.filter(
el => el.metadata.name === application.spec.gitServer
Expand All @@ -69,6 +77,7 @@ export const useCreateArgoApplication = () => {
imageTag,
gitServer,
valuesOverride,
gitOpsCodebase,
});

argoApplicationCreateMutation.mutate(argoApplicationData);
Expand All @@ -78,14 +87,30 @@ export const useCreateArgoApplication = () => {

const editArgoApplication = React.useCallback(
async ({
CDPipeline,
currentCDPipelineStage,
argoApplication,
application,
imageStream,
imageTag,
gitServers,
valuesOverride,
gitOpsCodebase,
}: EditArgoApplicationProps): Promise<void> => {
const [gitServer] = gitServers.filter(
el => el.metadata.name === application.spec.gitServer
);

const argoApplicationData: ApplicationKubeObjectInterface = editApplicationInstance({
CDPipeline,
currentCDPipelineStage,
argoApplication,
application,
imageStream,
imageTag,
gitServer,
valuesOverride,
gitOpsCodebase,
});

argoApplicationEditMutation.mutate(argoApplicationData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { CDPipelineMock } from '../mocks/CDPipeline.mock';
import { CDPipelineStageMock } from '../mocks/CDPipelineStage.mock';
import { enrichedApplicationMock } from '../mocks/enrichedApplication.mock';
import { gitOpsCodebaseMock } from '../mocks/gitOpsCodebase.mock';
import { gitServerMock } from '../mocks/gitServer.mock';
import { imageStreamMock } from '../mocks/imageStream.mock';
import { createArgoApplicationInstance } from './index';
Expand Down Expand Up @@ -42,6 +43,7 @@ describe('testing createApplicationInstance', () => {
imageTag: 'test-image-tag',
gitServer: gitServerMock as EDPGitServerKubeObjectInterface,
valuesOverride: false,
gitOpsCodebase: gitOpsCodebaseMock as unknown as EDPCodebaseKubeObjectInterface,
});

expect(object).toEqual(expectedApplicationOutputMock);
Expand All @@ -58,6 +60,7 @@ describe('testing createApplicationInstance', () => {
imageTag: 'test-image-tag',
gitServer: gitServerMock as EDPGitServerKubeObjectInterface,
valuesOverride: true,
gitOpsCodebase: gitOpsCodebaseMock as unknown as EDPCodebaseKubeObjectInterface,
});

expect(object).toEqual(expectedApplicationOutputMockWithValuesOverride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createArgoApplicationInstance = ({
imageTag,
gitServer,
valuesOverride,
gitOpsCodebase,
}: {
CDPipeline: EDPCDPipelineKubeObjectInterface;
currentCDPipelineStage: EDPCDPipelineStageKubeObjectInterface;
Expand All @@ -32,6 +33,7 @@ export const createArgoApplicationInstance = ({
imageTag: string;
gitServer: EDPGitServerKubeObjectInterface;
valuesOverride: boolean;
gitOpsCodebase: EDPCodebaseKubeObjectInterface;
}): ApplicationKubeObjectInterface => {
const {
metadata: { namespace, name: pipelineName },
Expand Down Expand Up @@ -62,6 +64,7 @@ export const createArgoApplicationInstance = ({

const isEDPVersioning = versioningType === CODEBASE_VERSIONING_TYPES.EDP;
const repoUrlUser = gitProvider === GIT_PROVIDERS.GERRIT ? 'argocd' : 'git';
const valuesRepoURL = `ssh://${repoUrlUser}@${gitHost}:${sshPort}${gitOpsCodebase.spec.gitUrlPath}`;
const repoURL = `ssh://${repoUrlUser}@${gitHost}:${sshPort}${gitUrlPath}`;
const targetRevision = isEDPVersioning ? `build/${imageTag}` : imageTag;

Expand Down Expand Up @@ -105,8 +108,8 @@ export const createArgoApplicationInstance = ({
? {
sources: [
{
repoURL: repoURL,
targetRevision: targetRevision,
repoURL: valuesRepoURL,
targetRevision: 'main',
ref: 'values',
},
{
Expand Down
59 changes: 57 additions & 2 deletions src/k8s/Application/utils/editApplicationInstance/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
// Todo: write new mocks
test('true', () => {});
import { EDPCDPipelineKubeObjectInterface } from '../../../EDPCDPipeline/types';
import { EDPCDPipelineStageKubeObjectInterface } from '../../../EDPCDPipelineStage/types';
import { EDPCodebaseKubeObjectInterface } from '../../../EDPCodebase/types';
import { EDPCodebaseImageStreamKubeObjectInterface } from '../../../EDPCodebaseImageStream/types';
import { EDPGitServerKubeObjectInterface } from '../../../EDPGitServer/types';
import { ApplicationKubeObjectInterface } from '../../types';
import {
expectedApplicationAfterEditOutputMock,
expectedApplicationAfterEditOutputMockWithValuesOverride,
} from '../mocks/application.mock';
import { CDPipelineMock } from '../mocks/CDPipeline.mock';
import { CDPipelineStageMock } from '../mocks/CDPipelineStage.mock';
import { enrichedApplicationMock } from '../mocks/enrichedApplication.mock';
import { gitOpsCodebaseMock } from '../mocks/gitOpsCodebase.mock';
import { gitServerMock } from '../mocks/gitServer.mock';
import { imageStreamMock } from '../mocks/imageStream.mock';
import { editApplicationInstance } from './index';

describe('testing editApplicationInstance', () => {
it('should return valid kube object', () => {
const object = editApplicationInstance({
CDPipeline: CDPipelineMock as EDPCDPipelineKubeObjectInterface,
currentCDPipelineStage:
CDPipelineStageMock as unknown as EDPCDPipelineStageKubeObjectInterface,
application:
enrichedApplicationMock.application as unknown as EDPCodebaseKubeObjectInterface,
imageStream: imageStreamMock as EDPCodebaseImageStreamKubeObjectInterface,
imageTag: 'test-image-tag',
gitServer: gitServerMock as EDPGitServerKubeObjectInterface,
valuesOverride: false,
gitOpsCodebase: gitOpsCodebaseMock as unknown as EDPCodebaseKubeObjectInterface,
argoApplication:
enrichedApplicationMock.argoApplication as unknown as ApplicationKubeObjectInterface,
});

expect(object).toEqual(expectedApplicationAfterEditOutputMock);
});

it('should return valid kube object with values override', () => {
const object = editApplicationInstance({
CDPipeline: CDPipelineMock as EDPCDPipelineKubeObjectInterface,
currentCDPipelineStage:
CDPipelineStageMock as unknown as EDPCDPipelineStageKubeObjectInterface,
application:
enrichedApplicationMock.application as unknown as EDPCodebaseKubeObjectInterface,
imageStream: imageStreamMock as EDPCodebaseImageStreamKubeObjectInterface,
imageTag: 'test-image-tag',
gitServer: gitServerMock as EDPGitServerKubeObjectInterface,
valuesOverride: true,
gitOpsCodebase: gitOpsCodebaseMock as unknown as EDPCodebaseKubeObjectInterface,
argoApplication:
enrichedApplicationMock.argoApplication as unknown as ApplicationKubeObjectInterface,
});

expect(object).toEqual(expectedApplicationAfterEditOutputMockWithValuesOverride);
});
});
Loading

0 comments on commit 0ab33d3

Please sign in to comment.