diff --git a/assets/translations/en-us.yaml b/assets/translations/en-us.yaml index b3fc0bb750a..1595e523933 100644 --- a/assets/translations/en-us.yaml +++ b/assets/translations/en-us.yaml @@ -3421,7 +3421,9 @@ workload: subdomain: label: Subdomain placeholder: e.g. web - + validation: + containers: Containers + containerImage: Container {name} - "Container Image" is required. replicas: Replicas showTabs: 'Show Advanced Options' scheduling: diff --git a/edit/workload/index.vue b/edit/workload/index.vue index 4a734463370..93c36962e2f 100644 --- a/edit/workload/index.vue +++ b/edit/workload/index.vue @@ -525,17 +525,6 @@ export default { if (this.container && !this.container.name) { this.$set(this.container, 'name', this.value.metadata.name); } - if (this.container) { - let existing; - - if (this.isInitContainer) { - existing = this.podTemplateSpec.initContainers.find(container => container._active); - } else { - existing = this.podTemplateSpec.containers.find(container => container._active); - } - - Object.assign(existing, this.container); - } const ports = this.value.containers.reduce((total, each) => { const containerPorts = each.ports || []; diff --git a/edit/workload/storage/index.vue b/edit/workload/storage/index.vue index 6212f1cbbeb..378afc1609f 100644 --- a/edit/workload/storage/index.vue +++ b/edit/workload/storage/index.vue @@ -57,10 +57,7 @@ export default { }, async fetch() { - const pvcs = await this.$store.dispatch('cluster/findAll', { type: PVC }); - const namespace = this.namespace || this.$store.getters['defaultNamespace']; - - this.pvcs = pvcs.filter(pvc => pvc.metadata.namespace === namespace); + this.pvcs = await this.$store.dispatch('cluster/findAll', { type: PVC }); }, data() { @@ -72,6 +69,12 @@ export default { return this.mode === _VIEW; }, + namespacedPVCs() { + const namespace = this.namespace || this.$store.getters['defaultNamespace']; + + return this.pvcs.filter(pvc => pvc.metadata.namespace === namespace); + }, + volumeTypeOpts() { const hasComponent = require .context('@/edit/workload/storage', false, /^.*\.vue$/) @@ -99,7 +102,7 @@ export default { }, pvcNames() { - return this.pvcs.map(pvc => pvc.metadata.name); + return this.namespacedPVCs.map(pvc => pvc.metadata.name); }, // only show volumes mounted in current container containerVolumes: { diff --git a/utils/validators/container-images.js b/utils/validators/container-images.js index adfbad50edb..14919f9501c 100644 --- a/utils/validators/container-images.js +++ b/utils/validators/container-images.js @@ -1,18 +1,24 @@ +import { get } from '@/utils/object'; + export function containerImages(spec, getters, errors) { - let container; + let podSpec; if (spec.jobTemplate) { // cronjob pod template is nested slightly different than other types - const { jobTemplate: { spec: { template: { spec: { containers = [] } } } } } = spec; - - container = containers[0] || {}; + podSpec = get(spec, 'jobTemplate.spec.template.spec'); } else { - const { template:{ spec:{ containers = [] } } } = spec; - - container = containers[0] || {}; + podSpec = get(spec, 'template.spec'); } - if (!container.image) { - errors.push(getters['i18n/t']('validation.required', { key: getters['i18n/t']('workload.container.image') })); + if (!podSpec.containers || !podSpec.containers.length) { + errors.push(getters['i18n/t']('validation.required', { key: getters['i18n/t']('workload.container.titles.containers') })); + + return; } + + podSpec.containers.forEach((container) => { + if (container && !container.image) { + errors.push(getters['i18n/t']('workload.validation.containerImage', { name: container.name })); + } + }); }