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

Support more traffic modes for Multi-cluster Gateway #4407

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

luolanzone
Copy link
Contributor

@luolanzone luolanzone commented Nov 23, 2022

In order to support multi-cluster traffic when the member cluster is deployed with networkPolicyOnly, noEncap and hybrid mode, antrea-agent will be responsible for the following:

  1. Create tunnel interface antrea-tun0 for cross-cluster traffic
  2. Watch all Pods on the Gateway and set up one rule per Pod in L3Fowarding table as long as the Pod is running on a regular Node instead of the Gateway.
  3. Update container interface's MTU with the tunnel header size deducted.

For #4383
The change is based on PR #4508, please review the top commit, thanks.

Signed-off-by: Lan Luo luola@vmware.com

@luolanzone luolanzone added the area/multi-cluster Issues or PRs related to multi cluster. label Nov 23, 2022
@codecov
Copy link

codecov bot commented Nov 23, 2022

Codecov Report

Merging #4407 (a26a3b8) into main (be49b4a) will decrease coverage by 1.81%.
The diff coverage is 67.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4407      +/-   ##
==========================================
- Coverage   69.83%   68.03%   -1.81%     
==========================================
  Files         401      404       +3     
  Lines       59529    60278     +749     
==========================================
- Hits        41575    41013     -562     
- Misses      15142    16453    +1311     
  Partials     2812     2812              
Flag Coverage Δ *Carryforward flag
e2e-tests 38.40% <ø> (+0.02%) ⬆️ Carriedforward from 8641721
integration-tests 34.29% <5.66%> (-0.16%) ⬇️
kind-e2e-tests 38.17% <10.10%> (-9.11%) ⬇️
unit-tests 59.95% <66.36%> (+0.19%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Impacted Files Coverage Δ
cmd/antrea-agent/agent.go 0.00% <0.00%> (ø)
...agent/cniserver/interface_configuration_windows.go 64.56% <0.00%> (-0.40%) ⬇️
pkg/agent/openflow/multicluster.go 85.50% <0.00%> (-9.66%) ⬇️
pkg/agent/cniserver/server.go 80.30% <18.18%> (-2.00%) ⬇️
pkg/agent/openflow/client.go 87.00% <36.84%> (-1.67%) ⬇️
...s/multicluster/leader/resourceexport_controller.go 78.07% <50.00%> (-1.61%) ⬇️
pkg/agent/multicluster/mc_route_controller.go 60.00% <71.87%> (+3.87%) ⬆️
pkg/agent/multicluster/pod_route_controller.go 72.97% <72.97%> (ø)
pkg/agent/agent.go 56.32% <85.71%> (-0.56%) ⬇️
pkg/agent/proxy/proxier.go 68.17% <85.71%> (-7.91%) ⬇️
... and 82 more

@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 2 times, most recently from ac9547d to 810bdd6 Compare November 25, 2022 07:40
pkg/agent/cniserver/interface_configuration_windows.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/server.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/pod_configuration.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 3 times, most recently from d7d6c06 to 08eae28 Compare November 30, 2022 00:53
@luolanzone
Copy link
Contributor Author

Will improve the unit test after cniserver package's UT #4348 is merged

@jianjuns
Copy link
Contributor

jianjuns commented Dec 8, 2022

In commit message:

responsible to do the following things -> responsible for the following

in a general Node -> on a regular Node

to minus the tunnel overhead -> with the tunnel header size deducted.

cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
cmd/antrea-agent/options.go Outdated Show resolved Hide resolved
cmd/antrea-agent/options.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/interface_configuration_windows.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/interface_configuration_windows.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/policy_only_route_controller.go Outdated Show resolved Hide resolved
@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 3 times, most recently from 21ebeda to 234b02e Compare December 12, 2022 09:07
@luolanzone luolanzone changed the title Multi-cluster support with networkPolicyOnly mode Multi-cluster support with more modes Dec 12, 2022
cmd/antrea-agent/options.go Outdated Show resolved Hide resolved
cmd/antrea-agent/options.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/server.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/server.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/server.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/server.go Outdated Show resolved Hide resolved
@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 2 times, most recently from d3e1729 to 6e38b7e Compare December 20, 2022 05:12
@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 2 times, most recently from ed50fad to c0916d9 Compare January 4, 2023 03:14
@jianjuns
Copy link
Contributor

jianjuns commented Jan 5, 2023

@luolanzone : my last commit changed the validation logic to ignore Multi-cluster options if the Multicluster feature gate is disabled, to be consistent with other features. You need to rebase and change the validation and agent init code too.

@luolanzone
Copy link
Contributor Author

@jianjuns sure, I will re-base first, thanks for the reminder.

cmd/antrea-agent/options.go Show resolved Hide resolved
cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
cmd/antrea-agent/agent.go Show resolved Hide resolved
cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
pkg/agent/agent.go Outdated Show resolved Hide resolved
pkg/agent/agent.go Outdated Show resolved Hide resolved
pkg/agent/agent.go Outdated Show resolved Hide resolved
cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
pkg/agent/cniserver/pod_configuration.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
@luolanzone
Copy link
Contributor Author

/test-multicluster-e2e

cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
mcClient,
gwInformer,
ciImportInformer,
mcInformerFactoryWithOption,
Copy link
Member

Choose a reason for hiding this comment

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

Why change it? I think the previous code that injects gwInformer and ciImportInformer explicitly is better:

  • It's clear the controller has dependencies on Gateway and ClusterInfoImport.
  • It follows the principle of least privilege.
  • The gatewayInformer can be shared with mcPodRouteController.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was feeling the parameters are too long, and trying to reduce the number. Added them back.

ofClient,
ovsBridgeClient,
ifaceStore,
nodeConfig,
mcNamespace,
o.config.Multicluster.Namespace,
Copy link
Member

Choose a reason for hiding this comment

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

why it still needs to pass the namespace when the lister only contains objects in this namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
cmd/antrea-agent/agent.go Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/openflow/client.go Outdated Show resolved Hide resolved
pkg/agent/openflow/multicluster.go Show resolved Hide resolved
@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 2 times, most recently from 1c2a591 to f215a36 Compare March 15, 2023 06:53
cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
}

