Merge pull request #2370 from mantis-toboggan-md/workload-detail

workload details pod list update
This commit is contained in:
Nancy 2021-02-23 09:18:33 -07:00 committed by GitHub
commit db04cd43f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 51 deletions

View File

@ -22,8 +22,11 @@ export default {
mixins: [CreateEditView],
async fetch() {
const hash = { pods: this.value.pods() };
const hash = { allPods: this.$store.dispatch('cluster/findAll', { type: POD }) };
if (this.value.type === WORKLOAD_TYPES.CRON_JOB) {
hash.allJobs = this.$store.dispatch('cluster/findAll', { type: WORKLOAD_TYPES.JOB });
}
const res = await allHash(hash);
for ( const k in res ) {
@ -32,10 +35,20 @@ export default {
},
data() {
return { pods: null };
return { allPods: null, allJobs: [] };
},
computed: {
pods() {
const relationships = get(this.value, 'metadata.relationships') || [];
const podRelationship = relationships.filter(relationship => relationship.toType === POD)[0];
if (podRelationship) {
return this.$store.getters['cluster/matching'](POD, podRelationship.selector).filter(pod => pod?.metadata?.namespace === this.value.metadata.namespace);
} else {
return [];
}
},
isJob() {
return this.value.type === WORKLOAD_TYPES.JOB;
},
@ -62,23 +75,21 @@ export default {
return this.podTemplateSpec?.containers[0];
},
jobEntries() {
if (this.value.type !== WORKLOAD_TYPES.CRON_JOB) {
jobRelationships() {
if (!this.isCronJob) {
return;
}
return get(this.value, 'status.active') || [];
return (get(this.value, 'metadata.relationships') || []).filter(relationship => relationship.toType === WORKLOAD_TYPES.JOB);
},
jobs() {
if (this.value.type !== WORKLOAD_TYPES.CRON_JOB) {
if (!this.isCronJob) {
return;
}
const entries = this.jobEntries;
return entries.map((obj) => {
return this.$store.getters['cluster/byId'](WORKLOAD_TYPES.JOB, `${ obj.namespace }/${ obj.name }`);
return this.jobRelationships.map((obj) => {
return this.$store.getters['cluster/byId'](WORKLOAD_TYPES.JOB, obj.toId );
}).filter(x => !!x);
},
@ -116,6 +127,22 @@ export default {
return out;
},
totalRuns() {
if (!this.jobs) {
return;
}
return this.jobs.reduce((total, job) => {
const { status = {} } = job;
total += (status.active || 0);
total += (status.succeeded || 0);
total += (status.failed || 0);
return total;
}, 0);
},
podRestarts() {
return this.pods.reduce((total, pod) => {
const { status:{ containerStatuses = [] } } = pod;
@ -188,7 +215,7 @@ export default {
<CountGauge
v-for="(group, key) in jobGauges"
:key="key"
:total="isCronJob? jobs.length : pods.length"
:total="isCronJob? totalRuns : pods.length"
:useful="group.count || 0"
:primary-color-var="`--sizzle-${group.color}`"
:name="t(`workload.gaugeStates.${key}`)"

View File

@ -1,6 +1,6 @@
import { insertAt } from '@/utils/array';
import { TARGET_WORKLOADS, TIMESTAMP, UI_MANAGED } from '@/config/labels-annotations';
import { WORKLOAD_TYPES, POD, SERVICE } from '@/config/types';
import { WORKLOAD_TYPES, SERVICE } from '@/config/types';
import { clone, get, set } from '@/utils/object';
import day from 'dayjs';
import { _CREATE } from '@/config/query-params';
@ -33,7 +33,7 @@ export default {
applyDefaults() {
return (vm, mode) => {
const spec = {};
const { spec = {} } = this;
if (this.type === WORKLOAD_TYPES.CRON_JOB) {
if (!spec.jobTemplate) {
@ -194,43 +194,9 @@ export default {
return out;
},
pods() {
const { metadata:{ relationships = [] } } = this;
return async() => {
if (this.type === WORKLOAD_TYPES.CRON_JOB) {
const jobRelationships = relationships.filter(relationship => relationship.toType === WORKLOAD_TYPES.JOB);
if (jobRelationships) {
const jobs = await Promise.all(jobRelationships.map((relationship) => {
return this.$dispatch('cluster/find', { type: WORKLOAD_TYPES.JOB, id: relationship.toId }, { root: true });
}));
const jobPods = await Promise.all(jobs.map((job) => {
return job.pods();
}));
return jobPods.reduce((all, each) => {
all.push(...each);
return all;
}, []);
}
}
const podRelationship = relationships.filter(relationship => relationship.toType === POD)[0];
let pods;
if (podRelationship) {
pods = await this.$dispatch('cluster/findMatching', { type: POD, selector: podRelationship.selector }, { root: true });
}
return pods.filter(pod => pod.metadata.namespace === this.metadata.namespace);
};
},
getServicesOwned() {
return async() => {
const { metadata:{ relationships = [] } } = this;
const relationships = get(this, 'metadata.relationships') || [];
const serviceRelationships = relationships.filter(relationship => relationship.toType === SERVICE && relationship.rel === 'owner');
if (serviceRelationships.length) {

View File

@ -360,7 +360,7 @@ export const actions = {
return;
}
// console.debug(`Create Event [${ state.config.namespace }]`, data.type, data.id); // eslint-disable-line no-console
// console.log(`Create Event [${ state.config.namespace }]`, data.type, data.id); // eslint-disable-line no-console
state.queue.push({
action: 'dispatch',
@ -374,7 +374,7 @@ export const actions = {
return;
}
// console.debug(`Change Event [${ state.config.namespace }]`, data.type, data.id); // eslint-disable-line no-console
// console.log(`Change Event [${ state.config.namespace }]`, data.type, data.id); // eslint-disable-line no-console
state.queue.push({
action: 'dispatch',
@ -390,7 +390,7 @@ export const actions = {
return;
}
// console.debug(`Remove Event [${ state.config.namespace }]`, data.type, data.id); // eslint-disable-line no-console
// console.log(`Remove Event [${ state.config.namespace }]`, data.type, data.id); // eslint-disable-line no-console
const obj = getters.byId(data.type, data.id);