Skip to content

Commit

Permalink
fix: Remove unuse code in container form.
Browse files Browse the repository at this point in the history
  • Loading branch information
leoliu committed May 26, 2020
1 parent 2663785 commit a474835
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class DropdownContent extends React.Component {
}

get registryUrl() {
const { formTemplate, imageRegistries } = this.props
const { imageRegistries } = this.props
if (!isEmpty(imageRegistries) && this.secretValue) {
const selectedSecret = imageRegistries.find(
item => item.value === this.secretValue
Expand All @@ -64,11 +64,8 @@ export default class DropdownContent extends React.Component {
return url
}
}
return get(
formTemplate,
'metadata.annotations["kubesphere.io/registryUrl"]',
''
)

return ''
}

get imageName() {
Expand Down Expand Up @@ -130,12 +127,7 @@ export default class DropdownContent extends React.Component {

handleSecretChange = value => {
const { formTemplate } = this.props
const currentSecret = this.secretsOptions.find(item => item.value === value)
let url = currentSecret.url || 'docker.io'

url = url.endsWith('/') ? url : `${url}/`
set(formTemplate, 'pullSecret', value)
set(formTemplate, 'metadata.annotations["kubesphere.io/registryUrl"]', url)
this.props.onChange(this.registryUrl)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class ContaineForm extends React.Component {
}

handleSubmit = callback => {
const { onSave } = this.props
const { onSave, withService } = this.props
const form = this.formRef.current

form &&
Expand All @@ -143,6 +143,12 @@ export default class ContaineForm extends React.Component {
)
}

if (!withService) {
data.ports.forEach(item => {
delete item.servicePort
})
}

onSave(data)
callback && callback()
})
Expand Down
43 changes: 23 additions & 20 deletions src/components/Forms/Workload/ContainerSettings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

import { concat, get, set, unset, isEmpty, omitBy, has, groupBy } from 'lodash'
import { concat, get, set, unset, isEmpty, omitBy, has } from 'lodash'
import React from 'react'
import { safeParseJSON, generateId } from 'utils'
import { MODULE_KIND_MAP } from 'utils/constants'
Expand Down Expand Up @@ -174,6 +174,7 @@ export default class ContainerSetting extends React.Component {
if (container.pullSecret) {
pullSecrets[container.pullSecret] = ''
containerSecretMap[container.name] = container.pullSecret
delete container.pullSecret
}
})

Expand All @@ -191,7 +192,12 @@ export default class ContainerSetting extends React.Component {
}

updateService = formData => {
const { formTemplate, module } = this.props
const { formTemplate, module, withService } = this.props

if (!withService) {
return
}

const containers = get(formData, `${this.prefix}spec.containers`, [])

// auto gen service ports by workload container ports
Expand Down Expand Up @@ -265,34 +271,31 @@ export default class ContainerSetting extends React.Component {
}

// split mergedContainers and update formTemplate
const groupedContainers = groupBy(mergedContainers, 'type')
set(
this.formTemplate,
`${this.prefix}spec.containers`,
groupedContainers['worker']
)
set(
this.formTemplate,
`${this.prefix}spec.initContainers`,
groupedContainers['init'] || []
)
const _containers = []
const _initContainers = []
mergedContainers.forEach(item => {
if (item.type === 'worker') {
delete item.type
_containers.push(item)
} else {
delete item.type
_initContainers.push(item)
}
})
set(this.formTemplate, `${this.prefix}spec.containers`, _containers)
set(this.formTemplate, `${this.prefix}spec.initContainers`, _initContainers)

// update image pull secrets
this.updatePullSecrets(this.formTemplate)

if (this.props.withService) {
this.updateService(this.formTemplate)
}
this.updateService(this.formTemplate)

this.hideContainer()
}

handleDelete = () => {
this.updatePullSecrets(this.formTemplate)

if (this.props.withService) {
this.updateService(this.formTemplate)
}
this.updateService(this.formTemplate)
}

handleClusterChange = value => {
Expand Down

0 comments on commit a474835

Please sign in to comment.