Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve workload form init values #41

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} />;
};