if ciImp.Namespace != c.namespace {
klog.ErrorS(errors.New("received unexpected object"), "enqueueClusterInfoImport can't process event", "obj", obj)
Copy link
Member

Choose a reason for hiding this comment

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

not resolved


podIP := pod.Status.PodIP
podName := types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}
cachedPodIP, exists := c.getPodNameIPCache(podName)
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need this cache. The Pod update event has the old Pod information. The old Pod IP is already known. A single enqueuePod callback is not suitable here.
For add and delete event, the handler should just enqueue the PodIP if it's not empty and not HostNetwork.
For update event, the handler should check if PodIP or HostIP changes. If yes, it should enqueue old PodIP and new PodIP, or just new PodIP if it doesn't change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the only usage seems to check if flows are installed for any Pod to call UninstallMulticlusterPodFlows() in syncGateway(). Maybe that is not necessary, and we can instead optimize a little to first check if the flow cache is empty or not in UninstallMulticlusterPodFlows() or deleteAllFlows.

Copy link
Member

Choose a reason for hiding this comment

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

deleteFlows called by UninstallMulticlusterPodFlows already has this optimization (do nothing if cache is empty)

pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved
Comment on lines 489 to 490
delAllFlows = append(delAllFlows, delFlows...)
cache.Delete(key)
Copy link
Member

Choose a reason for hiding this comment

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

it should be done after the operation succeeds only, otherwise the cache will be inconsistent if it fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refined

Comment on lines 195 to 197
// This generates the flow to forward cross-cluster request packets based
// on Pod IP.
return L3ForwardingTable.ofTable.BuildFlow(priorityNormal).
Copy link
Member

Choose a reason for hiding this comment

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

I was asking why it must use another rule to process this packet instead of the existing rule installed for in-cluster traffic. I now got it's because the VNI. I guess this should still use higher priority, otherwise packets may hit the other rule which doesn't encapsulate packet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, updated it to priorityHigh

pkg/agent/multicluster/pod_route_controller.go Outdated Show resolved Hide resolved

