Skip to content

Commit

Permalink
Add packetcapture feature (#5443)
Browse files Browse the repository at this point in the history
Introduced a new CRD called PacketCapture, which allow users
to configure capture options on target traffic. If a file server
is specified, the result pcap file will be uploaded. The pcap
file can be inspected by tools like wireshark or tcpdump.

Signed-off-by: Hang Yan <yhang@vmware.com>
Co-authored-by: Lan <luola@vmware.com>
Co-authored-by: Antonin Bas <antonin.bas@gmail.com>
Co-authored-by: Quan Tian <quan.tian@broadcom.com>
  • Loading branch information
4 people committed Nov 8, 2024
1 parent 615cecb commit 303fa7f
Show file tree
Hide file tree
Showing 24 changed files with 2,846 additions and 17 deletions.
5 changes: 4 additions & 1 deletion build/charts/antrea/conf/antrea-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ featureGates:
# be enabled, otherwise this flag will not take effect.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "CleanupStaleUDPSvcConntrack" "default" true) }}

# Enable traceflow which provides packet tracing feature to diagnose network issue.
# Enable Traceflow which provides packet tracing feature to diagnose network issue.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "Traceflow" "default" true) }}

# Enable PacketCapture feature which supports capturing packets to diagnose network issues.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "PacketCapture" "default" false) }}

# Enable NodePortLocal feature to make the Pods reachable externally through NodePort
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "NodePortLocal" "default" true) }}

