Updated graphql query in frontend and added cron support for custom workflow (#2333)
* Updated graphql query and added cron support for custom workflow Signed-off-by: Amit Kumar Das <amitkumar.das@mayadata.io> * Minor fix Signed-off-by: Amit Kumar Das <amitkumar.das@mayadata.io> * Fixed deepscan issue Signed-off-by: Amit Kumar Das <amitkumar.das@mayadata.io>
This commit is contained in:
parent
ecc15cec25
commit
4adb1db3a5
|
@ -8,7 +8,6 @@ import React from 'react';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
import { useSelector } from 'react-redux';
|
||||
import YAML from 'yaml';
|
||||
import workflowsList from '../PredifinedWorkflows/data';
|
||||
import Unimodal from '../../containers/layouts/Unimodal';
|
||||
import { CREATE_WORKFLOW } from '../../graphql';
|
||||
import {
|
||||
|
@ -35,6 +34,7 @@ import ButtonOutline from '../Button/ButtonOutline';
|
|||
import QontoConnector from './quontoConnector';
|
||||
import useStyles from './styles';
|
||||
import useQontoStepIconStyles from './useQontoStepIconStyles';
|
||||
import { cronWorkflow, workflowOnce } from '../../utils/workflowTemplate';
|
||||
|
||||
function getSteps(): string[] {
|
||||
return [
|
||||
|
@ -122,7 +122,6 @@ const CustomStepper = () => {
|
|||
(state: RootState) => state.workflowData
|
||||
);
|
||||
const {
|
||||
id,
|
||||
yaml,
|
||||
weights,
|
||||
description,
|
||||
|
@ -148,68 +147,50 @@ const CustomStepper = () => {
|
|||
const workflow = useActions(WorkflowActions);
|
||||
const [invalidYaml, setinValidYaml] = React.useState(false);
|
||||
const steps = getSteps();
|
||||
const scheduleOnce = workflowOnce;
|
||||
const scheduleMore = cronWorkflow;
|
||||
|
||||
function EditYaml() {
|
||||
const oldParsedYaml = YAML.parse(yaml);
|
||||
let NewLink: string = ' ';
|
||||
let NewYaml: string = ' ';
|
||||
const NewLink: string = ' ';
|
||||
if (
|
||||
oldParsedYaml.kind === 'Workflow' &&
|
||||
scheduleType.scheduleOnce !== 'now'
|
||||
) {
|
||||
NewLink = workflowsList[parseInt(id, 10)].chaosWkfCRDLink_Recur as string;
|
||||
fetch(NewLink)
|
||||
.then((data) => {
|
||||
data.text().then((yamlText) => {
|
||||
const oldParsedYaml = YAML.parse(yaml);
|
||||
const newParsedYaml = YAML.parse(yamlText);
|
||||
delete newParsedYaml.spec.workflowSpec;
|
||||
newParsedYaml.spec.schedule = cronSyntax;
|
||||
delete newParsedYaml.metadata.generateName;
|
||||
newParsedYaml.metadata.name = workflowData.name;
|
||||
newParsedYaml.spec.workflowSpec = oldParsedYaml.spec;
|
||||
const tz = {
|
||||
timezone:
|
||||
Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC',
|
||||
};
|
||||
Object.entries(tz).forEach(([key, value]) => {
|
||||
newParsedYaml.spec[key] = value;
|
||||
});
|
||||
NewYaml = YAML.stringify(newParsedYaml);
|
||||
workflow.setWorkflowDetails({
|
||||
link: NewLink,
|
||||
yaml: NewYaml,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Unable to fetch the yaml text${err}`);
|
||||
});
|
||||
const oldParsedYaml = YAML.parse(yaml);
|
||||
const newParsedYaml = YAML.parse(scheduleMore);
|
||||
delete newParsedYaml.spec.workflowSpec;
|
||||
newParsedYaml.spec.schedule = cronSyntax;
|
||||
delete newParsedYaml.metadata.generateName;
|
||||
newParsedYaml.metadata.name = workflowData.name;
|
||||
newParsedYaml.spec.workflowSpec = oldParsedYaml.spec;
|
||||
const timeZone = {
|
||||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC',
|
||||
};
|
||||
Object.entries(timeZone).forEach(([key, value]) => {
|
||||
newParsedYaml.spec[key] = value;
|
||||
});
|
||||
const NewYaml = YAML.stringify(newParsedYaml);
|
||||
workflow.setWorkflowDetails({
|
||||
link: NewLink,
|
||||
yaml: NewYaml,
|
||||
});
|
||||
}
|
||||
if (
|
||||
oldParsedYaml.kind === 'CronWorkflow' &&
|
||||
scheduleType.scheduleOnce === 'now'
|
||||
) {
|
||||
NewLink = workflowsList[parseInt(id, 10)].chaosWkfCRDLink as string;
|
||||
fetch(NewLink)
|
||||
.then((data) => {
|
||||
data.text().then((yamlText) => {
|
||||
const oldParsedYaml = YAML.parse(yaml);
|
||||
const newParsedYaml = YAML.parse(yamlText);
|
||||
delete newParsedYaml.spec;
|
||||
delete newParsedYaml.metadata.generateName;
|
||||
newParsedYaml.metadata.name = workflowData.name;
|
||||
newParsedYaml.spec = oldParsedYaml.spec.workflowSpec;
|
||||
NewYaml = YAML.stringify(newParsedYaml);
|
||||
workflow.setWorkflowDetails({
|
||||
link: NewLink,
|
||||
yaml: NewYaml,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Unable to fetch the yaml text${err}`);
|
||||
});
|
||||
const oldParsedYaml = YAML.parse(yaml);
|
||||
const newParsedYaml = YAML.parse(scheduleOnce);
|
||||
delete newParsedYaml.spec;
|
||||
delete newParsedYaml.metadata.generateName;
|
||||
newParsedYaml.metadata.name = workflowData.name;
|
||||
newParsedYaml.spec = oldParsedYaml.spec.workflowSpec;
|
||||
const NewYaml = YAML.stringify(newParsedYaml);
|
||||
workflow.setWorkflowDetails({
|
||||
link: NewLink,
|
||||
yaml: NewYaml,
|
||||
});
|
||||
}
|
||||
if (
|
||||
oldParsedYaml.kind === 'CronWorkflow' &&
|
||||
|
@ -219,13 +200,13 @@ const CustomStepper = () => {
|
|||
newParsedYaml.spec.schedule = cronSyntax;
|
||||
delete newParsedYaml.metadata.generateName;
|
||||
newParsedYaml.metadata.name = workflowData.name;
|
||||
const tz = {
|
||||
const timeZone = {
|
||||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC',
|
||||
};
|
||||
Object.entries(tz).forEach(([key, value]) => {
|
||||
Object.entries(timeZone).forEach(([key, value]) => {
|
||||
newParsedYaml.spec[key] = value;
|
||||
});
|
||||
NewYaml = YAML.stringify(newParsedYaml);
|
||||
const NewYaml = YAML.stringify(newParsedYaml);
|
||||
workflow.setWorkflowDetails({
|
||||
link: NewLink,
|
||||
yaml: NewYaml,
|
||||
|
|
|
@ -35,6 +35,7 @@ export const SCHEDULE_DETAILS = gql`
|
|||
cluster_id
|
||||
cluster_type
|
||||
cluster_name
|
||||
isRemoved
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -18,6 +18,7 @@ export interface ScheduleWorkflow {
|
|||
cluster_name: string;
|
||||
cluster_type: string;
|
||||
regularity?: string;
|
||||
isRemoved: boolean;
|
||||
}
|
||||
|
||||
export interface Schedules {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export const workflowOnce =
|
||||
'{\r\n "apiVersion": "argoproj.io/v1alpha1",\r\n "kind": "Workflow",\r\n "metadata": {\r\n "generateName": "argowf-chaos-node-cpu-hog-",\r\n "namespace": "litmus"\r\n },\r\n "spec": null\r\n}';
|
||||
export const cronWorkflow =
|
||||
'{\r\n "apiVersion": "argoproj.io/v1alpha1",\r\n "kind": "CronWorkflow",\r\n "metadata": {\r\n "name": "argo-chaos-pod-memory-cron-wf",\r\n "namespace": "litmus"\r\n },\r\n "spec": {\r\n "schedule": "0 * * * *",\r\n "concurrencyPolicy": "Forbid",\r\n "startingDeadlineSeconds": 0,\r\n "workflowSpec": null\r\n }\r\n}';
|
Loading…
Reference in New Issue