podIP := pod.Status.PodIP
podName := types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}
cachedPodIP, exists := c.getPodNameIPCache(podName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the only usage seems to check if flows are installed for any Pod to call UninstallMulticlusterPodFlows() in syncGateway(). Maybe that is not necessary, and we can instead optimize a little to first check if the flow cache is empty or not in UninstallMulticlusterPodFlows() or deleteAllFlows.

podIP := pod.Status.PodIP
podName := types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}
cachedPodIP, exists := c.getPodNameIPCache(podName)
if !exists && (podIP == "" || pod.Spec.HostNetwork) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As Quan said you should pass both old and new Pod to this func, and check both (exists && !HostNetwork && podIP != "" && nodeIP != ""), and something like:

  • !isOldValid && !newValid: return
  • !isOldValid: Add(newPodIP)
  • !isNewValid: Add(oldPodIP)
  • if oldPodIP != newPodIP: Add(newPodIP) Add(newPodIP)
  • if oldNodeIP != newNodeIP: Add(newPodIP)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@luolanzone
Copy link
Contributor Author

/test-multicluster-e2e

@luolanzone luolanzone force-pushed the mc-policyonly-routes branch 2 times, most recently from 4e14b49 to ccf17e0 Compare March 16, 2023 03:51

podIP := pod.Status.PodIP
podName := types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}
cachedPodIP, exists := c.getPodNameIPCache(podName)
Copy link
Member

Choose a reason for hiding this comment

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

deleteFlows called by UninstallMulticlusterPodFlows already has this optimization (do nothing if cache is empty)

Comment on lines 61 to 69
mcClient mcclientset.Interface
ovsBridgeClient ovsconfig.OVSBridgeClient
ofClient openflow.Client
interfaceStore interfacestore.InterfaceStore
nodeConfig *config.NodeConfig
podQueue workqueue.RateLimitingInterface
gwQueue workqueue.RateLimitingInterface
podInformer cache.SharedIndexInformer
podLister corelisters.PodLister
gwInformer cache.SharedIndexInformer
gwLister mclisters.GatewayLister
// podWorkersStarted is a boolean which tracks if the Pod flow controller has been started.
podWorkersStarted bool
podWorkersStartedMutex sync.RWMutex
podWorkerStopCh chan struct{}
Copy link
Member

Choose a reason for hiding this comment

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

There are a few attributes never used, please clean them up and remove from the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, thanks.

@luolanzone
Copy link
Contributor Author

/test-multicluster-e2e

// traffic will not go through tunnels in those modes.
type MCPodRouteController struct {
k8sClient kubernetes.Interface
mcClient mcclientset.Interface
Copy link
Member

Choose a reason for hiding this comment

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

this is not used either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@tnqn
Copy link
Member

tnqn commented Mar 16, 2023

/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

In order to support multi-cluster traffic when the member cluster is
deployed with networkPolicyOnly, noEcap or hybrid mode, antrea-agent
will be responsible for the following things:

1. Create tunnel interface `antrea-tun0` for cross-cluster traffic
2. Watch all Pods on the Gateway and set up one rule per Pod in L3Fowarding
table as long as the Pod is running on a regular Node instead of the Gateway.
3. Update container interface's MTU with the tunnel header size deducted.

Signed-off-by: Lan Luo <luola@vmware.com>
@luolanzone
Copy link
Contributor Author

/test-all
/test-multicluster-e2e

Copy link
Member

@tnqn tnqn 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 0391f4d into antrea-io:main Mar 17, 2023
jainpulkit22 pushed a commit to urharshitha/antrea that referenced this pull request Apr 28, 2023
In order to support multi-cluster traffic when the member cluster is
deployed with networkPolicyOnly, noEcap or hybrid mode, antrea-agent
will be responsible for the following things:

1. Create tunnel interface `antrea-tun0` for cross-cluster traffic
2. Watch all Pods on the Gateway and set up one rule per Pod in L3Fowarding
table as long as the Pod is running on a regular Node instead of the Gateway.
3. Update container interface's MTU with the tunnel header size deducted.

Signed-off-by: Lan Luo <luola@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/multi-cluster Issues or PRs related to multi cluster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants