Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Lens
Commits
f6193718
Unverified
Commit
f6193718
authored
3 years ago
by
Sebastian Malton
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Fix crash on NetworkPolicy when matchLabels is missing (#4500)
parent
637f26ae
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/renderer/components/+network-policies/__tests__/network-policy-details.test.tsx
+15
-0
...etwork-policies/__tests__/network-policy-details.test.tsx
src/renderer/components/+network-policies/network-policy-details.module.css
+9
-0
...nents/+network-policies/network-policy-details.module.css
src/renderer/components/+network-policies/network-policy-details.tsx
+48
-9
...r/components/+network-policies/network-policy-details.tsx
with
72 additions
and
9 deletions
+72
-9
src/renderer/components/+network-policies/__tests__/network-policy-details.test.tsx
+
15
-
0
View file @
f6193718
...
...
@@ -53,4 +53,19 @@ describe("NetworkPolicyDetails", () => {
expect
(
await
findByTestId
(
container
,
"
egress-0
"
)).
toBeInstanceOf
(
HTMLElement
);
expect
(
await
findByText
(
container
,
"
foo: bar
"
)).
toBeInstanceOf
(
HTMLElement
);
});
it
(
"
should not crash if egress nodeSelector doesn't have matchLabels
"
,
async
()
=>
{
const
spec
:
NetworkPolicySpec
=
{
egress
:
[{
to
:
[{
namespaceSelector
:
{},
}],
}],
podSelector
:
{},
};
const
policy
=
new
NetworkPolicy
({
metadata
:
{}
as
any
,
spec
}
as
any
);
const
{
container
}
=
render
(<
NetworkPolicyDetails
object
=
{
policy
}
/>);
expect
(
container
).
toBeInstanceOf
(
HTMLElement
);
});
});
This diff is collapsed.
Click to expand it.
src/renderer/components/+network-policies/network-policy-details.module.css
+
9
-
0
View file @
f6193718
...
...
@@ -29,4 +29,13 @@
padding-bottom
:
16px
;
}
}
ul
.policySelectorList
{
list-style
:
disc
;
}
.policySelectorList
ul
{
list-style
:
circle
;
list-style-position
:
inside
;
}
}
This diff is collapsed.
Click to expand it.
src/renderer/components/+network-policies/network-policy-details.tsx
+
48
-
9
View file @
f6193718
...
...
@@ -23,13 +23,15 @@ import styles from "./network-policy-details.module.css";
import
React
from
"
react
"
;
import
{
DrawerItem
,
DrawerTitle
}
from
"
../drawer
"
;
import
{
IPolicyIpBlock
,
IPolicySelector
,
NetworkPolicy
,
NetworkPolicyPeer
,
NetworkPolicyPort
}
from
"
../../../common/k8s-api/endpoints/network-policy.api
"
;
import
{
IPolicyIpBlock
,
NetworkPolicy
,
NetworkPolicyPeer
,
NetworkPolicyPort
}
from
"
../../../common/k8s-api/endpoints/network-policy.api
"
;
import
{
Badge
}
from
"
../badge
"
;
import
{
SubTitle
}
from
"
../layout/sub-title
"
;
import
{
observer
}
from
"
mobx-react
"
;
import
type
{
KubeObjectDetailsProps
}
from
"
../kube-object-details
"
;
import
{
KubeObjectMeta
}
from
"
../kube-object-meta
"
;
import
logger
from
"
../../../common/logger
"
;
import
type
{
LabelMatchExpression
,
LabelSelector
}
from
"
../../../common/k8s-api/kube-object
"
;
import
{
isEmpty
}
from
"
lodash
"
;
interface
Props
extends
KubeObjectDetailsProps
<
NetworkPolicy
>
{
}
...
...
@@ -60,20 +62,57 @@ export class NetworkPolicyDetails extends React.Component<Props> {
);
}
renderIPolicySelector
(
name
:
string
,
selector
:
IPolicySelector
|
undefined
)
{
renderMatchLabels
(
matchLabels
:
Record
<
string
,
string
|
undefined
>
|
undefined
)
{
if
(
!
matchLabels
)
{
return
null
;
}
return
Object
.
entries
(
matchLabels
)
.
map
(([
key
,
value
])
=>
<
li
key
=
{
key
}
>
{
key
}
:
{
value
}
</
li
>);
}
renderMatchExpressions
(
matchExpressions
:
LabelMatchExpression
[]
|
undefined
)
{
if
(
!
matchExpressions
)
{
return
null
;
}
return
matchExpressions
.
map
(
expr
=>
{
switch
(
expr
.
operator
)
{
case
"
DoesNotExist
"
:
case
"
Exists
"
:
return
<
li
key
=
{
expr
.
key
}
>
{
expr
.
key
}
(
{
expr
.
operator
}
)
</
li
>;
case
"
In
"
:
case
"
NotIn
"
:
return
(
<
li
key
=
{
expr
.
key
}
>
{
expr
.
key
}
(
{
expr
.
operator
}
)
<
ul
>
{
expr
.
values
.
map
((
value
,
index
)
=>
<
li
key
=
{
index
}
>
{
value
}
</
li
>)
}
</
ul
>
</
li
>
);
}
});
}
renderIPolicySelector
(
name
:
string
,
selector
:
LabelSelector
|
undefined
)
{
if
(
!
selector
)
{
return
null
;
}
const
{
matchLabels
,
matchExpressions
}
=
selector
;
return
(
<
DrawerItem
name
=
{
name
}
>
{
Object
.
entries
(
selector
.
matchLabels
)
.
map
(
data
=>
data
.
join
(
"
:
"
))
.
join
(
"
,
"
)
||
"
(empty)
"
}
<
ul
className
=
{
styles
.
policySelectorList
}
>
{
this
.
renderMatchLabels
(
matchLabels
)
}
{
this
.
renderMatchExpressions
(
matchExpressions
)
}
{
(
isEmpty
(
matchLabels
)
&&
isEmpty
(
matchExpressions
))
&&
(
<
li
>
(empty)
</
li
>
)
}
</
ul
>
</
DrawerItem
>
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help