Skip to content

Commit

Permalink
fix: Fix network policy rule some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
liyefox committed Jul 8, 2020
1 parent a3c3407 commit 018f0cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/pages/clusters/containers/Network/Policies/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ import { Link } from 'react-router-dom'
import { Avatar } from 'components/Base'
import Banner from 'components/Cards/Banner'
import NetworkStore from 'stores/network'
import withList, { ListPage } from 'components/HOCs/withList'
import { withClusterList, ListPage } from 'components/HOCs/withList'
import ResourceTable from 'clusters/components/ResourceTable'

import { getLocalTime, getDisplayName } from 'utils'
import { ICON_TYPES } from 'utils/constants'

@withList({
@withClusterList({
store: new NetworkStore('networkpolicies'),
name: 'Network Policy',
module: 'networkpolicies',
rowKey: 'key',
})
export default class NetworkPolicies extends React.Component {
tips = [
Expand Down Expand Up @@ -170,7 +171,7 @@ export default class NetworkPolicies extends React.Component {
<Banner {...bannerProps} tips={tips} />
<ResourceTable
{...tableProps}
rowKey={`${query.namespace}-${name}`}
rowKey="key"
itemActions={this.itemActions}
namespace={query.namespace}
columns={this.getColumns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ export default class Viewer extends React.Component {
const ports = get(direction, 'ports', [])
const rules = get(direction, `${fromto}`, [])
rules.forEach(rule => {
data.push({ namespace, specPodSelector, ports, ...rule })
data.push({
namespace,
specPodSelector,
ports,
direction: this.direction,
...rule,
})
})
})
return data
Expand Down Expand Up @@ -188,6 +194,7 @@ export default class Viewer extends React.Component {
const namespace = get(record, 'namespace', '')
const ipBlock = get(record, 'ipBlock')
const ipExpect = get(ipBlock, 'except')
const { direction } = record

const ipBlockLabel = this.renderIpBlock(ipBlock)

Expand All @@ -213,15 +220,21 @@ export default class Viewer extends React.Component {
<div>
<span>This rule allows pods in the namespace '{namespace}' </span>
{!isEmpty(podsLabels) && <span> with the label {podsLabels} </span>}
<span>to receive traffic from </span>
<span>
{direction === 'egress'
? 'to connect to '
: 'to receive traffic from '}
</span>
{!isEmpty(ipBlock) ? (
<label>
{ipExpect && 'all IPs in '} subnet '{ipBlockLabel}'{' '}
</label>
) : (
<label>
{!isEmpty(namespaceLabels) && (
<span>all pods in the namespace with the label {namespaceLabels} </span>
<span>
all pods in the namespace with the label {namespaceLabels}{' '}
</span>
)}
{!isEmpty(destPodLabels) && (
<span>
Expand Down

0 comments on commit 018f0cf

Please sign in to comment.