Skip to content

Commit

Permalink
feat: Add federated project resource management
Browse files Browse the repository at this point in the history
  • Loading branch information
leoliu committed Jun 12, 2020
1 parent 2afee75 commit b873b68
Show file tree
Hide file tree
Showing 259 changed files with 13,891 additions and 1,213 deletions.
38 changes: 37 additions & 1 deletion server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ client:
- cate: 'workspace'
items:
- { name: overview, title: Overview, icon: dashboard, skipAuth: true }
- { name: projects, title: NAV_PROJECTS, icon: project, skipAuth: true }
- name: projects
title: NAV_PROJECTS
icon: project
tabs:
- { name: projects, title: Projects }
- { name: federatedprojects, title: Multi-cluster Projects }
- { name: devops, title: DevOps Projects, icon: strategy-group }
- name: apps
title: Apps Management
Expand Down Expand Up @@ -317,6 +322,37 @@ client:
authKey: 'project-settings',
}

federatedProjectNavs:
- cate: 'project'
items:
- { name: overview, title: Overview, icon: dashboard, skipAuth: true }
- name: app-workloads
title: Application Workloads
icon: appcenter
children:
- { name: applications, title: Applications, icon: application }
- { name: services, title: Services }
- name: workloads
title: Workloads
tabs:
- { name: deployments, title: Deployments }
- { name: statefulsets, title: StatefulSets }
- { name: ingresses, title: Routes }
- { name: volumes, title: Volumes, icon: storage }
- name: config
title: Configuration Center
icon: hammer
children:
- { name: secrets, title: Secrets }
- { name: configmaps, title: ConfigMaps }
- name: settings
title: Project Settings
icon: cogwheel
children:
- { name: base-info, title: Basic Info, skipAuth: true }
- { name: quota, title: Quota Management, authKey: 'project-settings' }
- { name: advanced, title: Advanced Settings, authKey: 'project-settings' }

# devops page navigations
devopsNavs:
- cate: ''
Expand Down
30 changes: 18 additions & 12 deletions src/actions/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { set } from 'lodash'
import { Modal, Notify } from 'components/Base'
import { mergeLabels } from 'utils'
import { mergeLabels, updateFederatedAnnotations } from 'utils'