Expand Down
15 changes: 15 additions & 0 deletions build/charts/antrea/templates/agent/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ rules:
- patch
- create
- delete
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures
verbs:
- get
- watch
- list
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures/status
verbs:
- update
- apiGroups:
- crd.antrea.io
resources:
Expand Down Expand Up @@ -241,6 +255,7 @@ rules:
- secrets
resourceNames:
- antrea-bgp-passwords
- antrea-packetcapture-fileserver-auth
verbs:
- get
- list
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3967,9 +3967,12 @@ data:
# be enabled, otherwise this flag will not take effect.
# CleanupStaleUDPSvcConntrack: true
# Enable traceflow which provides packet tracing feature to diagnose network issue.
# Enable Traceflow which provides packet tracing feature to diagnose network issue.
# Traceflow: true
# Enable PacketCapture feature which supports capturing packets to diagnose network issues.
# PacketCapture: false
# Enable NodePortLocal feature to make the Pods reachable externally through NodePort
# NodePortLocal: true
Expand Down Expand Up @@ -4672,6 +4675,20 @@ rules:
- patch
- create
- delete
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures
verbs:
- get
- watch
- list
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures/status
verbs:
- update
- apiGroups:
- crd.antrea.io
resources:
Expand Down Expand Up @@ -4753,6 +4770,7 @@ rules:
- secrets
resourceNames:
- antrea-bgp-passwords
- antrea-packetcapture-fileserver-auth
verbs:
- get
- list
Expand Down Expand Up @@ -5365,7 +5383,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 4325a243ab510df539883b6384a30cf8b04ff862796444a6c5c10999159479c5
checksum/config: e2d1d8af083c88667ac4c22c87dea63e595b2f4f770190c32afb00c480440fe3
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5603,7 +5621,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 4325a243ab510df539883b6384a30cf8b04ff862796444a6c5c10999159479c5
checksum/config: e2d1d8af083c88667ac4c22c87dea63e595b2f4f770190c32afb00c480440fe3
labels:
app: antrea
component: antrea-controller
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3967,9 +3967,12 @@ data:
# be enabled, otherwise this flag will not take effect.
# CleanupStaleUDPSvcConntrack: true
# Enable traceflow which provides packet tracing feature to diagnose network issue.
# Enable Traceflow which provides packet tracing feature to diagnose network issue.
# Traceflow: true
# Enable PacketCapture feature which supports capturing packets to diagnose network issues.
# PacketCapture: false
# Enable NodePortLocal feature to make the Pods reachable externally through NodePort
# NodePortLocal: true
Expand Down Expand Up @@ -4672,6 +4675,20 @@ rules:
- patch
- create
- delete
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures
verbs:
- get
- watch
- list
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures/status
verbs:
- update
- apiGroups:
- crd.antrea.io
resources:
Expand Down Expand Up @@ -4753,6 +4770,7 @@ rules:
- secrets
resourceNames:
- antrea-bgp-passwords
- antrea-packetcapture-fileserver-auth
verbs:
- get
- list
Expand Down Expand Up @@ -5365,7 +5383,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 4325a243ab510df539883b6384a30cf8b04ff862796444a6c5c10999159479c5
checksum/config: e2d1d8af083c88667ac4c22c87dea63e595b2f4f770190c32afb00c480440fe3
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5604,7 +5622,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 4325a243ab510df539883b6384a30cf8b04ff862796444a6c5c10999159479c5
checksum/config: e2d1d8af083c88667ac4c22c87dea63e595b2f4f770190c32afb00c480440fe3
labels:
app: antrea
component: antrea-controller
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3967,9 +3967,12 @@ data:
# be enabled, otherwise this flag will not take effect.
# CleanupStaleUDPSvcConntrack: true
# Enable traceflow which provides packet tracing feature to diagnose network issue.
# Enable Traceflow which provides packet tracing feature to diagnose network issue.
# Traceflow: true
# Enable PacketCapture feature which supports capturing packets to diagnose network issues.
# PacketCapture: false
# Enable NodePortLocal feature to make the Pods reachable externally through NodePort
# NodePortLocal: true
Expand Down Expand Up @@ -4672,6 +4675,20 @@ rules:
- patch
- create
- delete
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures
verbs:
- get
- watch
- list
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures/status
verbs:
- update
- apiGroups:
- crd.antrea.io
resources:
Expand Down Expand Up @@ -4753,6 +4770,7 @@ rules:
- secrets
resourceNames:
- antrea-bgp-passwords
- antrea-packetcapture-fileserver-auth
verbs:
- get
- list
Expand Down Expand Up @@ -5365,7 +5383,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: f5cf00de39a27790a7e158a3eca79123de415b3b09d389ac984b74027bbfaade
checksum/config: 7e42a403d388e2ed556d9b41f4af83917eadd0863d4e2bef67353f5adb2ef6c3
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5601,7 +5619,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: f5cf00de39a27790a7e158a3eca79123de415b3b09d389ac984b74027bbfaade
checksum/config: 7e42a403d388e2ed556d9b41f4af83917eadd0863d4e2bef67353f5adb2ef6c3
labels:
app: antrea
component: antrea-controller
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3980,9 +3980,12 @@ data:
# be enabled, otherwise this flag will not take effect.
# CleanupStaleUDPSvcConntrack: true
# Enable traceflow which provides packet tracing feature to diagnose network issue.
# Enable Traceflow which provides packet tracing feature to diagnose network issue.
# Traceflow: true
# Enable PacketCapture feature which supports capturing packets to diagnose network issues.
# PacketCapture: false
# Enable NodePortLocal feature to make the Pods reachable externally through NodePort
# NodePortLocal: true
Expand Down Expand Up @@ -4685,6 +4688,20 @@ rules:
- patch
- create
- delete
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures
verbs:
- get
- watch
- list
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures/status
verbs:
- update
- apiGroups:
- crd.antrea.io
resources:
Expand Down Expand Up @@ -4766,6 +4783,7 @@ rules:
- secrets
resourceNames:
- antrea-bgp-passwords
- antrea-packetcapture-fileserver-auth
verbs:
- get
- list
Expand Down Expand Up @@ -5378,7 +5396,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 9e94f199d125877d889ba73e053c95b342e89323d0423cde074ae074df379494
checksum/config: 7d8b0a065c3db85e34e127fdf38b820b32712657900e3f8fe2703d4310c40632
checksum/ipsec-secret: d0eb9c52d0cd4311b6d252a951126bf9bea27ec05590bed8a394f0f792dcb2a4
labels:
app: antrea
Expand Down Expand Up @@ -5660,7 +5678,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 9e94f199d125877d889ba73e053c95b342e89323d0423cde074ae074df379494
checksum/config: 7d8b0a065c3db85e34e127fdf38b820b32712657900e3f8fe2703d4310c40632
labels:
app: antrea
component: antrea-controller
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3967,9 +3967,12 @@ data:
# be enabled, otherwise this flag will not take effect.
# CleanupStaleUDPSvcConntrack: true
# Enable traceflow which provides packet tracing feature to diagnose network issue.
# Enable Traceflow which provides packet tracing feature to diagnose network issue.
# Traceflow: true
# Enable PacketCapture feature which supports capturing packets to diagnose network issues.
# PacketCapture: false
# Enable NodePortLocal feature to make the Pods reachable externally through NodePort
# NodePortLocal: true
Expand Down Expand Up @@ -4672,6 +4675,20 @@ rules:
- patch
- create
- delete
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures
verbs:
- get
- watch
- list
- apiGroups:
- crd.antrea.io
resources:
- packetcaptures/status
verbs:
- update
- apiGroups:
- crd.antrea.io
resources:
Expand Down Expand Up @@ -4753,6 +4770,7 @@ rules:
- secrets
resourceNames:
- antrea-bgp-passwords
- antrea-packetcapture-fileserver-auth
verbs:
- get
- list
Expand Down Expand Up @@ -5365,7 +5383,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 8256bc0d365d60f16d0bdef14cf674be49d525ee1cd921e531f8bf7e521e1421
checksum/config: 2b4d82bcb825d50926115bad2125097f85aed424bfc49147444314cad8b7826a
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5601,7 +5619,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 8256bc0d365d60f16d0bdef14cf674be49d525ee1cd921e531f8bf7e521e1421
checksum/config: 2b4d82bcb825d50926115bad2125097f85aed424bfc49147444314cad8b7826a
labels:
app: antrea
component: antrea-controller
Expand Down
19 changes: 19 additions & 0 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
"antrea.io/antrea/pkg/agent/nodeip"
npl "antrea.io/antrea/pkg/agent/nodeportlocal"
"antrea.io/antrea/pkg/agent/openflow"
"antrea.io/antrea/pkg/agent/packetcapture"
"antrea.io/antrea/pkg/agent/proxy"
proxytypes "antrea.io/antrea/pkg/agent/proxy/types"
"antrea.io/antrea/pkg/agent/querier"
Expand Down Expand Up @@ -117,6 +118,7 @@ func run(o *Options) error {
informerFactory := informers.NewSharedInformerFactoryWithOptions(k8sClient, informerDefaultResync, informers.WithTransform(k8s.NewTrimmer(k8s.TrimNode)))
crdInformerFactory := crdinformers.NewSharedInformerFactoryWithOptions(crdClient, informerDefaultResync, crdinformers.WithTransform(k8s.NewTrimmer()))
traceflowInformer := crdInformerFactory.Crd().V1beta1().Traceflows()
packetCaptureInformer := crdInformerFactory.Crd().V1alpha1().PacketCaptures()
egressInformer := crdInformerFactory.Crd().V1beta1().Egresses()
externalIPPoolInformer := crdInformerFactory.Crd().V1beta1().ExternalIPPools()
trafficControlInformer := crdInformerFactory.Crd().V1alpha2().TrafficControls()
Expand Down Expand Up @@ -650,6 +652,19 @@ func run(o *Options) error {
o.enableAntreaProxy)
}

var packetCaptureController *packetcapture.Controller
if features.DefaultFeatureGate.Enabled(features.PacketCapture) {
packetCaptureController, err = packetcapture.NewPacketCaptureController(
k8sClient,
crdClient,
packetCaptureInformer,
ifaceStore,
)
if err != nil {
return fmt.Errorf("error when creating PacketCapture controller: %v", err)
}
}

if err := antreaClientProvider.RunOnce(); err != nil {
return err
}
Expand Down Expand Up @@ -808,6 +823,10 @@ func run(o *Options) error {
go traceflowController.Run(stopCh)
}

if features.DefaultFeatureGate.Enabled(features.PacketCapture) {
go packetCaptureController.Run(stopCh)
}

if o.enableAntreaProxy {
go proxier.GetProxyProvider().Run(stopCh)

Expand Down
Loading

0 comments on commit 303fa7f

Please sign in to comment.