Skip to content

Commit

Permalink
fix: Fix some issues in pipeline and s2i
Browse files Browse the repository at this point in the history
Signed-off-by: harrisonliu5 <harrisonliu_5@163.com>
  • Loading branch information
harrisonliu5 committed Aug 12, 2020
1 parent 8a94610 commit 24e87b4
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/locales/en/s2i.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
'Jobs Records': 'Jobs Records',
'Last build environment': 'Last build environment',
'Last Message': 'Last Message',
'Log module is not installed': 'Log module is not installed',
'Log is loading...': 'Log is loading...',
'New Image Tag': 'New Image Tag',
'New Tag': 'New Tag',
Expand Down
1 change: 1 addition & 0 deletions src/locales/es/s2i.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
'Jobs Records': 'Registros de trabajos',
'Last build environment': 'Último entorno de compilación',
'Last Message': 'Ultimo mensaje',
'Log module is not installed': 'Log module is not installed',
'Log is loading...': 'El registro se está cargando ...',
'New Image Tag': 'Nuevo tag de imagen',
'New Tag': 'Nuevo tag',
Expand Down
1 change: 1 addition & 0 deletions src/locales/tc/s2i.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default {
s2i: '代碼構建鏡像',
b2i: '成品構建鏡像',
'Log is loading...': '紀錄正在載入',
'Log module is not installed': '日誌模塊未安裝',
'Build Environment': '構建環境',
'File Uploaded Successfully': '上傳檔案成功',
'Upload Percent': '上傳進度',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh/s2i.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default {
s2i: '代码构建镜像',
b2i: '制品构建镜像',
'Log is loading...': '日志正在加载',
'Log module is not installed': '日志模块未安装',
'Build Environment': '构建环境',
'File Uploaded Successfully': '上传文件成功',
'Upload Percent': '上传进度',
Expand Down
1 change: 1 addition & 0 deletions src/pages/devops/containers/Pipelines/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class CICDs extends React.Component {
const { params } = this.props.match

await this.store.runBranch({
cluster: params.cluster,
devops: params.devops,
name: record.name,
})
Expand Down
22 changes: 20 additions & 2 deletions src/pages/projects/components/Cards/ImageRunRecord/Item/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,33 @@ export default class ImageBuilderLastRun extends React.Component {
super(props)
this.state = {
showLog: false,
noModuleMsg: null,
}
this.LogContent = React.createRef()
this.store = props.store
}

componentWillUnmount() {
clearTimeout(this.refreshTimer)
this.setState({
noModuleMsg: null,
})
}

toggleShowLog = () => {
const { showLog } = this.state
if (!showLog) {
this.getLog()
if (globals.app.hasKSModule('logging')) {
this.getLog()
this.setState({
noModuleMsg: null,
})
} else {
this.store.logData.isLoading = false
this.setState({
noModuleMsg: t('Log module is not installed'),
})
}
} else {
clearTimeout(this.refreshTimer)
}
Expand Down Expand Up @@ -109,6 +123,8 @@ export default class ImageBuilderLastRun extends React.Component {

renderLog = () => {
const { log, isLoading } = this.store.logData
const { noModuleMsg } = this.state

if (!this.state.showLog) {
return null
}
Expand All @@ -123,7 +139,9 @@ export default class ImageBuilderLastRun extends React.Component {

return (
<div className={styles.logContent} onClick={this.stopPropagation}>
<pre ref={this.LogContent}>{log || t('Log is loading...')}</pre>
<pre ref={this.LogContent}>
{noModuleMsg || log || t('Log is loading...')}
</pre>
</div>
)
}
Expand Down
17 changes: 13 additions & 4 deletions src/pages/projects/components/Cards/S2iBuilder/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from 'react'
import { get } from 'lodash'
import { Loading, Select } from '@pitrix/lego-ui'

import { Card } from 'components/Base'
import { Panel } from 'components/Base'
import BuilderStore from 'stores/s2i/builder'
import RunStore from 'stores/s2i/run'
import MAPPER from 'utils/object.mapper'
Expand Down Expand Up @@ -51,6 +51,10 @@ export default class S2IBuilder extends React.Component {
builderNames: [],
}

get cluster() {
return this.props.cluster
}

componentDidMount() {
const { builderNames } = this.props
this.fetchData(builderNames[0])
Expand Down Expand Up @@ -87,11 +91,12 @@ export default class S2IBuilder extends React.Component {

getBuilderDetail = async builderName => {
const { namespace } = this.props

const result = await this.builderStore.fetchDetail({
cluster: this.cluster,
name: builderName,
namespace,
})

if (get(result, '_originData.reason', '') === 'NotFound') {
this.setState({ notFound: true })
return
Expand Down Expand Up @@ -125,6 +130,7 @@ export default class S2IBuilder extends React.Component {
clearTimeout(this.refreshTimer)

const result = await this.builderStore.rerun({
cluster: this.cluster,
newTag,
name: currentBuilderName,
namespace,
Expand Down Expand Up @@ -201,7 +207,10 @@ export default class S2IBuilder extends React.Component {
}

return (
<Card title={t('Building Image')} operations={this.renderBuilderSelect()}>
<Panel
title={t('Building Image')}
operations={this.renderBuilderSelect()}
>
<BuilderInfo config={config} className={className} />
{this.renderLog()}
<RerunModal
Expand All @@ -210,7 +219,7 @@ export default class S2IBuilder extends React.Component {
onOk={this.handleRerun}
onCancel={this.hideRerun}
/>
</Card>
</Panel>
)
}
}
30 changes: 18 additions & 12 deletions src/pages/projects/components/Cards/S2iBuilder/log.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ export default class Log extends React.Component {
this.state = {
showLog: true,
isContainerPending: false,
noModuleMsg: null,
}
this.store = new RunStore()
this.refreshTimer = null
this.LogContent = React.createRef()
}

componentDidMount() {
this.getLog()
if (globals.app.hasKSModule('logging')) {
this.getLog()
} else {
this.store.logData.isLoading = false
this.setState({
noModuleMsg: t('Log module is not installed'),
})
}
}

componentWillUnmount() {
this.setState({ noModuleMsg: null })
clearTimeout(this.refreshTimer)
}

Expand All @@ -70,15 +79,8 @@ export default class Log extends React.Component {
this.refreshTimer = setTimeout(this.getLog, 4000)
return
}
if (globals.app.hasKSModule('logging')) {
await this.store.getLog(logURL, cluster)
} else {
await this.store.fetchPodsLogs(logURL, cluster).catch(error => {
if (error === 'container not ready') {
this.setState({ isContainerPending: true })
}
})
}
await this.store.getLog(logURL, cluster)

this.handleScrollToBottom()
if (logData.hasMore) {
this.getLog()
Expand Down Expand Up @@ -160,7 +162,7 @@ export default class Log extends React.Component {
renderLog() {
const { log } = this.store.logData
const { runState } = this.props

const { noModuleMsg } = this.state
if (!log) {
if (runState === 'Running' || runState === 'Unknown') {
return (
Expand All @@ -171,7 +173,11 @@ export default class Log extends React.Component {
}
return <p className={styles.noneLogDesc}>{t('No log records')}</p>
}
return <pre ref={this.LogContent}>{log}</pre>
return (
<pre ref={this.LogContent}>
{noModuleMsg || log || t('Log is loading...')}
</pre>
)
}

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/projects/components/Health/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export default class Health extends React.Component {
)
}

if (score <= 10) {
if (score <= 30) {
return (
<span>
<span className={classNames(styles.icon, styles.error, className)} />
{t('Warning')}
</span>
)
}
if (score > 50 && score <= 90) {
if (score > 30 && score <= 80) {
return (
<span>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ class ResourceStatus extends React.Component {
const { cluster, namespace } = this.props.match.params
const { detail } = this.store

if (isEmpty(detail.builderNames)) {
if (isEmpty(toJS(detail.builderNames))) {
return null
}

return (
<S2iBuilderCard
builderNames={detail.builderNames}
builderNames={toJS(detail.builderNames)}
cluster={cluster}
namespace={namespace}
className={styles.deployment_codeResource}
Expand Down
21 changes: 12 additions & 9 deletions src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

require('whatwg-fetch')
const get = require('lodash/get')
const set = require('lodash/set')
const merge = require('lodash/merge')
const isEmpty = require('lodash/isEmpty')
const qs = require('qs')
const { getClusterUrl } = require('./index')
const cookie = require('./cookie').default
import 'whatwg-fetch'
import qs from 'qs'
import { isObject, get, set, merge, isEmpty } from 'lodash'
import { getClusterUrl, safeParseJSON } from './index'
import cookie from './cookie'

const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']

Expand Down Expand Up @@ -165,7 +162,6 @@ function handleResponse(response, reject) {
}

const contentType = response.headers.get('content-type')

if (contentType && contentType.includes('json')) {
return response.json().then(data => {
if (response.status === 401) {
Expand Down Expand Up @@ -200,6 +196,13 @@ function handleResponse(response, reject) {
message: text,
}

// some errors are the string-json in devops
const errBody = safeParseJSON(text)
if (isObject(errBody) && !isEmpty(errBody)) {
error.status = errBody.code
error.message = errBody.message
}

if (typeof reject === 'function') {
return reject(response, error)
}
Expand Down

0 comments on commit 24e87b4

Please sign in to comment.