Skip to content

Fix inverted ipBlocksUpdated() causing dropped Group IPBlocks updates - #8209

Open
Archong-Liu wants to merge 1 commit into
antrea-io:mainfrom
Archong-Liu:fix/group-ipblocks-updated-inverted
Open

Fix inverted ipBlocksUpdated() causing dropped Group IPBlocks updates#8209
Archong-Liu wants to merge 1 commit into
antrea-io:mainfrom
Archong-Liu:fix/group-ipblocks-updated-inverted

Conversation

@Archong-Liu

@Archong-Liu Archong-Liu commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

updateGroup's ipBlocksUpdated() closure returned oldIPBs.Equal(newIPBs) instead of the negation, unlike the identical helper in clustergroup.go, which correctly returns !oldIPBs.Equal(newIPBs).

Because updateGroup skips internalGroupStore.Update() and enqueueInternalGroup() when !ipBlocksUpdated() && !svcRefUpdated() && !selectorUpdated() && !childGroupsUpdated() is true, the inverted boolean made an IPBlocks-only change on a Group CR look like "no change" whenever nothing else in the spec changed: the internal Group was left stale and never re-enqueued, so the updated IPBlocks were silently dropped instead of being propagated to policy enforcement.

Added a g-update-ip-block-only-change case to the existing TestUpdateGroup table instead of a separate top-level test function. It needs its own starting Group already in IPBlocks mode on both sides, rather than reusing TestUpdateGroup's selector-based baseline: processGroup returns early on IPBlocks and never sets Selector, so transitioning from a selector-based Group to an IPBlocks one would also flip selectorUpdated() and mask whether ipBlocksUpdated() itself is correct. Verified the new case fails against the pre-fix code and passes after the fix, while the other six existing cases in the table stay green either way (none of them actually isolate this regression).

Test plan

  • go test ./pkg/controller/networkpolicy/... passes
  • New case fails on pre-fix code, passes after the fix
  • go vet / gofmt / golangci-lint (linux + windows) clean

Copilot AI review requested due to automatic review settings July 23, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Archong-Liu

Copy link
Copy Markdown
Contributor Author

@antoninbas @luolanzone @jianjuns its a one line logical fix & test, would love some quick feedback, Thanks.

jianjuns
jianjuns previously approved these changes Jul 27, 2026
// TestUpdateGroupIPBlocksOnlyChange guards against a regression where ipBlocksUpdated() returned
// whether the old and new IPBlocks were equal instead of whether they differed, causing updateGroup
// to mistake an IPBlocks-only change for no change and skip updating the internal Group store.
func TestUpdateGroupIPBlocksOnlyChange(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot we add this case to TestUpdateGroup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure. I originally thought that a Group couldn't have both a NamespaceSelector and IPBlocks set at the same time so was feeling unsure to consolidate them.

But I think the trade off is fair to make the test code cleaner.

updateGroup's ipBlocksUpdated() closure returned oldIPBs.Equal(newIPBs)
instead of the negation, unlike the identical helper in
clustergroup.go, which correctly returns !oldIPBs.Equal(newIPBs).

Because updateGroup skips internalGroupStore.Update() and
enqueueInternalGroup() when
"!ipBlocksUpdated() && !svcRefUpdated() && !selectorUpdated() && !childGroupsUpdated()"
is true, the inverted boolean made an IPBlocks-only change on a Group
CR look like "no change" whenever nothing else in the spec changed:
the internal Group was left stale and never re-enqueued, so the
updated IPBlocks were silently dropped instead of being propagated to
policy enforcement.

Add a "g-update-ip-block-only-change" case to TestUpdateGroup, which
updates only IPBlocks and asserts the internal Group reflects the
change. It needs its own starting Group already in IPBlocks mode on
both sides, since processGroup returns early on IPBlocks and never
sets Selector, so reusing TestUpdateGroup's existing selector-based
baseline would also flip selectorUpdated() and mask the regression.
Verified it fails against the pre-fix code and passes after the fix.
Full networkpolicy package tests pass.

Signed-off-by: ArchongLiu <aaarrchong@gmail.com>
@Archong-Liu
Archong-Liu force-pushed the fix/group-ipblocks-updated-inverted branch from cad7969 to a78d0a8 Compare August 1, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants