diff --git a/build/charts/antrea/crds/packetcapture.yaml b/build/charts/antrea/crds/packetcapture.yaml new file mode 100644 index 00000000000..b9a1d9ed9df --- /dev/null +++ b/build/charts/antrea/crds/packetcapture.yaml @@ -0,0 +1,194 @@ +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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..2ea0d6d1641 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -2896,6 +2896,203 @@ 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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..57a4ca00448 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -2873,6 +2873,201 @@ 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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..69179538eb6 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -2896,6 +2896,203 @@ 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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..78a46fdd32f 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -2896,6 +2896,203 @@ 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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..853279551a4 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -2896,6 +2896,203 @@ 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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..284d225fb95 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -2896,6 +2896,203 @@ 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 + format: ipv4 + 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 + format: ipv4 + packet: + type: object + properties: + ipFamily: + type: string + enum: [IPv4] + 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: + numberCaptured: + type: integer + filePath: + 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..e40282c0349 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,146 @@ 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, mutually exclusive with 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 the spec of a TransportHeader. +type TransportHeader struct { + UDP *UDPHeader `json:"udp,omitempty"` + TCP *TCPHeader `json:"tcp,omitempty"` +} + +// UDPHeader describes the 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 the 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. No protocol based filter when it's empty. + 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/packets/. Currently only `sftp` protocol is supported. + 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 required + // for a capture session, and at least one `Pod` should be 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 destination. If not specified, + // 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 { + // NumberCaptured records how many packets have been captured. If it reaches the target number, the capture + // can be considered as finished. + NumberCaptured int32 `json:"numberCaptured"` + // FilePath specifies the location where captured packets are stored. It can either be a URL to download the pcap file (if "Spec.FileServer" is specified) + // or a local file path on the antrea-agent Pod where the packet was captured, formatted as : :. + // When using a local file path, the file will be automatically removed after the PacketCapture resource is deleted. + FilePath string `json:"filePath"` + // 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 = "PacketCapturePending" + // PacketCaptureRunning means antrea is processing this capture request. + PacketCaptureRunning PacketCaptureConditionType = "PacketCaptureRunning" + // PacketCaptureCompleted means enough packets have been captured and saved in an antrea-agent Pod locally already, but results haven't been + // uploaded yet (if a file server has been configured). + PacketCaptureCompleted PacketCaptureConditionType = "PacketCaptureCompleted" + // PacketCaptureFileUploaded means the captured packets file has been uploaded to the target file server. + 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..dd90a610ed5 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,195 @@ 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.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 +789,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 +826,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 +981,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 +1022,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..86a20fdd7d8 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_packetcapture.go @@ -0,0 +1,136 @@ +// 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) { + emptyResult := &v1alpha1.PacketCapture{} + obj, err := c.Fake. + Invokes(testing.NewRootGetActionWithOptions(packetcapturesResource, name, options), emptyResult) + if obj == nil { + return emptyResult, 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) { + emptyResult := &v1alpha1.PacketCaptureList{} + obj, err := c.Fake. + Invokes(testing.NewRootListActionWithOptions(packetcapturesResource, packetcapturesKind, opts), emptyResult) + if obj == nil { + return emptyResult, 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.NewRootWatchActionWithOptions(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) { + emptyResult := &v1alpha1.PacketCapture{} + obj, err := c.Fake. + Invokes(testing.NewRootCreateActionWithOptions(packetcapturesResource, packetCapture, opts), emptyResult) + if obj == nil { + return emptyResult, 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) { + emptyResult := &v1alpha1.PacketCapture{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateActionWithOptions(packetcapturesResource, packetCapture, opts), emptyResult) + if obj == nil { + return emptyResult, 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) (result *v1alpha1.PacketCapture, err error) { + emptyResult := &v1alpha1.PacketCapture{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(packetcapturesResource, "status", packetCapture, opts), emptyResult) + if obj == nil { + return emptyResult, 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.NewRootDeleteCollectionActionWithOptions(packetcapturesResource, opts, 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) { + emptyResult := &v1alpha1.PacketCapture{} + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceActionWithOptions(packetcapturesResource, name, pt, data, opts, subresources...), emptyResult) + if obj == nil { + return emptyResult, 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..9c52682070c --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/packetcapture.go @@ -0,0 +1,67 @@ +// 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" + + 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" + gentype "k8s.io/client-go/gentype" +) + +// 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) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + 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 { + *gentype.ClientWithList[*v1alpha1.PacketCapture, *v1alpha1.PacketCaptureList] +} + +// newPacketCaptures returns a PacketCaptures +func newPacketCaptures(c *CrdV1alpha1Client) *packetCaptures { + return &packetCaptures{ + gentype.NewClientWithList[*v1alpha1.PacketCapture, *v1alpha1.PacketCaptureList]( + "packetcaptures", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v1alpha1.PacketCapture { return &v1alpha1.PacketCapture{} }, + func() *v1alpha1.PacketCaptureList { return &v1alpha1.PacketCaptureList{} }), + } +} 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..d052771c46f --- /dev/null +++ b/pkg/client/listers/crd/v1alpha1/packetcapture.go @@ -0,0 +1,46 @@ +// 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/labels" + "k8s.io/client-go/listers" + "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 { + listers.ResourceIndexer[*v1alpha1.PacketCapture] +} + +// NewPacketCaptureLister returns a new PacketCaptureLister. +func NewPacketCaptureLister(indexer cache.Indexer) PacketCaptureLister { + return &packetCaptureLister{listers.New[*v1alpha1.PacketCapture](indexer, v1alpha1.Resource("packetcapture"))} +}