From 03b443cf71394d9ac571c9b34bb852c8d1cefea4 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Wed, 30 Oct 2024 16:48:38 +0800 Subject: [PATCH] Add packetcatpure feature api Signed-off-by: Hang Yan --- build/charts/antrea/crds/packetcapture.yaml | 200 ++++++++++ build/yamls/antrea-aks.yml | 203 ++++++++++ build/yamls/antrea-crds.yml | 201 ++++++++++ build/yamls/antrea-eks.yml | 203 ++++++++++ build/yamls/antrea-gke.yml | 203 ++++++++++ build/yamls/antrea-ipsec.yml | 203 ++++++++++ build/yamls/antrea.yml | 203 ++++++++++ docs/api.md | 1 + pkg/apis/crd/v1alpha1/register.go | 2 + pkg/apis/crd/v1alpha1/types.go | 146 +++++++ .../crd/v1alpha1/zz_generated.deepcopy.go | 361 ++++++++++++++++++ .../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, 2415 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..54715d16503 --- /dev/null +++ b/build/charts/antrea/crds/packetcapture.yaml @@ -0,0 +1,200 @@ +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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + 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 c1cbf2da1e2..8150d635ef8 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -2896,6 +2896,209 @@ 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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap + --- # 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 6b6a2fb3091..b834ac135a0 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -2873,6 +2873,207 @@ 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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap +--- +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 1ec9870744a..42cc50e5627 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -2896,6 +2896,209 @@ 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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap + --- # 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 5890d414a44..d42bf874a61 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -2896,6 +2896,209 @@ 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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap + --- # 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 84eafd01dfe..f68c6958d43 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -2896,6 +2896,209 @@ 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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap + --- # Source: antrea/crds/supportbundlecollection.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 2d44748eaff..e9b646c66b1 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -2896,6 +2896,209 @@ 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: .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.source.ip + description: The IP address of the source. + name: Source-IP + 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: + - source + - captureConfig + - destination + anyOf: + - properties: + source: + required: [pod] + - properties: + destination: + required: [pod] + properties: + source: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + oneOf: + - required: + - pod + - required: + - ip + properties: + pod: + type: object + required: + - name + properties: + namespace: + type: string + default: default + name: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4, IPv6] + default: IPv4 + protocol: + x-kubernetes-int-or-string: true + 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 + + timeout: + type: integer + minimum: 1 + maximum: 300 + default: 60 + captureConfig: + type: object + oneOf: + - required: + - firstN + properties: + firstN: + type: object + required: + - number + 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: + startTime: + type: string + numCapturedPackets: + type: integer + packetsFilePath: + type: string + conditions: + type: array + items: + type: object + properties: + type: + type: string + status: + type: string + lastTransitionTime: + type: string + reason: + type: string + message: + type: string + subresources: + status: {} + scope: Cluster + names: + plural: packetcaptures + singular: packetcapture + kind: PacketCapture + shortNames: + - pcap + --- # 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..499e7a2ca9c 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,148 @@ 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"` } + +type PodReference struct { + Namespace string `json:"namespace"` + Name string `json:"name"` +} + +// Source describes the source spec of the packetcapture. +type Source struct { + // Pod is the source Pod, exclusive with source `IP`. + Pod *PodReference `json:"pod,omitempty"` + // IP is the source IPv4 or IPv6 address. + IP *string `json:"ip,omitempty"` +} + +// Destination describes the destination spec of the PacketCapture. +type Destination struct { + // Pod is the destination Pod, exclusive with destination `IP`. + Pod *PodReference `json:"pod,omitempty"` + // IP is the source IPv4 or IPv6 address. + IP *string `json:"ip,omitempty"` +} + +// 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"` +} + +// Packet includes header info. +type Packet struct { + // IPFamily is the filter's IP family. Defaults to IPv4. + IPFamily v1.IPFamily `json:"ipFamily,omitempty"` + // Protocol represents the transport protocol. Default is to not filter on protocol. + 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"` +} + +// +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 means we only capture first N packets from the target traffic. + // At the moment this is the only supported configuration and it is required for every capture. + FirstN *PacketCaptureFirstNConfig `json:"firstN,omitempty"` +} + +// PacketCaptureFileServer specifies the PacketCapture file server information. +type PacketCaptureFileServer struct { + // The URL of the file server. It is set with format: scheme://host[:port][/path], + // e.g, https://api.example.com:8443/v1/supportbundles/. If scheme is not set, https is used by default. + URL string `json:"url"` +} + +type PacketCaptureSpec struct { + // Timeout is the timeout for this capture session. If not specified, defaults to 60s. + Timeout *uint16 `json:"timeout,omitempty"` + CaptureConfig CaptureConfig `json:"captureConfig"` + // Source is the traffic source we want to perform capture on. Both `Source` and `Destination` is reuqired + // for a capture session, and at least one `Pod` should present either in the source or the destination. + Source Source `json:"source"` + Destination Destination `json:"destination"` + // Packet defines what kind of traffic we want to capture between the source and desination. If not spicified, + // all kinds of traffic will count. + Packet *Packet `json:"packet,omitempty"` + // FileServer specifies the sftp url config for a file server. If present, captured packets will be uploaded to this server. + // If not, the packet capture results will only be present as a file in the antrea-agent container. + // When the capture finished, the path information will be shown in `.status.PacketsFilePath`. + FileServer *PacketCaptureFileServer `json:"fileServer,omitempty"` +} + +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"` + // PacketsFilePath is the file path where the captured packets are stored. The format is: ":". + // If `.spec.FileServer` is present, this file will also be uploaded to the target location. This file + // will be removed after the PacketCapture CR is deleted. + PacketsFilePath string `json:"packetsFilePath"` + // StartTime is the time when this capture session started. + StartTime *metav1.Time `json:"startTime,omitempty"` + // Condition represents the latest available observations of the PacketCapture 's current state. + Conditions []PacketCaptureCondition `json:"conditions"` +} + +type PacketCaptureConditionType string + +const ( + // PacketCapturePending means this request is still pending. + PacketCapturePending PacketCaptureConditionType = "PacketCapturePedning" + // PacketCaptureRunning means antrea is processing this capture request. + PacketCaptureRunning PacketCaptureConditionType = "PacketCaptureRunning" + // CaptureCompleted means enough packets has been captured and saved in antrea-agent Pod locally already, but results hasn't been + // uploaded yet (if a fileserver has been configured). + PacketCaptureCompleted PacketCaptureConditionType = "PacketCaptureCompleted" + // PacketsUploaded means the captured packets file has been uploaded to the target fileserver. + PacketCaptureFileUploaded PacketCaptureConditionType = "PacketCaptureFileUploaded" +) + +type PacketCaptureCondition struct { + Type PacketCaptureConditionType `json:"type"` + Status metav1.ConditionStatus `json:"status"` + LastTransitionTime metav1.Time `json:"lastTransitionTime"` + Reason string `json:"reason"` + Message string `json:"message"` +} diff --git a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go index a45bdeca9c0..4818e26db89 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,53 @@ 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 + 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 +} + +// 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 +584,199 @@ 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 *PacketCaptureCondition) DeepCopyInto(out *PacketCaptureCondition) { + *out = *in + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCaptureCondition. +func (in *PacketCaptureCondition) DeepCopy() *PacketCaptureCondition { + if in == nil { + return nil + } + out := new(PacketCaptureCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PacketCaptureFileServer) DeepCopyInto(out *PacketCaptureFileServer) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PacketCaptureFileServer. +func (in *PacketCaptureFileServer) DeepCopy() *PacketCaptureFileServer { + if in == nil { + return nil + } + out := new(PacketCaptureFileServer) + in.DeepCopyInto(out) + return out +} + +// 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) + in.Source.DeepCopyInto(&out.Source) + in.Destination.DeepCopyInto(&out.Destination) + if in.Packet != nil { + in, out := &in.Packet, &out.Packet + *out = new(Packet) + (*in).DeepCopyInto(*out) + } + if in.FileServer != nil { + in, out := &in.FileServer, &out.FileServer + *out = new(PacketCaptureFileServer) + **out = **in + } + 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.StartTime != nil { + in, out := &in.StartTime, &out.StartTime + *out = (*in).DeepCopy() + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]PacketCaptureCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + 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 @@ -552,6 +793,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 @@ -573,6 +830,32 @@ 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 + 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 +} + +// 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 +985,32 @@ 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 + } + 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 +1026,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 +}