From 46467e1927ba068ea16ca0352487a4443868faf5 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Tue, 24 Sep 2024 16:12:33 +0800 Subject: [PATCH 1/4] Add packetcapture feature api Signed-off-by: Hang Yan --- build/charts/antrea/crds/packetcapture.yaml | 196 ++++++++++++ build/yamls/antrea-aks.yml | 182 +++++++++++ build/yamls/antrea-crds.yml | 180 +++++++++++ build/yamls/antrea-eks.yml | 182 +++++++++++ build/yamls/antrea-gke.yml | 182 +++++++++++ build/yamls/antrea-ipsec.yml | 182 +++++++++++ build/yamls/antrea.yml | 182 +++++++++++ docs/api.md | 1 + pkg/apis/crd/v1alpha1/register.go | 2 + pkg/apis/crd/v1alpha1/types.go | 121 ++++++++ .../crd/v1alpha1/zz_generated.deepcopy.go | 291 ++++++++++++++++++ .../typed/crd/v1alpha1/crd_client.go | 5 + .../crd/v1alpha1/fake/fake_crd_client.go | 4 + .../crd/v1alpha1/fake/fake_packetcapture.go | 130 ++++++++ .../typed/crd/v1alpha1/generated_expansion.go | 2 + .../typed/crd/v1alpha1/packetcapture.go | 182 +++++++++++ .../crd/v1alpha1/interface.go | 7 + .../crd/v1alpha1/packetcapture.go | 87 ++++++ .../informers/externalversions/generic.go | 2 + .../crd/v1alpha1/expansion_generated.go | 4 + .../listers/crd/v1alpha1/packetcapture.go | 66 ++++ 21 files changed, 2190 insertions(+) create mode 100644 build/charts/antrea/crds/packetcapture.yaml create mode 100644 pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_packetcapture.go create mode 100644 pkg/client/clientset/versioned/typed/crd/v1alpha1/packetcapture.go create mode 100644 pkg/client/informers/externalversions/crd/v1alpha1/packetcapture.go create mode 100644 pkg/client/listers/crd/v1alpha1/packetcapture.go diff --git a/build/charts/antrea/crds/packetcapture.yaml b/build/charts/antrea/crds/packetcapture.yaml new file mode 100644 index 00000000000..f3199af33f0 --- /dev/null +++ b/build/charts/antrea/crds/packetcapture.yaml @@ -0,0 +1,196 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + nullable: true + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + nullable: true + oneOf: + - required: + - pod + - required: + - ip + - required: + - service + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + x-kubernetes-validations: + - rule: "(self.ipFamily == 'IPv4' && self.protocol != 'IPv6-ICMP' && self.protocol != 58) || (self.ipFamily == 'IPv6' && self.protocol != 'ICMP' && self.protocol != 1) " + message: "packet.ipFamily is incompatiable with packet.protocol" + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + enum: [ICMP, TCP, UDP, IPv6-ICMP, 1, 6, 17, 58] + default: ICMP + transportHeader: + type: object + nullable: true + oneOf: + - required: + - tcp + - required: + - udp + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index dc3588bd87f..d278c39bf49 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -2866,6 +2866,188 @@ spec: shortNames: - nlm +--- +# Source: antrea/crds/packetcapture.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + minimum: 0 + maximum: 255 + ipv6Header: + type: object + properties: + nextHeader: + type: integer + minimum: 0 + maximum: 65535 + transportHeader: + type: object + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcp + --- # Source: antrea/crds/supportbundlecollection.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index 7036bd85bbe..0bb11322eae 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -2843,6 +2843,186 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + minimum: 0 + maximum: 255 + ipv6Header: + type: object + properties: + nextHeader: + type: integer + minimum: 0 + maximum: 65535 + transportHeader: + type: object + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcp +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: name: supportbundlecollections.crd.antrea.io spec: diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index ad84136fde0..a01b7fb7bc5 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -2866,6 +2866,188 @@ spec: shortNames: - nlm +--- +# Source: antrea/crds/packetcapture.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + minimum: 0 + maximum: 255 + ipv6Header: + type: object + properties: + nextHeader: + type: integer + minimum: 0 + maximum: 65535 + transportHeader: + type: object + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcp + --- # Source: antrea/crds/supportbundlecollection.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 12b550e747b..a66b3585033 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -2866,6 +2866,188 @@ spec: shortNames: - nlm +--- +# Source: antrea/crds/packetcapture.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + minimum: 0 + maximum: 255 + ipv6Header: + type: object + properties: + nextHeader: + type: integer + minimum: 0 + maximum: 65535 + transportHeader: + type: object + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcp + --- # Source: antrea/crds/supportbundlecollection.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index b9fb72487d8..0171f7a392c 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -2866,6 +2866,188 @@ spec: shortNames: - nlm +--- +# Source: antrea/crds/packetcapture.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + minimum: 0 + maximum: 255 + ipv6Header: + type: object + properties: + nextHeader: + type: integer + minimum: 0 + maximum: 65535 + transportHeader: + type: object + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcp + --- # Source: antrea/crds/supportbundlecollection.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 13f314dd022..6969be8f897 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -2866,6 +2866,188 @@ spec: shortNames: - nlm +--- +# Source: antrea/crds/packetcapture.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: packetcaptures.crd.antrea.io + labels: + app: antrea +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the PacketCapture. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.timeout + description: Timeout in seconds. + name: Timeout + type: integer + priority: 10 + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - fileServer + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + minimum: 0 + maximum: 255 + ipv6Header: + type: object + properties: + nextHeader: + type: integer + minimum: 0 + maximum: 65535 + transportHeader: + type: object + properties: + udp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + tcp: + type: object + properties: + srcPort: + type: integer + minimum: 1 + maximum: 65535 + dstPort: + type: integer + minimum: 1 + maximum: 65535 + flags: + type: integer + minimum: 0 + maximum: 255 + timeout: + type: integer + minimum: 1 + maximum: 300 + captureConfig: + type: object + anyOf: + - properties: + firstN: + required: [number] + properties: + firstN: + type: object + properties: + number: + type: integer + format: int32 + fileServer: + type: object + properties: + url: + type: string + pattern: 's{0,1}ftps{0,1}:\/\/[\w-_./]+:\d+' + status: + type: object + properties: + reason: + type: string + phase: + type: string + startTime: + type: string + numCapturedPackets: + type: integer + packetsFileName: + type: string + + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcp + --- # Source: antrea/crds/supportbundlecollection.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/docs/api.md b/docs/api.md index 4547cb66738..5000c95aad9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -40,6 +40,7 @@ These are the CRDs currently available in `crd.antrea.io`. | `Group` | v1beta1 | v1.13.0 | N/A | N/A | | `NetworkPolicy` | v1beta1 | v1.13.0 | N/A | N/A | | `NodeLatencyMonitor` | v1alpha1 | v2.1.0 | N/A | N/A | +| `PacketCapture` | v1alpha1 | v2.2 | N/A | N/A | | `SupportBundleCollection` | v1alpha1 | v1.10.0 | N/A | N/A | | `Tier` | v1beta1 | v1.13.0 | N/A | N/A | | `Traceflow` | v1beta1 | v1.13.0 | N/A | N/A | diff --git a/pkg/apis/crd/v1alpha1/register.go b/pkg/apis/crd/v1alpha1/register.go index ecefd26a924..bbd0b0b8229 100644 --- a/pkg/apis/crd/v1alpha1/register.go +++ b/pkg/apis/crd/v1alpha1/register.go @@ -57,6 +57,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &NodeLatencyMonitorList{}, &BGPPolicy{}, &BGPPolicyList{}, + &PacketCapture{}, + &PacketCaptureList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index 378d3a5c58c..cc1b1ed8275 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -17,6 +17,7 @@ package v1alpha1 import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) // IPBlock describes a particular CIDR (Ex. "192.168.1.1/24") that is allowed @@ -354,3 +355,123 @@ type BGPPeer struct { // a restart before deleting stale routes. The range of the value is from 1 to 3600, and the default value is 120. GracefulRestartTimeSeconds *int32 `json:"gracefulRestartTimeSeconds,omitempty"` } + +// Source describes the source spec of the packetcapture. +type Source struct { + // Namespace is the source Namespace. + Namespace string `json:"namespace"` + // Pod is the source Pod. + Pod string `json:"pod"` + // IP is the source IPv4 or IPv6 address. + IP string `json:"ip"` +} + +// Destination describes the destination spec of the PacketCapture. +type Destination struct { + // Namespace is the destination Namespace. + Namespace string `json:"namespace"` + // Pod is the destination Pod, exclusive with destination Service. + Pod string `json:"pod"` + // Service is the destination Service, exclusive with destination Pod. + Service string `json:"service"` + // IP is the destination IPv4 or IPv6 address. + IP string `json:"ip"` +} + +// TransportHeader describes spec of a TransportHeader. +type TransportHeader struct { + UDP *UDPHeader `json:"udp,omitempty"` + TCP *TCPHeader `json:"tcp,omitempty"` +} + +// UDPHeader describes spec of a UDP header. +type UDPHeader struct { + // SrcPort is the source port. + SrcPort *int32 `json:"srcPort,omitempty"` + // DstPort is the destination port. + DstPort *int32 `json:"dstPort,omitempty"` +} + +// TCPHeader describes spec of a TCP header. +type TCPHeader struct { + // SrcPort is the source port. + SrcPort *int32 `json:"srcPort,omitempty"` + // DstPort is the destination port. + DstPort *int32 `json:"dstPort,omitempty"` + // Flags are flags in the header. + Flags *int32 `json:"flags,omitempty"` +} + +// Packet includes header info. +type Packet struct { + // IPFamily is the filter's IP family. Default to `IPv4`. + IPFamily v1.IPFamily `json:"ipFamily"` + // Protocol represents the transport protocol. default to ICMP(1). Other + // possible choices are: TCP(6), UDP(17). + Protocol *intstr.IntOrString `json:"protocol,omitempty"` + TransportHeader TransportHeader `json:"transportHeader"` +} + +// PacketCaptureFirstNConfig contains the config for the FirstN type capture. The only supported parameter is +// `Number` at the moment, meaning capturing the first specified number of packets in a flow. +type PacketCaptureFirstNConfig struct { + Number int32 `json:"number"` +} + +const DefaultPacketCaptureTimeout uint16 = 60 + +type PacketCapturePhase string + +const ( + PacketCaptureRunning PacketCapturePhase = "Running" + PacketCaptureSucceeded PacketCapturePhase = "Succeeded" + PacketCaptureFailed PacketCapturePhase = "Failed" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type PacketCaptureList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []PacketCapture `json:"items"` +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type PacketCapture struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec PacketCaptureSpec `json:"spec"` + Status PacketCaptureStatus `json:"status"` +} + +type CaptureConfig struct { + FirstN *PacketCaptureFirstNConfig `json:"firstN,omitempty"` +} + +type PacketCaptureSpec struct { + Timeout *uint16 `json:"timeout,omitempty"` + CaptureConfig CaptureConfig `json:"captureConfig"` + Source Source `json:"source"` + Destination Destination `json:"destination"` + Packet *Packet `json:"packet,omitempty"` + // FileServer specifies the sftp url config for the fileServer. Captured packets will be uploaded to this server. + FileServer BundleFileServer `json:"fileServer"` +} + +type PacketCaptureStatus struct { + Phase PacketCapturePhase `json:"phase"` + // Reason records the failure reason when the capture fails. + Reason string `json:"reason"` + // NumCapturedPackets records how many packets have been captured. If it reaches the target number, the capture + // can be considered as finished. + NumCapturedPackets *int32 `json:"numCapturedPackets,omitempty"` + // PacketsFileName is the file name where the captured packets are temporarily cached. The file will be + // removed after the PacketCapture is deleted. + PacketsFileName string `json:"packetsFileName"` + StartTime *metav1.Time `json:"startTime,omitempty"` +} diff --git a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go index a45bdeca9c0..f4a512257c4 100644 --- a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go @@ -23,6 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" + intstr "k8s.io/apimachinery/pkg/util/intstr" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -266,6 +267,43 @@ func (in *BundleServerAuthConfiguration) DeepCopy() *BundleServerAuthConfigurati return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CaptureConfig) DeepCopyInto(out *CaptureConfig) { + *out = *in + if in.FirstN != nil { + in, out := &in.FirstN, &out.FirstN + *out = new(PacketCaptureFirstNConfig) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptureConfig. +func (in *CaptureConfig) DeepCopy() *CaptureConfig { + if in == nil { + return nil + } + out := new(CaptureConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Destination) DeepCopyInto(out *Destination) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Destination. +func (in *Destination) DeepCopy() *Destination { + if in == nil { + return nil + } + out := new(Destination) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EgressAdvertisement) DeepCopyInto(out *EgressAdvertisement) { *out = *in @@ -536,6 +574,160 @@ func (in *NodeLatencyMonitorSpec) DeepCopy() *NodeLatencyMonitorSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Packet) DeepCopyInto(out *Packet) { + *out = *in + if in.Protocol != nil { + in, out := &in.Protocol, &out.Protocol + *out = new(intstr.IntOrString) + **out = **in + } + in.TransportHeader.DeepCopyInto(&out.TransportHeader) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Packet. +func (in *Packet) DeepCopy() *Packet { + if in == nil { + return nil + } + out := new(Packet) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PacketCapture) DeepCopyInto(out *PacketCapture) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCapture. +func (in *PacketCapture) DeepCopy() *PacketCapture { + if in == nil { + return nil + } + out := new(PacketCapture) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PacketCapture) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PacketCaptureFirstNConfig) DeepCopyInto(out *PacketCaptureFirstNConfig) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCaptureFirstNConfig. +func (in *PacketCaptureFirstNConfig) DeepCopy() *PacketCaptureFirstNConfig { + if in == nil { + return nil + } + out := new(PacketCaptureFirstNConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PacketCaptureList) DeepCopyInto(out *PacketCaptureList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PacketCapture, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCaptureList. +func (in *PacketCaptureList) DeepCopy() *PacketCaptureList { + if in == nil { + return nil + } + out := new(PacketCaptureList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PacketCaptureList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PacketCaptureSpec) DeepCopyInto(out *PacketCaptureSpec) { + *out = *in + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(uint16) + **out = **in + } + in.CaptureConfig.DeepCopyInto(&out.CaptureConfig) + out.Source = in.Source + out.Destination = in.Destination + if in.Packet != nil { + in, out := &in.Packet, &out.Packet + *out = new(Packet) + (*in).DeepCopyInto(*out) + } + out.FileServer = in.FileServer + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCaptureSpec. +func (in *PacketCaptureSpec) DeepCopy() *PacketCaptureSpec { + if in == nil { + return nil + } + out := new(PacketCaptureSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PacketCaptureStatus) DeepCopyInto(out *PacketCaptureStatus) { + *out = *in + if in.NumCapturedPackets != nil { + in, out := &in.NumCapturedPackets, &out.NumCapturedPackets + *out = new(int32) + **out = **in + } + if in.StartTime != nil { + in, out := &in.StartTime, &out.StartTime + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCaptureStatus. +func (in *PacketCaptureStatus) DeepCopy() *PacketCaptureStatus { + if in == nil { + return nil + } + out := new(PacketCaptureStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PodAdvertisement) DeepCopyInto(out *PodAdvertisement) { *out = *in @@ -573,6 +765,22 @@ func (in *ServiceAdvertisement) DeepCopy() *ServiceAdvertisement { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Source) DeepCopyInto(out *Source) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Source. +func (in *Source) DeepCopy() *Source { + if in == nil { + return nil + } + out := new(Source) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SupportBundleCollection) DeepCopyInto(out *SupportBundleCollection) { *out = *in @@ -702,6 +910,37 @@ func (in *SupportBundleCollectionStatus) DeepCopy() *SupportBundleCollectionStat return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TCPHeader) DeepCopyInto(out *TCPHeader) { + *out = *in + if in.SrcPort != nil { + in, out := &in.SrcPort, &out.SrcPort + *out = new(int32) + **out = **in + } + if in.DstPort != nil { + in, out := &in.DstPort, &out.DstPort + *out = new(int32) + **out = **in + } + if in.Flags != nil { + in, out := &in.Flags, &out.Flags + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TCPHeader. +func (in *TCPHeader) DeepCopy() *TCPHeader { + if in == nil { + return nil + } + out := new(TCPHeader) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TLSProtocol) DeepCopyInto(out *TLSProtocol) { *out = *in @@ -717,3 +956,55 @@ func (in *TLSProtocol) DeepCopy() *TLSProtocol { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TransportHeader) DeepCopyInto(out *TransportHeader) { + *out = *in + if in.UDP != nil { + in, out := &in.UDP, &out.UDP + *out = new(UDPHeader) + (*in).DeepCopyInto(*out) + } + if in.TCP != nil { + in, out := &in.TCP, &out.TCP + *out = new(TCPHeader) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TransportHeader. +func (in *TransportHeader) DeepCopy() *TransportHeader { + if in == nil { + return nil + } + out := new(TransportHeader) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UDPHeader) DeepCopyInto(out *UDPHeader) { + *out = *in + if in.SrcPort != nil { + in, out := &in.SrcPort, &out.SrcPort + *out = new(int32) + **out = **in + } + if in.DstPort != nil { + in, out := &in.DstPort, &out.DstPort + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UDPHeader. +func (in *UDPHeader) DeepCopy() *UDPHeader { + if in == nil { + return nil + } + out := new(UDPHeader) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go index bcff19f9bd7..c0780d228ec 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go @@ -29,6 +29,7 @@ type CrdV1alpha1Interface interface { BGPPoliciesGetter ExternalNodesGetter NodeLatencyMonitorsGetter + PacketCapturesGetter SupportBundleCollectionsGetter } @@ -49,6 +50,10 @@ func (c *CrdV1alpha1Client) NodeLatencyMonitors() NodeLatencyMonitorInterface { return newNodeLatencyMonitors(c) } +func (c *CrdV1alpha1Client) PacketCaptures() PacketCaptureInterface { + return newPacketCaptures(c) +} + func (c *CrdV1alpha1Client) SupportBundleCollections() SupportBundleCollectionInterface { return newSupportBundleCollections(c) } diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go index 4d6c869b949..34b1c00ff7e 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go @@ -38,6 +38,10 @@ func (c *FakeCrdV1alpha1) NodeLatencyMonitors() v1alpha1.NodeLatencyMonitorInter return &FakeNodeLatencyMonitors{c} } +func (c *FakeCrdV1alpha1) PacketCaptures() v1alpha1.PacketCaptureInterface { + return &FakePacketCaptures{c} +} + func (c *FakeCrdV1alpha1) SupportBundleCollections() v1alpha1.SupportBundleCollectionInterface { return &FakeSupportBundleCollections{c} } diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_packetcapture.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_packetcapture.go new file mode 100644 index 00000000000..36b7b7682ce --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_packetcapture.go @@ -0,0 +1,130 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakePacketCaptures implements PacketCaptureInterface +type FakePacketCaptures struct { + Fake *FakeCrdV1alpha1 +} + +var packetcapturesResource = v1alpha1.SchemeGroupVersion.WithResource("packetcaptures") + +var packetcapturesKind = v1alpha1.SchemeGroupVersion.WithKind("PacketCapture") + +// Get takes name of the packetCapture, and returns the corresponding packetCapture object, and an error if there is any. +func (c *FakePacketCaptures) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PacketCapture, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(packetcapturesResource, name), &v1alpha1.PacketCapture{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PacketCapture), err +} + +// List takes label and field selectors, and returns the list of PacketCaptures that match those selectors. +func (c *FakePacketCaptures) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PacketCaptureList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(packetcapturesResource, packetcapturesKind, opts), &v1alpha1.PacketCaptureList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.PacketCaptureList{ListMeta: obj.(*v1alpha1.PacketCaptureList).ListMeta} + for _, item := range obj.(*v1alpha1.PacketCaptureList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested packetCaptures. +func (c *FakePacketCaptures) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(packetcapturesResource, opts)) +} + +// Create takes the representation of a packetCapture and creates it. Returns the server's representation of the packetCapture, and an error, if there is any. +func (c *FakePacketCaptures) Create(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.CreateOptions) (result *v1alpha1.PacketCapture, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(packetcapturesResource, packetCapture), &v1alpha1.PacketCapture{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PacketCapture), err +} + +// Update takes the representation of a packetCapture and updates it. Returns the server's representation of the packetCapture, and an error, if there is any. +func (c *FakePacketCaptures) Update(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.UpdateOptions) (result *v1alpha1.PacketCapture, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(packetcapturesResource, packetCapture), &v1alpha1.PacketCapture{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PacketCapture), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakePacketCaptures) UpdateStatus(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.UpdateOptions) (*v1alpha1.PacketCapture, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(packetcapturesResource, "status", packetCapture), &v1alpha1.PacketCapture{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PacketCapture), err +} + +// Delete takes name of the packetCapture and deletes it. Returns an error if one occurs. +func (c *FakePacketCaptures) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(packetcapturesResource, name, opts), &v1alpha1.PacketCapture{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakePacketCaptures) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(packetcapturesResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.PacketCaptureList{}) + return err +} + +// Patch applies the patch and returns the patched packetCapture. +func (c *FakePacketCaptures) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PacketCapture, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(packetcapturesResource, name, pt, data, subresources...), &v1alpha1.PacketCapture{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PacketCapture), err +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go index 0631615e701..fdcf058ec7e 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go @@ -22,4 +22,6 @@ type ExternalNodeExpansion interface{} type NodeLatencyMonitorExpansion interface{} +type PacketCaptureExpansion interface{} + type SupportBundleCollectionExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/packetcapture.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/packetcapture.go new file mode 100644 index 00000000000..3cbff9e855d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/packetcapture.go @@ -0,0 +1,182 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + scheme "antrea.io/antrea/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// PacketCapturesGetter has a method to return a PacketCaptureInterface. +// A group's client should implement this interface. +type PacketCapturesGetter interface { + PacketCaptures() PacketCaptureInterface +} + +// PacketCaptureInterface has methods to work with PacketCapture resources. +type PacketCaptureInterface interface { + Create(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.CreateOptions) (*v1alpha1.PacketCapture, error) + Update(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.UpdateOptions) (*v1alpha1.PacketCapture, error) + UpdateStatus(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.UpdateOptions) (*v1alpha1.PacketCapture, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.PacketCapture, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PacketCaptureList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PacketCapture, err error) + PacketCaptureExpansion +} + +// packetCaptures implements PacketCaptureInterface +type packetCaptures struct { + client rest.Interface +} + +// newPacketCaptures returns a PacketCaptures +func newPacketCaptures(c *CrdV1alpha1Client) *packetCaptures { + return &packetCaptures{ + client: c.RESTClient(), + } +} + +// Get takes name of the packetCapture, and returns the corresponding packetCapture object, and an error if there is any. +func (c *packetCaptures) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PacketCapture, err error) { + result = &v1alpha1.PacketCapture{} + err = c.client.Get(). + Resource("packetcaptures"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of PacketCaptures that match those selectors. +func (c *packetCaptures) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PacketCaptureList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.PacketCaptureList{} + err = c.client.Get(). + Resource("packetcaptures"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested packetCaptures. +func (c *packetCaptures) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("packetcaptures"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a packetCapture and creates it. Returns the server's representation of the packetCapture, and an error, if there is any. +func (c *packetCaptures) Create(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.CreateOptions) (result *v1alpha1.PacketCapture, err error) { + result = &v1alpha1.PacketCapture{} + err = c.client.Post(). + Resource("packetcaptures"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(packetCapture). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a packetCapture and updates it. Returns the server's representation of the packetCapture, and an error, if there is any. +func (c *packetCaptures) Update(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.UpdateOptions) (result *v1alpha1.PacketCapture, err error) { + result = &v1alpha1.PacketCapture{} + err = c.client.Put(). + Resource("packetcaptures"). + Name(packetCapture.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(packetCapture). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *packetCaptures) UpdateStatus(ctx context.Context, packetCapture *v1alpha1.PacketCapture, opts v1.UpdateOptions) (result *v1alpha1.PacketCapture, err error) { + result = &v1alpha1.PacketCapture{} + err = c.client.Put(). + Resource("packetcaptures"). + Name(packetCapture.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(packetCapture). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the packetCapture and deletes it. Returns an error if one occurs. +func (c *packetCaptures) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("packetcaptures"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *packetCaptures) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("packetcaptures"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched packetCapture. +func (c *packetCaptures) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PacketCapture, err error) { + result = &v1alpha1.PacketCapture{} + err = c.client.Patch(pt). + Resource("packetcaptures"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/crd/v1alpha1/interface.go b/pkg/client/informers/externalversions/crd/v1alpha1/interface.go index e69100682ba..244bbe860f2 100644 --- a/pkg/client/informers/externalversions/crd/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1alpha1/interface.go @@ -28,6 +28,8 @@ type Interface interface { ExternalNodes() ExternalNodeInformer // NodeLatencyMonitors returns a NodeLatencyMonitorInformer. NodeLatencyMonitors() NodeLatencyMonitorInformer + // PacketCaptures returns a PacketCaptureInformer. + PacketCaptures() PacketCaptureInformer // SupportBundleCollections returns a SupportBundleCollectionInformer. SupportBundleCollections() SupportBundleCollectionInformer } @@ -58,6 +60,11 @@ func (v *version) NodeLatencyMonitors() NodeLatencyMonitorInformer { return &nodeLatencyMonitorInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// PacketCaptures returns a PacketCaptureInformer. +func (v *version) PacketCaptures() PacketCaptureInformer { + return &packetCaptureInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + // SupportBundleCollections returns a SupportBundleCollectionInformer. func (v *version) SupportBundleCollections() SupportBundleCollectionInformer { return &supportBundleCollectionInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/crd/v1alpha1/packetcapture.go b/pkg/client/informers/externalversions/crd/v1alpha1/packetcapture.go new file mode 100644 index 00000000000..1995048a4c9 --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1alpha1/packetcapture.go @@ -0,0 +1,87 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + versioned "antrea.io/antrea/pkg/client/clientset/versioned" + internalinterfaces "antrea.io/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "antrea.io/antrea/pkg/client/listers/crd/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// PacketCaptureInformer provides access to a shared informer and lister for +// PacketCaptures. +type PacketCaptureInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.PacketCaptureLister +} + +type packetCaptureInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewPacketCaptureInformer constructs a new informer for PacketCapture type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewPacketCaptureInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredPacketCaptureInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredPacketCaptureInformer constructs a new informer for PacketCapture type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredPacketCaptureInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1alpha1().PacketCaptures().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1alpha1().PacketCaptures().Watch(context.TODO(), options) + }, + }, + &crdv1alpha1.PacketCapture{}, + resyncPeriod, + indexers, + ) +} + +func (f *packetCaptureInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredPacketCaptureInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *packetCaptureInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1alpha1.PacketCapture{}, f.defaultInformer) +} + +func (f *packetCaptureInformer) Lister() v1alpha1.PacketCaptureLister { + return v1alpha1.NewPacketCaptureLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 07c1d724cbc..d8325bbf33f 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -59,6 +59,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().ExternalNodes().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("nodelatencymonitors"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().NodeLatencyMonitors().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("packetcaptures"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().PacketCaptures().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("supportbundlecollections"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().SupportBundleCollections().Informer()}, nil diff --git a/pkg/client/listers/crd/v1alpha1/expansion_generated.go b/pkg/client/listers/crd/v1alpha1/expansion_generated.go index 6d1c92155c1..ebe5ff42e87 100644 --- a/pkg/client/listers/crd/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/crd/v1alpha1/expansion_generated.go @@ -32,6 +32,10 @@ type ExternalNodeNamespaceListerExpansion interface{} // NodeLatencyMonitorLister. type NodeLatencyMonitorListerExpansion interface{} +// PacketCaptureListerExpansion allows custom methods to be added to +// PacketCaptureLister. +type PacketCaptureListerExpansion interface{} + // SupportBundleCollectionListerExpansion allows custom methods to be added to // SupportBundleCollectionLister. type SupportBundleCollectionListerExpansion interface{} diff --git a/pkg/client/listers/crd/v1alpha1/packetcapture.go b/pkg/client/listers/crd/v1alpha1/packetcapture.go new file mode 100644 index 00000000000..b7c9cc4ad53 --- /dev/null +++ b/pkg/client/listers/crd/v1alpha1/packetcapture.go @@ -0,0 +1,66 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// PacketCaptureLister helps list PacketCaptures. +// All objects returned here must be treated as read-only. +type PacketCaptureLister interface { + // List lists all PacketCaptures in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.PacketCapture, err error) + // Get retrieves the PacketCapture from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.PacketCapture, error) + PacketCaptureListerExpansion +} + +// packetCaptureLister implements the PacketCaptureLister interface. +type packetCaptureLister struct { + indexer cache.Indexer +} + +// NewPacketCaptureLister returns a new PacketCaptureLister. +func NewPacketCaptureLister(indexer cache.Indexer) PacketCaptureLister { + return &packetCaptureLister{indexer: indexer} +} + +// List lists all PacketCaptures in the indexer. +func (s *packetCaptureLister) List(selector labels.Selector) (ret []*v1alpha1.PacketCapture, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.PacketCapture)) + }) + return ret, err +} + +// Get retrieves the PacketCapture from the index for a given name. +func (s *packetCaptureLister) Get(name string) (*v1alpha1.PacketCapture, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("packetcapture"), name) + } + return obj.(*v1alpha1.PacketCapture), nil +} From a1039f0be0a10e6c86515f9ba102bb71e7d33d51 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Wed, 25 Sep 2024 14:42:20 +0800 Subject: [PATCH 2/4] comments Signed-off-by: Hang Yan --- build/charts/antrea/crds/packetcapture.yaml | 2 +- pkg/apis/crd/v1alpha1/types.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/charts/antrea/crds/packetcapture.yaml b/build/charts/antrea/crds/packetcapture.yaml index f3199af33f0..e2e7ecb0f92 100644 --- a/build/charts/antrea/crds/packetcapture.yaml +++ b/build/charts/antrea/crds/packetcapture.yaml @@ -103,7 +103,7 @@ spec: type: object x-kubernetes-validations: - rule: "(self.ipFamily == 'IPv4' && self.protocol != 'IPv6-ICMP' && self.protocol != 58) || (self.ipFamily == 'IPv6' && self.protocol != 'ICMP' && self.protocol != 1) " - message: "packet.ipFamily is incompatiable with packet.protocol" + message: "packet.ipFamily is incompatible with packet.protocol" properties: ipFamily: type: string diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index cc1b1ed8275..3686ac43cd8 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -470,8 +470,8 @@ type PacketCaptureStatus struct { // NumCapturedPackets records how many packets have been captured. If it reaches the target number, the capture // can be considered as finished. NumCapturedPackets *int32 `json:"numCapturedPackets,omitempty"` - // PacketsFileName is the file name where the captured packets are temporarily cached. The file will be - // removed after the PacketCapture is deleted. - PacketsFileName string `json:"packetsFileName"` - StartTime *metav1.Time `json:"startTime,omitempty"` + // PacketsFileName is the file name where the captured packets are temporarily cached, also the file name stored in the configured fileserver. The temporary file in the local cache will be removed after the PacketCapture is deleted. + PacketsFileName string `json:"packetsFileName"` + // StartTime is the time when this capture sessions starts. + StartTime *metav1.Time `json:"startTime,omitempty"` } From ee7255c9f2566c55cfecc37cb4aa79580e2bb7b4 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Mon, 30 Sep 2024 19:34:10 +0800 Subject: [PATCH 3/4] pod ref Signed-off-by: Hang Yan --- build/charts/antrea/crds/packetcapture.yaml | 26 +++++--- pkg/apis/crd/v1alpha1/types.go | 26 +++++--- .../crd/v1alpha1/zz_generated.deepcopy.go | 61 ++++++++++++++++++- 3 files changed, 93 insertions(+), 20 deletions(-) diff --git a/build/charts/antrea/crds/packetcapture.yaml b/build/charts/antrea/crds/packetcapture.yaml index e2e7ecb0f92..c6326fcc6b4 100644 --- a/build/charts/antrea/crds/packetcapture.yaml +++ b/build/charts/antrea/crds/packetcapture.yaml @@ -69,9 +69,12 @@ spec: - ip properties: pod: - type: string - namespace: - type: string + type: object + properties: + namespace: + type: string + name: + type: string ip: type: string oneOf: @@ -89,11 +92,19 @@ spec: - service properties: pod: - type: string + type: object + properties: + namespace: + type: string + name: + type: string service: - type: string - namespace: - type: string + type: object + properties: + namespace: + type: string + name: + type: string ip: type: string oneOf: @@ -111,7 +122,6 @@ spec: default: IPv4 protocol: x-kubernetes-int-or-string: true - enum: [ICMP, TCP, UDP, IPv6-ICMP, 1, 6, 17, 58] default: ICMP transportHeader: type: object diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index 3686ac43cd8..fea1b663fdb 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -356,26 +356,32 @@ type BGPPeer struct { GracefulRestartTimeSeconds *int32 `json:"gracefulRestartTimeSeconds,omitempty"` } +type PodReference struct { + Namespace string + Name string +} + +type ServiceReference struct { + Namespace string + Name string +} + // Source describes the source spec of the packetcapture. type Source struct { - // Namespace is the source Namespace. - Namespace string `json:"namespace"` - // Pod is the source Pod. - Pod string `json:"pod"` + // Pod is the source pod, + Pod *PodReference `json:"pod,omitempty"` // IP is the source IPv4 or IPv6 address. - IP string `json:"ip"` + IP *string `json:"ip,omitempty"` } // Destination describes the destination spec of the PacketCapture. type Destination struct { - // Namespace is the destination Namespace. - Namespace string `json:"namespace"` // Pod is the destination Pod, exclusive with destination Service. - Pod string `json:"pod"` + Pod *PodReference `json:"pod,omitempty"` // Service is the destination Service, exclusive with destination Pod. - Service string `json:"service"` + Service *ServiceReference `json:"service,omitempty"` // IP is the destination IPv4 or IPv6 address. - IP string `json:"ip"` + IP *string `json:"ip,omitempty"` } // TransportHeader describes spec of a TransportHeader. diff --git a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go index f4a512257c4..669be368c1d 100644 --- a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go @@ -291,6 +291,21 @@ func (in *CaptureConfig) DeepCopy() *CaptureConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Destination) DeepCopyInto(out *Destination) { *out = *in + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = new(PodReference) + **out = **in + } + if in.Service != nil { + in, out := &in.Service, &out.Service + *out = new(ServiceReference) + **out = **in + } + if in.IP != nil { + in, out := &in.IP, &out.IP + *out = new(string) + **out = **in + } return } @@ -682,8 +697,8 @@ func (in *PacketCaptureSpec) DeepCopyInto(out *PacketCaptureSpec) { **out = **in } in.CaptureConfig.DeepCopyInto(&out.CaptureConfig) - out.Source = in.Source - out.Destination = in.Destination + in.Source.DeepCopyInto(&out.Source) + in.Destination.DeepCopyInto(&out.Destination) if in.Packet != nil { in, out := &in.Packet, &out.Packet *out = new(Packet) @@ -744,6 +759,22 @@ func (in *PodAdvertisement) DeepCopy() *PodAdvertisement { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodReference) DeepCopyInto(out *PodReference) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodReference. +func (in *PodReference) DeepCopy() *PodReference { + if in == nil { + return nil + } + out := new(PodReference) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServiceAdvertisement) DeepCopyInto(out *ServiceAdvertisement) { *out = *in @@ -765,9 +796,35 @@ func (in *ServiceAdvertisement) DeepCopy() *ServiceAdvertisement { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceReference) DeepCopyInto(out *ServiceReference) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceReference. +func (in *ServiceReference) DeepCopy() *ServiceReference { + if in == nil { + return nil + } + out := new(ServiceReference) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Source) DeepCopyInto(out *Source) { *out = *in + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = new(PodReference) + **out = **in + } + if in.IP != nil { + in, out := &in.IP, &out.IP + *out = new(string) + **out = **in + } return } From 46778a90569b03f610dab01d747619757b812d28 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Wed, 9 Oct 2024 15:54:18 +0800 Subject: [PATCH 4/4] update field and yaml Signed-off-by: Hang Yan --- build/charts/antrea/crds/packetcapture.yaml | 4 ---- pkg/apis/crd/v1alpha1/types.go | 5 ++--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/build/charts/antrea/crds/packetcapture.yaml b/build/charts/antrea/crds/packetcapture.yaml index c6326fcc6b4..ec3aed35e95 100644 --- a/build/charts/antrea/crds/packetcapture.yaml +++ b/build/charts/antrea/crds/packetcapture.yaml @@ -112,9 +112,6 @@ spec: - format: ipv6 packet: type: object - x-kubernetes-validations: - - rule: "(self.ipFamily == 'IPv4' && self.protocol != 'IPv6-ICMP' && self.protocol != 58) || (self.ipFamily == 'IPv6' && self.protocol != 'ICMP' && self.protocol != 1) " - message: "packet.ipFamily is incompatible with packet.protocol" properties: ipFamily: type: string @@ -122,7 +119,6 @@ spec: default: IPv4 protocol: x-kubernetes-int-or-string: true - default: ICMP transportHeader: type: object nullable: true diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index fea1b663fdb..b944789be0a 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -411,9 +411,8 @@ type TCPHeader struct { // Packet includes header info. type Packet struct { // IPFamily is the filter's IP family. Default to `IPv4`. - IPFamily v1.IPFamily `json:"ipFamily"` - // Protocol represents the transport protocol. default to ICMP(1). Other - // possible choices are: TCP(6), UDP(17). + IPFamily v1.IPFamily `json:"ipFamily,omitempty"` + // Protocol represents the transport protocol. default is not filter on protocol Protocol *intstr.IntOrString `json:"protocol,omitempty"` TransportHeader TransportHeader `json:"transportHeader"` }