import DeployAppModal from 'projects/components/Modals/DeployApp'
import CreateAppModal from 'projects/components/Modals/CreateApp'
Expand All @@ -43,10 +43,7 @@ export default {
onOk: data => {
store.create(data, { cluster, namespace }).then(() => {
Modal.close(modal)
success &&
success(
`/${workspace}/clusters/${cluster}/projects/${namespace}/applications/composing`
)
success && success()
})
},
store,
Expand All @@ -60,14 +57,15 @@ export default {
'crd.app.addcomponent': {
on({ store, detail, cluster, namespace, success, ...props }) {
const modal = Modal.open({
onOk: data => {
onOk: async data => {
const labels = detail.selector
const serviceMeshEnable = String(detail.serviceMeshEnable)

const component = {
service: data.Service,
workload: data.Deployment || data.StatefulSet,
}

mergeLabels(component.service, labels)
mergeLabels(component.workload, labels)

Expand All @@ -88,13 +86,21 @@ export default {
serviceMeshEnable
)

store
.addComponent(component, { name: detail.name, cluster, namespace })
.then(() => {
Modal.close(modal)
Notify.success({ content: `${t('Add Component Successfully')}!` })
success && success()
if (props.isFederated) {
updateFederatedAnnotations(component.workload)
updateFederatedAnnotations(component.service)
await store.create(component, { namespace })
} else {
await store.addComponent(component, {
name: detail.name,
cluster,
namespace,
})
}

Modal.close(modal)
Notify.success({ content: `${t('Add Component Successfully')}!` })
success && success()
},
store,
cluster,
Expand Down
13 changes: 12 additions & 1 deletion src/actions/configmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ import FORM_STEPS from 'configs/steps/configmaps'

export default {
'configmap.create': {
on({ store, cluster, namespace, module, success, ...props }) {
on({ store, cluster, namespace, module, isFederated, success, ...props }) {
const kind = MODULE_KIND_MAP[module]
const formTemplate = {
[kind]: FORM_TEMPLATES[module]({
namespace,
}),
}

if (isFederated) {
Object.keys(formTemplate).forEach(key => {
formTemplate[key] = FORM_TEMPLATES.federated({
data: formTemplate[key],
clusters: props.projectDetail.clusters.map(item => item.name),
kind: key,
})
})
}

const modal = Modal.open({
onOk: newObject => {
const data = get(newObject, kind)
Expand All @@ -55,6 +65,7 @@ export default {
cluster,
namespace,
name: kind,
isFederated,
formTemplate,
steps: FORM_STEPS,
modal: CreateModal,
Expand Down
16 changes: 10 additions & 6 deletions src/actions/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
const params = {
name: data.name,
namespace: detail.name,
cluster: detail.cluster,
}

const spec = get(data, 'spec.hard', {})
Expand All @@ -76,12 +77,15 @@ export default {
spec: data.spec,
})
} else {
await quotaStore.create({
apiVersion: 'v1',
kind: 'ResourceQuota',
metadata: { ...params, name: detail.name },
spec: data.spec,
})
await quotaStore.create(
{
apiVersion: 'v1',
kind: 'ResourceQuota',
metadata: { ...params, name: detail.name },
spec: data.spec,
},
params
)
}

Modal.close(modal)
Expand Down
15 changes: 3 additions & 12 deletions src/actions/resource.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@

import { Modal, Notify } from 'components/Base'
import DeleteModal from 'components/Modals/Delete'
import FederatedStore from 'stores/federated'

export default {
'resource.delete': {
on({ store, detail, success, ...props }) {
const fedStore = new FederatedStore(store.module)
const _store = detail.isFedManaged ? fedStore : store

const modal = Modal.open({
onOk: () => {
_store.delete(detail).then(() => {
store.delete(detail).then(() => {
Modal.close(modal)
Notify.success({ content: `${t('Deleted Successfully')}!` })
success && success()
})
},
store: _store,
store,
modal: DeleteModal,
resource: detail.name,
...props,
Expand All @@ -43,7 +39,6 @@ export default {
},
'resource.batch.delete': {
on({ store, success, rowKey, ...props }) {
const fedStore = new FederatedStore(store.module)
const { data, selectedRowKeys } = store.list

const selectNames = data
Expand All @@ -56,11 +51,7 @@ export default {

data.forEach(item => {
if (selectNames.includes(item.name)) {
if (item.isFedManaged) {
reqs.push(fedStore.delete(item))
} else {
reqs.push(store.delete(item))
}
reqs.push(store.delete(item))
}
})

Expand Down
8 changes: 2 additions & 6 deletions src/actions/resource.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { Modal } from 'components/Base'
import EditBasicInfoModal from 'components/Modals/EditBasicInfo'
import EditYamlModal from 'components/Modals/EditYaml'

import FederatedStore from 'stores/federated'

export default {
'resource.baseinfo.edit': {
on({ store, detail, success, ...props }) {
Expand All @@ -41,16 +39,14 @@ export default {
},
'resource.yaml.edit': {
on({ store, detail, success, ...props }) {
const fedStore = new FederatedStore(store.module)
const _store = detail.isFedManaged ? fedStore : store
const modal = Modal.open({
onOk: async data => {
await _store.patch(detail, data)
await store.patch(detail, data)
Modal.close(modal)
success && success()
},
detail,
store: _store,
store,
modal: EditYamlModal,
...props,
})
Expand Down
13 changes: 12 additions & 1 deletion src/actions/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ import FORM_STEPS from 'configs/steps/ingresses'

export default {
'router.create': {
on({ store, cluster, namespace, module, success, ...props }) {
on({ store, cluster, namespace, module, success, isFederated, ...props }) {
const kind = MODULE_KIND_MAP[module]
const formTemplate = {
[kind]: FORM_TEMPLATES[module]({
namespace,
}),
}

if (isFederated) {
Object.keys(formTemplate).forEach(key => {
formTemplate[key] = FORM_TEMPLATES.federated({
data: formTemplate[key],
clusters: props.projectDetail.clusters.map(item => item.name),
kind: key,
})
})
}

const modal = Modal.open({
onOk: newObject => {
const data = get(newObject, kind)
Expand All @@ -59,6 +69,7 @@ export default {
namespace,
name: 'Route',
formTemplate,
isFederated,
steps: FORM_STEPS,
modal: CreateModal,
store,
Expand Down
13 changes: 12 additions & 1 deletion src/actions/secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ import FORM_STEPS from 'configs/steps/secrets'

export default {
'secret.create': {
on({ store, cluster, namespace, module, success, ...props }) {
on({ store, cluster, namespace, module, isFederated, success, ...props }) {
const kind = MODULE_KIND_MAP[module]
const formTemplate = {
[kind]: FORM_TEMPLATES[module]({
namespace,
}),
}

if (isFederated) {
Object.keys(formTemplate).forEach(key => {
formTemplate[key] = FORM_TEMPLATES.federated({
data: formTemplate[key],
clusters: props.projectDetail.clusters.map(item => item.name),
kind: key,
})
})
}

const modal = Modal.open({
onOk: newObject => {
const data = get(newObject, kind)
Expand All @@ -55,6 +65,7 @@ export default {
cluster,
namespace,
name: kind,
isFederated,
formTemplate,
steps: FORM_STEPS,
modal: CreateModal,
Expand Down
14 changes: 13 additions & 1 deletion src/actions/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ export default {
cluster,
namespace,
module,
isFederated,
extendformTemplate,
success,
...props
}) {
const kind = MODULE_KIND_MAP[module]
const formTemplate = {
[kind]: {
...FORM_TEMPLATES[module]({
...FORM_TEMPLATES.volumes({
namespace,
}),
...extendformTemplate,
},
}

if (isFederated) {
Object.keys(formTemplate).forEach(key => {
formTemplate[key] = FORM_TEMPLATES.federated({
data: formTemplate[key],
clusters: props.projectDetail.clusters.map(item => item.name),
kind: key,
})
})
}

const modal = Modal.open({
onOk: async newObject => {
const data = get(newObject, kind)
Expand All @@ -70,6 +81,7 @@ export default {
namespace,
name: kind,
formTemplate,
isFederated,
steps: fromSnapshot ? APPLY_SNAPSHOT_FORM_STEPS : FORM_STEPS,
modal: CreateModal,
store,
Expand Down
Loading

0 comments on commit b873b68

Please sign in to comment.