From ac084742d767751a7c9a211e0d3f7191c87d216d Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Fri, 29 Nov 2024 11:11:53 +0800 Subject: [PATCH 1/4] feat: cronjob history limit num from env --- frontend/providers/cronjob/deploy/Kubefile | 3 +++ frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl | 4 ++++ frontend/providers/cronjob/src/utils/json2Yaml.ts | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/providers/cronjob/deploy/Kubefile b/frontend/providers/cronjob/deploy/Kubefile index d1537f2f426..3dca0d3f3f4 100644 --- a/frontend/providers/cronjob/deploy/Kubefile +++ b/frontend/providers/cronjob/deploy/Kubefile @@ -9,4 +9,7 @@ ENV cloudDomain="127.0.0.1.nip.io" ENV cloudPort="" ENV certSecretName="wildcard-cert" +ENV SUCCESSFUL_JOBS_HISTORY_LIMIT="3" +ENV FAILED_JOBS_HISTORY_LIMIT="3" + CMD ["kubectl apply -f manifests"] diff --git a/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl b/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl index 2c00f4930d6..a61b41cf119 100644 --- a/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl +++ b/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl @@ -41,6 +41,10 @@ spec: value: {{ .cloudDomain }} - name: APPLAUNCHPAD_URL value: applaunchpad.{{ .cloudDomain }} + - name: SUCCESSFUL_JOBS_HISTORY_LIMIT + value: {{ .successfulJobsHistoryLimit }} + - name: FAILED_JOBS_HISTORY_LIMIT + value: {{ .failedJobsHistoryLimit }} securityContext: runAsNonRoot: true runAsUser: 1001 diff --git a/frontend/providers/cronjob/src/utils/json2Yaml.ts b/frontend/providers/cronjob/src/utils/json2Yaml.ts index 982ea8ce2de..f516f63513a 100644 --- a/frontend/providers/cronjob/src/utils/json2Yaml.ts +++ b/frontend/providers/cronjob/src/utils/json2Yaml.ts @@ -111,8 +111,8 @@ export const json2CronJob = (data: CronJobEditType) => { schedule: data.schedule, concurrencyPolicy: 'Replace', startingDeadlineSeconds: 60, - successfulJobsHistoryLimit: 3, - failedJobsHistoryLimit: 3, + successfulJobsHistoryLimit: Number(process.env.SUCCESSFUL_JOBS_HISTORY_LIMIT) || 3, + failedJobsHistoryLimit: Number(process.env.FAILED_JOBS_HISTORY_LIMIT) || 3, timeZone: timeZone, jobTemplate: { activeDeadlineSeconds: 600, From 67096bc594625142f54624824ad0cd8161f86852 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Fri, 29 Nov 2024 11:34:51 +0800 Subject: [PATCH 2/4] fix: env from api --- .../providers/cronjob/deploy/manifests/deploy.yaml.tmpl | 4 ++-- .../providers/cronjob/src/pages/api/platform/getEnv.ts | 6 +++++- frontend/providers/cronjob/src/utils/json2Yaml.ts | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl b/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl index a61b41cf119..814dffcb36d 100644 --- a/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl +++ b/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl @@ -42,9 +42,9 @@ spec: - name: APPLAUNCHPAD_URL value: applaunchpad.{{ .cloudDomain }} - name: SUCCESSFUL_JOBS_HISTORY_LIMIT - value: {{ .successfulJobsHistoryLimit }} + value: "{{ .successfulJobsHistoryLimit }}" - name: FAILED_JOBS_HISTORY_LIMIT - value: {{ .failedJobsHistoryLimit }} + value: "{{ .failedJobsHistoryLimit }}" securityContext: runAsNonRoot: true runAsUser: 1001 diff --git a/frontend/providers/cronjob/src/pages/api/platform/getEnv.ts b/frontend/providers/cronjob/src/pages/api/platform/getEnv.ts index 7ca46baf7d5..2e8044e0795 100644 --- a/frontend/providers/cronjob/src/pages/api/platform/getEnv.ts +++ b/frontend/providers/cronjob/src/pages/api/platform/getEnv.ts @@ -6,13 +6,17 @@ import type { NextApiRequest, NextApiResponse } from 'next'; export type EnvResponse = { domain: string; applaunchpadUrl: string; + successfulJobsHistoryLimit: number; + failedJobsHistoryLimit: number; }; export default async function handler(req: NextApiRequest, res: NextApiResponse) { jsonRes(res, { data: { domain: process.env.SEALOS_DOMAIN || defaultDomain, - applaunchpadUrl: process.env.APPLAUNCHPAD_URL || `applaunchpad.${process.env.SEALOS_DOMAIN}` + applaunchpadUrl: process.env.APPLAUNCHPAD_URL || `applaunchpad.${process.env.SEALOS_DOMAIN}`, + successfulJobsHistoryLimit: Number(process.env.SUCCESSFUL_JOBS_HISTORY_LIMIT) || 3, + failedJobsHistoryLimit: Number(process.env.FAILED_JOBS_HISTORY_LIMIT) || 3 } }); } diff --git a/frontend/providers/cronjob/src/utils/json2Yaml.ts b/frontend/providers/cronjob/src/utils/json2Yaml.ts index f516f63513a..191c8b4c400 100644 --- a/frontend/providers/cronjob/src/utils/json2Yaml.ts +++ b/frontend/providers/cronjob/src/utils/json2Yaml.ts @@ -8,7 +8,8 @@ import useEnvStore from '@/store/env'; export const json2CronJob = (data: CronJobEditType) => { const timeZone = getUserTimeZone(); const kcHeader = encodeURIComponent(getUserKubeConfig()); - const { applaunchpadUrl } = useEnvStore.getState().SystemEnv; + const { applaunchpadUrl, successfulJobsHistoryLimit, failedJobsHistoryLimit } = + useEnvStore.getState().SystemEnv; const metadata = { name: data.jobName, @@ -111,8 +112,8 @@ export const json2CronJob = (data: CronJobEditType) => { schedule: data.schedule, concurrencyPolicy: 'Replace', startingDeadlineSeconds: 60, - successfulJobsHistoryLimit: Number(process.env.SUCCESSFUL_JOBS_HISTORY_LIMIT) || 3, - failedJobsHistoryLimit: Number(process.env.FAILED_JOBS_HISTORY_LIMIT) || 3, + successfulJobsHistoryLimit, + failedJobsHistoryLimit, timeZone: timeZone, jobTemplate: { activeDeadlineSeconds: 600, From eff4a09eae1e38b900ae9aaf89e5f9645cac056a Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Fri, 29 Nov 2024 11:39:16 +0800 Subject: [PATCH 3/4] fix: use Env Store --- frontend/providers/cronjob/src/store/env.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/providers/cronjob/src/store/env.ts b/frontend/providers/cronjob/src/store/env.ts index 79197e489b1..82db7872dad 100644 --- a/frontend/providers/cronjob/src/store/env.ts +++ b/frontend/providers/cronjob/src/store/env.ts @@ -13,7 +13,9 @@ const useEnvStore = create()( immer((set, get) => ({ SystemEnv: { domain: '', - applaunchpadUrl: '' + applaunchpadUrl: '', + successfulJobsHistoryLimit: 3, + failedJobsHistoryLimit: 3 }, initSystemEnv: async () => { const data = await getPlatformEnv(); From 462203e4fccc98b01f3c683f30d7b381a48c4032 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Fri, 29 Nov 2024 13:10:24 +0800 Subject: [PATCH 4/4] fix: deploy env name --- frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl b/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl index 814dffcb36d..6b1cb420ece 100644 --- a/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl +++ b/frontend/providers/cronjob/deploy/manifests/deploy.yaml.tmpl @@ -42,9 +42,9 @@ spec: - name: APPLAUNCHPAD_URL value: applaunchpad.{{ .cloudDomain }} - name: SUCCESSFUL_JOBS_HISTORY_LIMIT - value: "{{ .successfulJobsHistoryLimit }}" + value: "{{ .SUCCESSFUL_JOBS_HISTORY_LIMIT }}" - name: FAILED_JOBS_HISTORY_LIMIT - value: "{{ .failedJobsHistoryLimit }}" + value: "{{ .FAILED_JOBS_HISTORY_LIMIT }}" securityContext: runAsNonRoot: true runAsUser: 1001