Skip to content

Commit

Permalink
Merge pull request #41 from webzard-io/yz-patch
Browse files Browse the repository at this point in the history
improve workload form init values
  • Loading branch information
MrWindlike authored Oct 16, 2023
2 parents 4c56892 + 670e2f1 commit 0b02efa
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 163 deletions.
147 changes: 147 additions & 0 deletions packages/refine/src/constants/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,150 @@ export const BASE_INIT_VALUE = {
labels: {},
},
};

const DEFAULT_MATCH_LABEL = 'sks.user.kubesmart.smtx.io/app';

const BASE_CONTAINER_INIT_VALUE = {
name: 'container-0',
imagePullPolicy: 'Always',
image: '',
};

const BASE_WORKLOAD_SPEC_INIT_VALUE = {
affinity: {},
imagePullSecrets: [],
initContainers: [],
volumes: [],
};

export const DEPLOYMENT_INIT_VALUE = {
apiVersion: 'apps/v1',
kind: 'Deployment',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {
[DEFAULT_MATCH_LABEL]: '',
},
},
template: {
metadata: {
labels: {
[DEFAULT_MATCH_LABEL]: '',
},
},
spec: {
containers: [BASE_CONTAINER_INIT_VALUE],
restartPolicy: 'Always',
...BASE_WORKLOAD_SPEC_INIT_VALUE,
},
},
},
};

export const CRONJOB_INIT_VALUE = {
apiVersion: 'batch/v1beta1',
kind: 'CronJob',
...BASE_INIT_VALUE,
spec: {
schedule: '',
jobTemplate: {
metadata: {
labels: {},
},
spec: {
template: {
spec: {
containers: [BASE_CONTAINER_INIT_VALUE],
restartPolicy: 'Never',
...BASE_WORKLOAD_SPEC_INIT_VALUE,
},
},
},
},
},
};

export const DAEMONSET_INIT_VALUE = {
apiVersion: 'apps/v1',
kind: 'DaemonSet',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {
[DEFAULT_MATCH_LABEL]: '',
},
},
template: {
metadata: {
labels: {
[DEFAULT_MATCH_LABEL]: '',
},
},
spec: {
containers: [BASE_CONTAINER_INIT_VALUE],
restartPolicy: 'Always',
...BASE_WORKLOAD_SPEC_INIT_VALUE,
},
},
},
};

export const JOB_INIT_VALUE = {
apiVersion: 'batch/v1',
kind: 'Job',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {},
},
template: {
metadata: {
labels: {},
},
spec: {
containers: [BASE_CONTAINER_INIT_VALUE],
restartPolicy: 'Never',
...BASE_WORKLOAD_SPEC_INIT_VALUE,
},
},
},
};

export const STATEFULSET_INIT_VALUE = {
apiVersion: 'apps/v1',
kind: 'StatefulSet',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {
[DEFAULT_MATCH_LABEL]: '',
},
},
template: {
metadata: {
labels: {
[DEFAULT_MATCH_LABEL]: '',
},
},
spec: {
containers: [BASE_CONTAINER_INIT_VALUE],
restartPolicy: 'Always',
...BASE_WORKLOAD_SPEC_INIT_VALUE,
},
},
},
};

export const POD_INIT_VALUE = {
apiVersion: 'v1',
kind: 'Pod',
...BASE_INIT_VALUE,
spec: {
containers: [BASE_CONTAINER_INIT_VALUE],
},
};
31 changes: 2 additions & 29 deletions packages/refine/src/pages/cronjobs/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { FormProps } from 'antd/lib/form';
import React from 'react';
import YamlForm from 'src/components/YamlForm';
import { BASE_INIT_VALUE } from 'src/constants/k8s';
import { CRONJOB_INIT_VALUE } from 'src/constants/k8s';

