Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realize Egress for a Pod once its network is created #3360

Merged
merged 1 commit into from
Mar 2, 2022

Conversation

tnqn
Copy link
Member

@tnqn tnqn commented Feb 25, 2022

Previously antrea-controller included a Pod in an EgressGroup only when
its IP has been presented in K8s API. If a Pod tries to access external
right after it's up, Node IP will be used as the SNAT IP even when an
Egress applying to it has been created because its Pod IP may haven't
been reported to K8s API or antrea-controller may haven't included the
Pod in the EgressGroup.

This patch fixes it by making CNIServer notify EgressController that it
has processed CNI ADD request of a Pod, then EgressController can
reconcile the corresponding Egress immediately, instead of waiting for
the Pod to be reported to K8s API. As NetworkPolicyController relies on
that event as well, we introduce a channel implementation which supports
multiple subscribers.

Fixes #3361

Signed-off-by: Quan Tian qtian@vmware.com

@tnqn tnqn added action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes. labels Feb 25, 2022
@tnqn tnqn added this to the Antrea v1.6 release milestone Feb 25, 2022
@tnqn
Copy link
Member Author

tnqn commented Feb 25, 2022

@Dyanngg Do you remember why it's entityUpdateChannel, instead of podUpdateChannel? I don't find anywhere entity update is published. Is it reserved for future usage? Anyway I think later we could create an externalEntityUpdateChannel when necessary, instead of mixing the channel of PodUpdate. Please let me know if this change breaks anything.

@tnqn
Copy link
Member Author

tnqn commented Feb 25, 2022

/test-all

@tnqn
Copy link
Member Author

tnqn commented Feb 28, 2022

/test-all

@tnqn
Copy link
Member Author

tnqn commented Feb 28, 2022

/test-ipv6-all
/test-ipv6-only-all

@tnqn
Copy link
Member Author

tnqn commented Feb 28, 2022

/test-ipv6-e2e
/test-ipv6-only-e2e

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2022

Codecov Report

Merging #3360 (b43ad53) into main (26c039c) will decrease coverage by 7.24%.
The diff coverage is 34.69%.

❗ Current head b43ad53 differs from pull request most recent head c24e914. Consider uploading reports for the commit c24e914 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3360      +/-   ##
==========================================
- Coverage   60.85%   53.61%   -7.25%     
==========================================
  Files         268      240      -28     
  Lines       26723    34179    +7456     
==========================================
+ Hits        16263    18324    +2061     
- Misses       8649    14078    +5429     
+ Partials     1811     1777      -34     
Flag Coverage Δ
e2e-tests 53.61% <34.69%> (?)
kind-e2e-tests ?
unit-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/agent/apiserver/handlers/ovsflows/handler.go 13.48% <ø> (-61.52%) ⬇️
pkg/agent/openflow/network_policy.go 64.38% <0.00%> (-18.87%) ⬇️
pkg/agent/types/networkpolicy.go 81.08% <ø> (-2.26%) ⬇️
pkg/controller/egress/controller.go 0.00% <0.00%> (-88.45%) ⬇️
pkg/controller/ipam/validate.go 0.00% <0.00%> (-80.00%) ⬇️
pkg/flowaggregator/flowaggregator.go 63.57% <0.00%> (-5.54%) ⬇️
pkg/agent/agent_linux.go 5.47% <16.66%> (+1.84%) ⬆️
pkg/util/channel/channel.go 80.64% <80.64%> (ø)
pkg/agent/cniserver/pod_configuration.go 42.47% <100.00%> (-11.22%) ⬇️
pkg/agent/cniserver/server.go 40.58% <100.00%> (-25.08%) ⬇️
... and 274 more

@tnqn
Copy link
Member Author

tnqn commented Feb 28, 2022

/test-all

@tnqn tnqn requested a review from jianjuns February 28, 2022 16:01
Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

In commit message:

Previously antrea-controller only included a Pod in an EgressGroup only

Remove one "only".

type eventHandler func(string)

type Subscriber interface {
// Subscribe subscribes an eventHandler which will be called when there is an event sent to the channel.
Copy link
Contributor

Choose a reason for hiding this comment

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

subscribes -> registers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove "there is"

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// Channel is different from the Go channel which dispatches every event to only single consumer regardless of the
// number of consumers. Instead, it dispatches every event to all consumers by calling the eventHandlers they have
// registered.
type Channel struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use a different name to distinguish from Golang channel? Like SubscriptionChannel.

Copy link
Member Author

Choose a reason for hiding this comment

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

does SubscribableChannel make sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me.

Previously antrea-controller included a Pod in an EgressGroup only when
its IP has been presented in K8s API. If a Pod tries to access external
right after it's up, Node IP will be used as the SNAT IP even when an
Egress applying to it has been created because its Pod IP may haven't
been reported to K8s API or antrea-controller may haven't included the
Pod in the EgressGroup.

This patch fixes it by making CNIServer notify EgressController that it
has processed CNI ADD request of a Pod, then EgressController can
reconcile the corresponding Egress immediately, instead of waiting for
the Pod to be reported to K8s API. As NetworkPolicyController relies on
that event as well, we introduce a channel implementation which supports
multiple subscribers.

Fixes antrea-io#3361

Signed-off-by: Quan Tian <qtian@vmware.com>
@tnqn
Copy link
Member Author

tnqn commented Mar 1, 2022

/test-all

Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

LGTM

@tnqn tnqn merged commit 24f85ce into antrea-io:main Mar 2, 2022
@tnqn tnqn deleted the egress-realization branch March 2, 2022 02:52
GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Mar 10, 2022
Previously antrea-controller included a Pod in an EgressGroup only when
its IP has been presented in K8s API. If a Pod tries to access external
right after it's up, Node IP will be used as the SNAT IP even when an
Egress applying to it has been created because its Pod IP may haven't
been reported to K8s API or antrea-controller may haven't included the
Pod in the EgressGroup.

This patch fixes it by making CNIServer notify EgressController that it
has processed CNI ADD request of a Pod, then EgressController can
reconcile the corresponding Egress immediately, instead of waiting for
the Pod to be reported to K8s API. As NetworkPolicyController relies on
that event as well, we introduce a channel implementation which supports
multiple subscribers.

Fixes antrea-io#3361

Signed-off-by: Quan Tian <qtian@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial egress connections from Pods go out with node IP rather than Egress IP assigned
3 participants