From f1e16f5e121bd3359f90fb255747d1e9d16724dc Mon Sep 17 00:00:00 2001 From: LiuYan <361112237@qq.com> Date: Thu, 11 May 2023 15:42:56 +0800 Subject: [PATCH] fix missing job/pod resources on CronJobs/Jobs detail page --- shell/models/batch.cronjob.js | 21 ++++++++++++++++++--- shell/models/workload.js | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/shell/models/batch.cronjob.js b/shell/models/batch.cronjob.js index 012a3bdf52..6e7a5ce754 100644 --- a/shell/models/batch.cronjob.js +++ b/shell/models/batch.cronjob.js @@ -2,6 +2,7 @@ import { insertAt } from '@shell/utils/array'; import { clone } from '@shell/utils/object'; import { WORKLOAD_TYPES } from '@shell/config/types'; import Workload from './workload'; +import { WORKLOAD_TYPE_TO_KIND_MAPPING } from '@shell/detail/workload/index'; export default class CronJob extends Workload { get state() { @@ -47,12 +48,26 @@ export default class CronJob extends Workload { } async runNow() { - const job = await this.$dispatch('create', clone(this.spec.jobTemplate)); + const ownerRef = { + apiVersion: this.apiVersion, + controller: true, + kind: this.kind, + name: this.metadata.name, + uid: this.metadata.uid + }; + + // Set type and kind to ensure the correct model is returned (via classify). This object will be persisted to the store + const job = await this.$dispatch('create', { + type: WORKLOAD_TYPES.JOB, + kind: WORKLOAD_TYPE_TO_KIND_MAPPING[WORKLOAD_TYPES.JOB], + ...clone(this.spec.jobTemplate) + }); - job.type = WORKLOAD_TYPES.JOB; job.metadata = job.metadata || {}; job.metadata.namespace = this.metadata.namespace; - job.metadata.generateName = `${ this.metadata.name }-`; + // Can't use `generatedName` and no `name`... as this fails schema validation + job.metadata.name = `${ this.metadata.name }-${ Date.now() }`; + job.metadata.ownerReferences = [ownerRef]; await job.save(); diff --git a/shell/models/workload.js b/shell/models/workload.js index 14be1cdd9a..895b958829 100644 --- a/shell/models/workload.js +++ b/shell/models/workload.js @@ -296,7 +296,7 @@ export default class Workload extends WorkloadService { } get endpoint() { - return this?.metadata?.annotations[CATTLE_PUBLIC_ENDPOINTS]; + return this?.metadata?.annotations?.[CATTLE_PUBLIC_ENDPOINTS]; } get desired() {