Repository navigation
Show what a NetworkPolicy actually does on its detail page and list column - #1745
Conversation
…olumn A policy that omits policyTypes isolates ingress (and egress when it has egress rules) — the classic default-deny is exactly that shape — but the list column showed it as "-" and the detail page and diagram showed no rules at all. One shared helper now applies Kubernetes' defaulting for all three, and the detail page says when the type was defaulted rather than declared. A peer that sets both podSelector and namespaceSelector is an AND and is now shown as one; matchExpressions no longer read as "all pods"; endPort ranges appear in the rule list.
PR Summary by QodoCorrect NetworkPolicy semantics across list, detail, and diagram
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding |
Why
The NetworkPolicy detail page and list column mis-described policies in ways that read as more permissive than reality:
podSelectorandnamespaceSelector(an AND — "these pods, in these namespaces") showed only the pod selector, so a narrow cross-namespace grant read as a broad same-namespace one.matchExpressionsrendered as "all pods" / "All pods" in the flow diagram.endPortranges were dropped from the rule list (TCP/9000for a 9000–9100 range).policyTypesshowed as isolating nothing (list:-; detail: no rules at all), when Kubernetes' defaulting makes it isolate ingress — the classic default-deny shape.What
One shared helper,
packages/k8s-ui/src/utils/network-policy.ts, now backs the list column (getNetworkPolicyTypes), the detail renderer and the flow diagram, so the three surfaces cannot disagree:effectivePolicyTypes(spec)applies Kubernetes' defaulting exactly (omitted ⇒ Ingress, plus Egress iff egress rules exist) and reports whether the type was declared. The detail page says "by default — policyTypes not set" when it wasn't.formatNetworkPolicyPortrendersPROTO/port,PROTO/start-endfor numeric ranges,PROTO/*for protocol-only entries; a range off a named port is not a range and isn't shown as one.formatKubernetesLabelSelector, somatchExpressionsread astier In (web,api)rather than "all".Scope note on
policyTypes. The API server defaultspolicyTypeson admission, so objects read from a cluster always carry it explicitly and the list/detail were already right for them. The defaulting fix matters for specs that haven't been admitted — the YAML preview/editor, GitOps desired-state views, snapshots — and it keeps the UI consistent withpkg/netpol, which applies the same rule server-side.Additive only: no
@skyhook-io/k8s-uiexport or prop removed or renamed.Testing
utils/network-policy.test.ts(defaulting, type naming, port formatting incl. invalid-range cases) andNetworkPolicyRenderer.test.tsx(each of the four shapes, the explicit-types negative, and diagram-specific assertions so a break in one surface can't hide behind the other). Full k8s-ui suite green;make tscclean.Ingressfor the default-deny; detail pages render the denied flow, the AND'ed peer (app=radarinkubernetes.io/metadata.name=radar),role Exists → tier In (web,api)in the diagram, andTCP/9000-9100+UDP/53with the10.0.0.0/8 except 10.0.1.0/24egress block. No console errors.Follow-ups (separate PRs)
pkg/netpol: a per-policy explanation primitive (enables the next item without duplicating semantics)./api/network-policies/evaluate(the Traffic view's dropped-flow panel) onpkg/netpol; its own evaluator still ignores ports, mishandlesnamespaceSelectorandipBlock.Note
Low Risk
Presentation-only changes in k8s-ui with unit tests; no enforcement or API behavior changes, and the diff corrects previously misleading policy UI.
Overview
Introduces shared
network-policyhelpers so the list column, detail renderer, and flow diagram agree on Kubernetes semantics instead of each interpreting the spec differently.effectivePolicyTypes/effectivePolicyTypeNamesapply API defaulting whenpolicyTypesis omitted (ingress-only unless egress rules exist); the detail view always shows policy types and notes "by default — policyTypes not set" when defaulted.formatNetworkPolicyPortstandardizes port badges and diagram labels, including numericendPortranges.The renderer now shows both
podSelectorandnamespaceSelectoron the same peer (AND semantics). The diagram formats selectors viaformatKubernetesLabelSelector, somatchExpressionsare not shown as "all pods". Vitest covers the helpers and renderer/diagram HTML expectations.Reviewed by Cursor Bugbot for commit af6bae0. Bugbot is set up for automated code reviews on this repo. Configure here.