Skip to content

Commit

Permalink
fix: Fix loadbalancer info of service, ingress and gateway
Browse files Browse the repository at this point in the history
Signed-off-by: leoliu <leoliu@yunify.com>
  • Loading branch information
leoliu committed Aug 17, 2020
1 parent 999b20e commit 5b4d966
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 129 deletions.
8 changes: 4 additions & 4 deletions src/components/Forms/Route/RouteRules/RuleForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export default class RuleForm extends React.Component {
const { gateway } = this.props
const service = get(data, 'http.paths[0].backend.serviceName')
const _host = gateway.isHostName
? gateway.loadBalancerIngress
: `${service}.${namespace}.${gateway.loadBalancerIngress}.nip.io`
? gateway.defaultIngress
: `${service}.${namespace}.${gateway.defaultIngress}.nip.io`
const namespace = gateway.namespace

return host === _host ? 'auto' : 'specify'
Expand Down Expand Up @@ -164,8 +164,8 @@ export default class RuleForm extends React.Component {
...data,
protocol: 'http',
host: gateway.isHostName
? gateway.loadBalancerIngress
: `${service}.${namespace}.${gateway.loadBalancerIngress}.nip.io`,
? gateway.defaultIngress
: `${service}.${namespace}.${gateway.defaultIngress}.nip.io`,
})
} else {
onSave(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
display: block;
margin-left: 111px;
color: $text-color;

@include break-all;
white-space: pre-wrap;
}
}
}
8 changes: 1 addition & 7 deletions src/pages/clusters/containers/Workload/Routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,7 @@ export default class Routers extends React.Component {
dataIndex: 'loadBalancerIngress',
isHideable: true,
width: '22%',
render: loadBalancerIngress => (
<div>
{loadBalancerIngress.map((item, index) => (
<p key={index}>{item.ip || item.hostname}</p>
))}
</div>
),
render: loadBalancerIngress => loadBalancerIngress.join('; '),
},
{
title: t('Project'),
Expand Down
26 changes: 2 additions & 24 deletions src/pages/clusters/containers/Workload/Services/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Avatar, Text } from 'components/Base'
import Banner from 'components/Cards/Banner'
import { withClusterList, ListPage } from 'components/HOCs/withList'
import ResourceTable from 'clusters/components/ResourceTable'
import ServiceAccess from 'projects/components/ServiceAccess'