export const CronJobForm: React.FC<FormProps> = () => {
return (
<YamlForm
initialValues={{
apiVersion: 'batch/v1beta1',
kind: 'CronJob',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {},
},
template: {
metadata: {
labels: {},
},
spec: {
containers: [
{
name: '',
image: '',
},
],
},
},
},
}}
/>
);
return <YamlForm initialValues={CRONJOB_INIT_VALUE} />;
};
31 changes: 2 additions & 29 deletions packages/refine/src/pages/daemonsets/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { FormProps } from 'antd/lib/form';
import React from 'react';
import YamlForm from 'src/components/YamlForm';
import { BASE_INIT_VALUE } from 'src/constants/k8s';
import { DAEMONSET_INIT_VALUE } from 'src/constants/k8s';

export const DaemonSetForm: React.FC<FormProps> = () => {
return (
<YamlForm
initialValues={{
apiVersion: 'apps/v1',
kind: 'DaemonSet',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {},
},
template: {
metadata: {
labels: {},
},
spec: {
containers: [
{
name: '',
image: '',
},
],
},
},
},
}}
/>
);
return <YamlForm initialValues={DAEMONSET_INIT_VALUE} />;
};
31 changes: 2 additions & 29 deletions packages/refine/src/pages/deployments/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { FormProps } from 'antd/lib/form';
import React from 'react';
import YamlForm from 'src/components/YamlForm';
import { BASE_INIT_VALUE } from 'src/constants/k8s';
import { DEPLOYMENT_INIT_VALUE } from 'src/constants/k8s';

export const DeploymentForm: React.FC<FormProps> = () => {
return (
<YamlForm
initialValues={{
apiVersion: 'apps/v1',
kind: 'Deployment',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {},
},
template: {
metadata: {
labels: {},
},
spec: {
containers: [
{
name: '',
image: '',
},
],
},
},
},
}}
/>
);
return <YamlForm initialValues={DEPLOYMENT_INIT_VALUE} />;
};
31 changes: 2 additions & 29 deletions packages/refine/src/pages/jobs/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { FormProps } from 'antd/lib/form';
import React from 'react';
import YamlForm from 'src/components/YamlForm';
import { BASE_INIT_VALUE } from 'src/constants/k8s';
import { JOB_INIT_VALUE } from 'src/constants/k8s';

export const JobForm: React.FC<FormProps> = () => {
return (
<YamlForm
initialValues={{
apiVersion: 'batch/v1',
kind: 'Job',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {},
},
template: {
metadata: {
labels: {},
},
spec: {
containers: [
{
name: '',
image: '',
},
],
},
},
},
}}
/>
);
return <YamlForm initialValues={JOB_INIT_VALUE} />;
};
20 changes: 2 additions & 18 deletions packages/refine/src/pages/pods/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { FormProps } from 'antd/lib/form';
import React from 'react';
import YamlForm from 'src/components/YamlForm';
import { BASE_INIT_VALUE } from 'src/constants/k8s';
import { POD_INIT_VALUE } from 'src/constants/k8s';

export const PodForm: React.FC<FormProps> = () => {
return (
<YamlForm
initialValues={{
apiVersion: 'v1',
kind: 'Pod',
...BASE_INIT_VALUE,
spec: {
containers: [
{
name: '',
image: '',
},
],
},
}}
/>
);
return <YamlForm initialValues={POD_INIT_VALUE} />;
};
31 changes: 2 additions & 29 deletions packages/refine/src/pages/statefulsets/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { FormProps } from 'antd/lib/form';
import React from 'react';
import YamlForm from 'src/components/YamlForm';
import { BASE_INIT_VALUE } from 'src/constants/k8s';
import { STATEFULSET_INIT_VALUE } from 'src/constants/k8s';

export const StatefulSetForm: React.FC<FormProps> = () => {
return (
<YamlForm
initialValues={{
apiVersion: 'apps/v1',
kind: 'StatefulSet',
...BASE_INIT_VALUE,
spec: {
replicas: 1,
selector: {
matchLabels: {},
},
template: {
metadata: {
labels: {},
},
spec: {
containers: [
{
name: '',
image: '',
},
],
},
},
},
}}
/>
);
return <YamlForm initialValues={STATEFULSET_INIT_VALUE} />;
};

0 comments on commit 0b02efa

Please sign in to comment.