diff --git a/locales/en/l10n-projects-applicationWorkloads-daemonsets-list.js b/locales/en/l10n-projects-applicationWorkloads-daemonsets-list.js index 8e08ee4e778..6d03db61531 100644 --- a/locales/en/l10n-projects-applicationWorkloads-daemonsets-list.js +++ b/locales/en/l10n-projects-applicationWorkloads-daemonsets-list.js @@ -19,6 +19,8 @@ module.exports = { // Banner // List + DAEMONSETS_LOW: 'daemonsets', + DAEMONSETS_PL: 'daemonsets', // List > Create > Basic Information // List > Create > Pod Settings CONTAINER_SETTINGS_DESC: 'Set the image, name, type, and computing resources of the container.', diff --git a/locales/en/l10n-projects-applicationWorkloads-statefulsets-list.js b/locales/en/l10n-projects-applicationWorkloads-statefulsets-list.js index 046c8a60713..378658a39cb 100644 --- a/locales/en/l10n-projects-applicationWorkloads-statefulsets-list.js +++ b/locales/en/l10n-projects-applicationWorkloads-statefulsets-list.js @@ -19,6 +19,8 @@ module.exports = { // Banner // List + STATEFULSETS_LOW: 'Statefulsets', + STATEFULSETS_PL: 'Statefulsets', // List > Create > Basic Information // List > Create > Pod Settings > Update Settings > Rolling Update Settings PARTITION_ORDINAL_EMPTY: 'Please set a ordinal for dividing pod replicas.', diff --git a/src/pages/clusters/containers/Workload/DaemonSets/index.jsx b/src/pages/clusters/containers/Workload/DaemonSets/index.jsx index 4e7e8a8b92d..54143424e88 100644 --- a/src/pages/clusters/containers/Workload/DaemonSets/index.jsx +++ b/src/pages/clusters/containers/Workload/DaemonSets/index.jsx @@ -25,6 +25,7 @@ import { withClusterList, ListPage } from 'components/HOCs/withList' import WorkloadStatus from 'projects/components/WorkloadStatus' import StatusReason from 'projects/components/StatusReason' import ResourceTable from 'clusters/components/ResourceTable' +import { get } from 'lodash' import { getLocalTime, getDisplayName } from 'utils' import { getWorkloadStatus } from 'utils/status' @@ -36,6 +37,7 @@ import WorkloadStore from 'stores/workload' store: new WorkloadStore('daemonsets'), module: 'daemonsets', name: 'WORKLOAD', + rowKey: 'uid', }) export default class DaemonSets extends React.Component { handleTabChange = value => { @@ -64,6 +66,23 @@ export default class DaemonSets extends React.Component { } } + get selectActions() { + const { tableProps, trigger, module, rootStore } = this.props + return [ + ...get(tableProps, 'tableActions.selectActions', {}), + { + key: 'stop', + text: t('STOP'), + onClick: () => + trigger('resource.batch.stop', { + type: module.toUpperCase(), + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get itemActions() { const { module, name, trigger } = this.props return [ @@ -202,6 +221,7 @@ export default class DaemonSets extends React.Component { !record.isFedManaged + get selectActions() { + const { tableProps, trigger, module, rootStore } = this.props + return [ + ...get(tableProps, 'tableActions.selectActions', {}), + { + key: 'stop', + text: t('STOP'), + onClick: () => + trigger('resource.batch.stop', { + type: module.toUpperCase(), + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get itemActions() { const { module, trigger, name } = this.props return [ @@ -215,6 +233,7 @@ export default class StatefulSets extends React.Component { + trigger('resource.batch.stop', { + type: name, + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get tableActions() { const { trigger, name, tableProps } = this.props return { @@ -191,6 +209,7 @@ export default class Deployments extends React.Component { {...tableProps} itemActions={this.itemActions} tableActions={this.tableActions} + selectActions={this.selectActions} columns={this.getColumns()} onCreate={this.showCreate} searchType="name" diff --git a/src/pages/fedprojects/containers/StatefulSets/index.jsx b/src/pages/fedprojects/containers/StatefulSets/index.jsx index 335529ed420..b7e7884dd3f 100644 --- a/src/pages/fedprojects/containers/StatefulSets/index.jsx +++ b/src/pages/fedprojects/containers/StatefulSets/index.jsx @@ -17,7 +17,7 @@ */ import React from 'react' - +import { get } from 'lodash' import { Avatar, Status } from 'components/Base' import Banner from 'components/Cards/Banner' import { withProjectList, ListPage } from 'components/HOCs/withList' @@ -35,6 +35,7 @@ import WorkloadStore from 'stores/workload' store: new FederatedStore(new WorkloadStore('statefulsets')), module: 'statefulsets', name: 'WORKLOAD', + rowKey: 'uid', }) export default class StatefulSets extends React.Component { get prefix() { @@ -63,6 +64,23 @@ export default class StatefulSets extends React.Component { } } + get selectActions() { + const { tableProps, trigger, module, rootStore } = this.props + return [ + ...get(tableProps, 'tableActions.selectActions', {}), + { + key: 'stop', + text: t('STOP'), + onClick: () => + trigger('resource.batch.stop', { + type: module.toUpperCase(), + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get itemActions() { const { trigger, name } = this.props return [ @@ -208,6 +226,7 @@ export default class StatefulSets extends React.Component { {...tableProps} itemActions={this.itemActions} tableActions={this.tableActions} + selectActions={this.selectActions} columns={this.getColumns()} onCreate={this.showCreate} searchType="name" diff --git a/src/pages/projects/containers/DaemonSets/index.jsx b/src/pages/projects/containers/DaemonSets/index.jsx index df8b342a625..50fcd29be7a 100644 --- a/src/pages/projects/containers/DaemonSets/index.jsx +++ b/src/pages/projects/containers/DaemonSets/index.jsx @@ -17,7 +17,7 @@ */ import React from 'react' - +import { get } from 'lodash' import { Avatar } from 'components/Base' import Banner from 'components/Cards/Banner' import { withProjectList, ListPage } from 'components/HOCs/withList' @@ -35,6 +35,7 @@ import WorkloadStore from 'stores/workload' store: new WorkloadStore('daemonsets'), module: 'daemonsets', name: 'WORKLOAD', + rowKey: 'uid', }) export default class DaemonSets extends React.Component { get prefix() { @@ -67,6 +68,23 @@ export default class DaemonSets extends React.Component { } } + get selectActions() { + const { tableProps, trigger, module, rootStore } = this.props + return [ + ...get(tableProps, 'tableActions.selectActions', {}), + { + key: 'stop', + text: t('STOP'), + onClick: () => + trigger('resource.batch.stop', { + type: module.toUpperCase(), + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get itemActions() { const { module, trigger, name } = this.props return [ @@ -215,6 +233,7 @@ export default class DaemonSets extends React.Component { {...tableProps} itemActions={this.itemActions} tableActions={this.tableActions} + selectActions={this.selectActions} columns={this.getColumns()} onCreate={this.showCreate} /> diff --git a/src/pages/projects/containers/Deployments/index.jsx b/src/pages/projects/containers/Deployments/index.jsx index 56d3d6b19f9..8738b265693 100644 --- a/src/pages/projects/containers/Deployments/index.jsx +++ b/src/pages/projects/containers/Deployments/index.jsx @@ -17,7 +17,7 @@ */ import React from 'react' - +import { get } from 'lodash' import { Avatar } from 'components/Base' import Banner from 'components/Cards/Banner' import { withProjectList, ListPage } from 'components/HOCs/withList' @@ -35,6 +35,7 @@ import WorkloadStore from 'stores/workload' store: new WorkloadStore('deployments'), module: 'deployments', name: 'WORKLOAD', + rowKey: 'uid', }) export default class Deployments extends React.Component { get prefix() { @@ -67,6 +68,23 @@ export default class Deployments extends React.Component { } } + get selectActions() { + const { tableProps, trigger, name, rootStore } = this.props + return [ + ...get(tableProps, 'tableActions.selectActions', {}), + { + key: 'stop', + text: t('STOP'), + onClick: () => + trigger('resource.batch.stop', { + type: name, + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get itemActions() { const { module, trigger, name } = this.props return [ @@ -224,6 +242,7 @@ export default class Deployments extends React.Component { {...tableProps} itemActions={this.itemActions} tableActions={this.tableActions} + selectActions={this.selectActions} columns={this.getColumns()} onCreate={this.showCreate} /> diff --git a/src/pages/projects/containers/StatefulSets/index.jsx b/src/pages/projects/containers/StatefulSets/index.jsx index e77b8f1df5b..c640fef7e00 100644 --- a/src/pages/projects/containers/StatefulSets/index.jsx +++ b/src/pages/projects/containers/StatefulSets/index.jsx @@ -17,7 +17,7 @@ */ import React from 'react' - +import { get } from 'lodash' import { Avatar } from 'components/Base' import Banner from 'components/Cards/Banner' import { withProjectList, ListPage } from 'components/HOCs/withList' @@ -35,6 +35,7 @@ import WorkloadStore from 'stores/workload' store: new WorkloadStore('statefulsets'), module: 'statefulsets', name: 'WORKLOAD', + rowKey: 'uid', }) export default class StatefulSets extends React.Component { get prefix() { @@ -67,6 +68,23 @@ export default class StatefulSets extends React.Component { } } + get selectActions() { + const { tableProps, trigger, module, rootStore } = this.props + return [ + ...get(tableProps, 'tableActions.selectActions', {}), + { + key: 'stop', + text: t('STOP'), + onClick: () => + trigger('resource.batch.stop', { + type: module.toUpperCase(), + rowKey: 'uid', + success: rootStore.routing.query(), + }), + }, + ] + } + get itemActions() { const { module, trigger, name } = this.props return [ @@ -223,6 +241,7 @@ export default class StatefulSets extends React.Component { {...tableProps} itemActions={this.itemActions} tableActions={this.tableActions} + selectActions={this.selectActions} columns={this.getColumns()} onCreate={this.showCreate} /> diff --git a/src/stores/federated.js b/src/stores/federated.js index 33d05bbb640..9ded625cc14 100644 --- a/src/stores/federated.js +++ b/src/stores/federated.js @@ -16,8 +16,8 @@ * along with KubeSphere Console. If not, see . */ -import { set, get, keyBy, findKey, cloneDeep } from 'lodash' -import { action, observable } from 'mobx' +import { set, get, keyBy, findKey, cloneDeep, isEmpty } from 'lodash' +import { action, observable, toJS } from 'mobx' import { withDryRun, LimitsEqualRequests } from 'utils' import ObjectMapper from 'utils/object.mapper' import { MODULE_KIND_MAP } from 'utils/constants' @@ -356,4 +356,67 @@ export default class FederatedStore extends Base { async deleteSchedule(params) { return request.delete(`${this.getScheduleListUrl(params)}/${params.name}`) } + + @action + async stop(item) { + const { name, cluster, namespace } = item + const params = { name, cluster, namespace } + const promises = [] + let scheduleData = {} + + if (this.resourceStore.module === 'deployments') { + scheduleData = await request.get( + `${this.getScheduleListUrl(params)}/${params.name}`, + {}, + {}, + () => { + return {} + } + ) + } + + const isWeightScheduled = !isEmpty(scheduleData) + const overrides = [...toJS(item._originData.spec.overrides)] + + if (isWeightScheduled) { + promises.push( + request.patch(`${this.getScheduleListUrl(params)}/${params.name}`, { + spec: { + totalReplicas: 0, + }, + }) + ) + } else { + const _overrides = overrides.map(config => { + if (config.clusterOverrides) { + config.clusterOverrides = config.clusterOverrides.map(spec => { + spec.value = 0 + return spec + }) + return config + } + + config = { + ...config, + clusterOverrides: [ + { + path: '/spec/replicas', + value: 0, + }, + ], + } + return config + }) + + promises.push( + request.patch(this.getDetailUrl({ name, cluster, namespace }), { + spec: { + overrides: _overrides, + }, + }) + ) + + return this.submitting(Promise.all(promises)) + } + } } diff --git a/src/stores/workload/index.js b/src/stores/workload/index.js index b328c83b358..e24098d8f53 100644 --- a/src/stores/workload/index.js +++ b/src/stores/workload/index.js @@ -161,12 +161,26 @@ export default class WorkloadStore extends Base { @action stop({ name, cluster, namespace }) { const promises = [] + const patchFiled = + this.module === 'daemonsets' + ? { + spec: { + template: { + spec: { + nodeSelector: { + 'non-existing': 'true', + }, + }, + }, + }, + } + : { + spec: { + replicas: 0, + }, + } promises.push( - request.patch(this.getDetailUrl({ name, cluster, namespace }), { - spec: { - replicas: 0, - }, - }) + request.patch(this.getDetailUrl({ name, cluster, namespace }), patchFiled) ) return this.submitting(Promise.all(promises))