import { getLocalTime, getDisplayName } from 'utils'
import { ICON_TYPES, SERVICE_TYPES } from 'utils/constants'
Expand Down Expand Up @@ -162,30 +163,7 @@ export default class Services extends React.Component {
dataIndex: 'specType',
isHideable: true,
width: '20%',
render: (type, record) => {
if (type === 'ClusterIP') {
return '-'
}

if (type === 'NodePort') {
return (
<Text
description={type}
title={record.ports
.filter(port => port.nodePort)
.map(port => `${port.port}:${port.nodePort}/${port.protocol}`)
.join(';')}
/>
)
}

return (
<Text
description={type}
title={record.loadBalancerIngress || record.externalName}
/>
)
},
render: (_, record) => <ServiceAccess data={record} />,
},
{
title: t('Created Time'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class InternetAccess extends React.Component {
let ip = '-'

if (isEmpty(gateway.externalIPs)) {
ip = gateway.loadBalancerIngress
ip = gateway.loadBalancerIngresses.join(', ')
} else {
ip = gateway.externalIPs.join(', ')
}
Expand Down Expand Up @@ -199,7 +199,7 @@ class InternetAccess extends React.Component {
{gateway.type === 'NodePort' ? (
<>
<Text
title={gateway.loadBalancerIngress || '-'}
title={gateway.loadBalancerIngress.join('; ') || '-'}
description={t('Gateway Address')}
/>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ export default class Components extends Component {
return '-'
}

return gateway.ports.map(port => `${port.name}:${port.nodePort}`).join(', ')
return gateway.ports.map(port => `${port.name}:${port.nodePort}`).join('; ')
}

getExternalIP(gateway) {
let ip = '-'

if (isEmpty(gateway.externalIPs)) {
ip = gateway.loadBalancerIngress
ip = gateway.loadBalancerIngress.join('; ')
} else {
ip = gateway.externalIPs.join(', ')
ip = gateway.externalIPs.join('; ')
}

return ip || '-'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export default class Item extends React.Component {
return '-'
}

return gateway.ports.map(port => `${port.name}:${port.nodePort}`).join(', ')
return gateway.ports.map(port => `${port.name}:${port.nodePort}`).join('; ')
}

getExternalIP(gateway) {
let ip = '-'

if (isEmpty(gateway.externalIPs)) {
ip = gateway.loadBalancerIngress
ip = gateway.loadBalancerIngress.join('; ')
} else {
ip = gateway.externalIPs.join(', ')
ip = gateway.externalIPs.join('; ')
}

return ip || '-'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ export default class Ports extends Component {
</Tooltip>
</div>
</div>
{gateway.loadBalancerIngress && (
{gateway.defaultIngress && (
<a
href={`http://${gateway.loadBalancerIngress}:${
port.nodePort
}`}
href={`http://${gateway.defaultIngress}:${port.nodePort}`}
target="_blank"
>
<Button className={styles.access} noShadow>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/projects/components/Cards/Services/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default class ServiceItem extends React.Component {

const { type, clusterIP, loadBalancerIngress, externalName } = detail
const content =
type === 'Virtual IP' ? clusterIP : loadBalancerIngress || externalName
type === 'Virtual IP'
? clusterIP
: loadBalancerIngress.join(';') || externalName

return (
<div className={classnames(styles.item, className)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class RuleForm extends React.Component {

const { gateway } = this.props
const service = get(data, 'http.paths[0].backend.serviceName')
const ip = gateway.loadBalancerIngress
const ip = gateway.defaultIngress
const namespace = gateway.namespace

return host === `${service}.${namespace}.${ip}.nip.io` ? 'auto' : 'specify'
Expand Down Expand Up @@ -129,8 +129,8 @@ export default class RuleForm extends React.Component {
...data,
protocol: 'http',
host: gateway.isHostName
? gateway.loadBalancerIngress
: `${service}.${namespace}.${gateway.loadBalancerIngress}.nip.io`,
? gateway.defaultIngress
: `${service}.${namespace}.${gateway.defaultIngress}.nip.io`,
})
} else {
onOk(data)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/projects/components/Modals/CreateApp/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export default class ServiceDeployAppModal extends React.Component {
formData.ingress,
'spec.rules[0].host',
gateway.isHostName
? gateway.loadBalancerIngress
: `productpage.${namespace}.${gateway.loadBalancerIngress}.nip.io`
? gateway.defaultIngress
: `productpage.${namespace}.${gateway.defaultIngress}.nip.io`
)

this.setState({ formData })
Expand Down
50 changes: 50 additions & 0 deletions src/pages/projects/components/ServiceAccess/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of KubeSphere Console.
* Copyright (C) 2019 The KubeSphere Console Authors.
*
* KubeSphere Console is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KubeSphere Console is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

import React from 'react'

import { Text } from 'components/Base'

export default function ServiceAccess({ data }) {
if (data.specType === 'ClusterIP') {
return '-'
}

if (data.specType === 'NodePort') {
return (
<Text
description={data.specType}
title={data.ports
.filter(port => port.nodePort)
.map(port => `${port.port}:${port.nodePort}/${port.protocol}`)
.join(';')}
/>
)
}

if (data.specType === 'LoadBalancer') {
return (
<Text
description={data.specType}
title={data.loadBalancerIngress.join('; ')}
/>
)
}

return <Text description={data.specType} title={data.externalName} />
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ class InternetAccess extends React.Component {
return '-'
}

return gateway.ports.map(port => `${port.name}:${port.nodePort}`).join(', ')
return gateway.ports.map(port => `${port.name}:${port.nodePort}`).join('; ')
}

getExternalIP(gateway) {
let ip = '-'

if (isEmpty(gateway.externalIPs)) {
ip = gateway.loadBalancerIngress
ip = gateway.loadBalancerIngress.join('; ')
} else {
ip = gateway.externalIPs.join(', ')
ip = gateway.externalIPs.join('; ')
}

return ip || '-'
Expand Down Expand Up @@ -196,7 +196,7 @@ class InternetAccess extends React.Component {
{gateway.type === 'NodePort' ? (
<>
<div className={styles.item}>
<div>{gateway.loadBalancerIngress || '-'}</div>
<div>{gateway.loadBalancerIngress.join('; ') || '-'}</div>
<p>{t('Gateway Address')}</p>
</div>
<div className={styles.item}>
Expand Down
11 changes: 1 addition & 10 deletions src/pages/projects/containers/Routes/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ export default class RouteDetail extends React.Component {
return
}

const { loadBalancerIngress = [] } = detail

let ips = []
loadBalancerIngress.forEach(item => {
item.ip && ips.push(item.ip)
item.hostname && ips.push(item.hostname)
})
ips = ips.map((ip, index) => <p key={index}>{ip}</p>)

return [
{
name: t('Cluster'),
Expand All @@ -163,7 +154,7 @@ export default class RouteDetail extends React.Component {
},
{
name: t('Gateway Address'),
value: ips,
value: detail.loadBalancerIngress.join('\r\n'),
},
{
name: t('Created Time'),
Expand Down
8 changes: 1 addition & 7 deletions src/pages/projects/containers/Routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ export default class Routers extends React.Component {
dataIndex: 'loadBalancerIngress',
isHideable: true,
width: '22%',
render: loadBalancerIngress => (
<div>
{loadBalancerIngress.map((item, index) => (
<p key={index}>{item.ip || item.hostname}</p>
))}
</div>
),
render: loadBalancerIngress => loadBalancerIngress.join('; '),
},
{
title: t('Application'),
Expand Down
6 changes: 2 additions & 4 deletions src/pages/projects/containers/Services/Detail/Ports/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ export default class Ports extends Component {
</Tooltip>
</div>
</div>
{gateway.loadBalancerIngress && (
{gateway.defaultIngress && (
<a
href={`http://${gateway.loadBalancerIngress}:${
port.nodePort
}`}
href={`http://${gateway.defaultIngress}:${port.nodePort}`}
target="_blank"
>
<Button className={styles.access} noShadow>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/projects/containers/Services/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ export default class ServiceDetail extends React.Component {
if (detail.type === 'ExternalName') {
externalIP = detail.externalName
} else if (detail.specType === 'LoadBalancer') {
externalIP = detail.loadBalancerIngress
externalIP = detail.loadBalancerIngress.join('\r\n')
} else if (detail.externalIPs) {
externalIP = detail.externalIPs.join(', ')
externalIP = detail.externalIPs.join('\r\n')
}

const serviceType = get(detail, 'annotations["kubesphere.io/serviceType"]')
Expand Down
26 changes: 2 additions & 24 deletions src/pages/projects/containers/Services/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Avatar, Text } from 'components/Base'
import Banner from 'components/Cards/Banner'
import { withProjectList, ListPage } from 'components/HOCs/withList'
import Table from 'components/Tables/List'
import ServiceAccess from 'projects/components/ServiceAccess'

import { getLocalTime, getDisplayName } from 'utils'
import { ICON_TYPES, SERVICE_TYPES } from 'utils/constants'
Expand Down Expand Up @@ -173,30 +174,7 @@ export default class Services extends React.Component {
dataIndex: 'specType',
isHideable: true,
width: '20%',
render: (type, record) => {
if (type === 'ClusterIP') {
return '-'
}

if (type === 'NodePort') {
return (
<Text
description={type}
title={record.ports
.filter(port => port.nodePort)
.map(port => `${port.port}:${port.nodePort}/${port.protocol}`)
.join(';')}
/>
)
}

return (
<Text
description={type}
title={record.loadBalancerIngress || record.externalName}
/>
)
},
render: (_, record) => <ServiceAccess data={record} />,
},
{
title: t('Created Time'),
Expand Down
Loading

0 comments on commit 5b4d966

Please sign in to comment.