From 5baf453bdf317ac266b686a16c1e1909a57680cd Mon Sep 17 00:00:00 2001 From: Lan Luo Date: Fri, 9 Jun 2023 17:11:38 +0800 Subject: [PATCH] Promote Traceflow API to v1beta1 1. Promote Traceflow API to v1beta1. 2. Remove srcIP field in IPHeader and IPv6Header since it's never used and duplicated with parent struct. 3. Change IPHeader field to a pointer in Packet struct. 4. Change Flags field to a pointer in the TCPHeader struct. Signed-off-by: Lan Luo --- build/charts/antrea/crds/traceflow.yaml | 233 +++++- build/yamls/antrea-aks.yml | 233 +++++- build/yamls/antrea-crds.yml | 233 +++++- build/yamls/antrea-eks.yml | 233 +++++- build/yamls/antrea-gke.yml | 233 +++++- build/yamls/antrea-ipsec.yml | 233 +++++- build/yamls/antrea.yml | 233 +++++- cmd/antrea-agent/agent.go | 2 +- cmd/antrea-controller/controller.go | 2 +- docs/api.md | 3 +- docs/traceflow-guide.md | 6 +- pkg/agent/controller/traceflow/packetin.go | 90 +-- .../controller/traceflow/packetin_test.go | 141 ++-- .../traceflow/traceflow_controller.go | 48 +- .../traceflow/traceflow_controller_test.go | 290 ++++---- pkg/apis/crd/v1beta1/register.go | 2 + pkg/apis/crd/v1beta1/traceflow_types.go | 283 ++++++++ pkg/apis/crd/v1beta1/zz_generated.deepcopy.go | 326 ++++++++- pkg/apiserver/openapi/zz_generated.openapi.go | 674 ++++++++++++++++++ .../versioned/typed/crd/v1beta1/crd_client.go | 7 +- .../typed/crd/v1beta1/fake/fake_crd_client.go | 6 +- .../typed/crd/v1beta1/fake/fake_traceflow.go | 131 ++++ .../typed/crd/v1beta1/generated_expansion.go | 4 +- .../versioned/typed/crd/v1beta1/traceflow.go | 182 +++++ .../externalversions/crd/v1beta1/interface.go | 9 +- .../externalversions/crd/v1beta1/traceflow.go | 87 +++ .../informers/externalversions/generic.go | 4 +- .../crd/v1beta1/expansion_generated.go | 6 +- pkg/client/listers/crd/v1beta1/traceflow.go | 66 ++ pkg/controller/traceflow/controller.go | 58 +- pkg/controller/traceflow/controller_test.go | 54 +- pkg/graphviz/traceflow.go | 68 +- pkg/graphviz/traceflow_test.go | 255 +++---- 33 files changed, 3917 insertions(+), 518 deletions(-) create mode 100644 pkg/apis/crd/v1beta1/traceflow_types.go create mode 100644 pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_traceflow.go create mode 100644 pkg/client/clientset/versioned/typed/crd/v1beta1/traceflow.go create mode 100644 pkg/client/informers/externalversions/crd/v1beta1/traceflow.go create mode 100644 pkg/client/listers/crd/v1beta1/traceflow.go diff --git a/build/charts/antrea/crds/traceflow.yaml b/build/charts/antrea/crds/traceflow.yaml index 113e98bd488..ded73b81f78 100644 --- a/build/charts/antrea/crds/traceflow.yaml +++ b/build/charts/antrea/crds/traceflow.yaml @@ -9,7 +9,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -246,6 +246,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index 576a4ada7a0..be334b0b397 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -2382,7 +2382,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -2619,6 +2619,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index 2f0743aa33e..989d2c94f2c 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -2357,7 +2357,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -2594,6 +2594,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index abdfb016b51..6830643fa41 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -2382,7 +2382,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -2619,6 +2619,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 0644b4f38e2..7479e286de5 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -2382,7 +2382,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -2619,6 +2619,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index 0a83edf5d40..f8e3f57060b 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -2382,7 +2382,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -2619,6 +2619,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 7907d69756f..1bb5195a75a 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -2382,7 +2382,7 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false additionalPrinterColumns: - jsonPath: .status.phase description: The phase of the Traceflow. @@ -2619,6 +2619,237 @@ spec: type: object subresources: status: {} + - name: v1beta1 + served: true + storage: true + additionalPrinterColumns: + - jsonPath: .status.phase + description: The phase of the Traceflow. + name: Phase + type: string + - jsonPath: .spec.source.pod + description: The name of the source Pod. + name: Source-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.pod + description: The name of the destination Pod. + name: Destination-Pod + type: string + priority: 10 + - jsonPath: .spec.destination.ip + description: The IP address of the destination. + name: Destination-IP + type: string + priority: 10 + - jsonPath: .spec.liveTraffic + description: Trace live traffic. + name: Live-Traffic + type: boolean + priority: 10 + - jsonPath: .spec.droppedOnly + description: Capture only the dropped packet. + name: Dropped-Only + type: boolean + 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 + properties: + source: + type: object + properties: + pod: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + destination: + type: object + properties: + pod: + type: string + service: + type: string + namespace: + type: string + ip: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + packet: + type: object + properties: + ipHeader: + type: object + properties: + protocol: + type: integer + ttl: + type: integer + flags: + type: integer + ipv6Header: + type: object + properties: + nextHeader: + type: integer + hopLimit: + type: integer + transportHeader: + type: object + properties: + icmp: + type: object + properties: + id: + type: integer + sequence: + type: integer + udp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + tcp: + type: object + properties: + srcPort: + type: integer + dstPort: + type: integer + flags: + type: integer + liveTraffic: + type: boolean + droppedOnly: + type: boolean + timeout: + type: integer + status: + type: object + properties: + reason: + type: string + dataplaneTag: + type: integer + phase: + type: string + startTime: + type: string + results: + type: array + items: + type: object + properties: + node: + type: string + role: + type: string + timestamp: + type: integer + observations: + type: array + items: + type: object + properties: + component: + type: string + componentInfo: + type: string + action: + type: string + pod: + type: string + dstMAC: + type: string + networkPolicy: + type: string + ttl: + type: integer + translatedSrcIP: + type: string + translatedDstIP: + type: string + tunnelDstIP: + type: string + egressIP: + type: string + egress: + type: string + capturedPacket: + properties: + srcIP: + type: string + dstIP: + type: string + length: + type: integer + ipHeader: + properties: + flags: + type: integer + protocol: + type: integer + ttl: + type: integer + type: object + ipv6Header: + properties: + hopLimit: + type: integer + nextHeader: + type: integer + type: object + transportHeader: + properties: + tcp: + properties: + dstPort: + type: integer + srcPort: + type: integer + flags: + type: integer + type: object + udp: + properties: + dstPort: + type: integer + srcPort: + type: integer + type: object + icmp: + properties: + id: + type: integer + sequence: + type: integer + type: object + type: object + type: object + subresources: + status: {} scope: Cluster names: plural: traceflows diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index fc2e48adc53..15abf875f12 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -106,7 +106,7 @@ func run(o *Options) error { informerFactory := informers.NewSharedInformerFactory(k8sClient, informerDefaultResync) crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, informerDefaultResync) - traceflowInformer := crdInformerFactory.Crd().V1alpha1().Traceflows() + traceflowInformer := crdInformerFactory.Crd().V1beta1().Traceflows() egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses() externalIPPoolInformer := crdInformerFactory.Crd().V1alpha2().ExternalIPPools() trafficControlInformer := crdInformerFactory.Crd().V1alpha2().TrafficControls() diff --git a/cmd/antrea-controller/controller.go b/cmd/antrea-controller/controller.go index 7bf2ae9c96d..0b23025aee2 100644 --- a/cmd/antrea-controller/controller.go +++ b/cmd/antrea-controller/controller.go @@ -136,7 +136,7 @@ func run(o *Options) error { eeInformer := crdInformerFactory.Crd().V1alpha2().ExternalEntities() anpInformer := crdInformerFactory.Crd().V1alpha1().NetworkPolicies() tierInformer := crdInformerFactory.Crd().V1alpha1().Tiers() - tfInformer := crdInformerFactory.Crd().V1alpha1().Traceflows() + tfInformer := crdInformerFactory.Crd().V1beta1().Traceflows() cgInformer := crdInformerFactory.Crd().V1alpha3().ClusterGroups() grpInformer := crdInformerFactory.Crd().V1alpha3().Groups() egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses() diff --git a/docs/api.md b/docs/api.md index 926930618d8..9f45709fbb6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -36,7 +36,7 @@ These are the CRDs currently available in `crd.antrea.io`. | `Group` | v1alpha3 | v1.8.0 | N/A | N/A | | `NetworkPolicy` | v1alpha1 | v1.0.0 | N/A | N/A | | `Tier` | v1alpha1 | v1.0.0 | N/A | N/A | -| `Traceflow` | v1alpha1 | v1.0.0 | N/A | N/A | +| `Traceflow` | v1beta1 | v1.13.0 | N/A | N/A | ### Other API groups @@ -70,6 +70,7 @@ These are the API group versions which are curently available when using Antrea. | CRD | CRD version | Introduced in | Deprecated in | Removed in | |---|---|---|---|---| | `ClusterGroup` | v1alpha2 | v1.0.0 | v1.1.0 | v1.12.0 [^1] | +| `Traceflow` | v1alpha2 | v1.0.0 | v1.13.0 | N/A | [^1]: The v1alpha2 version of the `ClusterGroup` CRD is no longer served by the apiserver in v1.12 and is completely removed in v1.13. diff --git a/docs/traceflow-guide.md b/docs/traceflow-guide.md index beb1ac16296..5cf8b5d4782 100644 --- a/docs/traceflow-guide.md +++ b/docs/traceflow-guide.md @@ -68,7 +68,7 @@ You can start a new trace by creating Traceflow CRD via kubectl and a YAML file configuration of Traceflow CRD. An example YAML file of Traceflow CRD might look like this: ```yaml -apiVersion: crd.antrea.io/v1alpha1 +apiVersion: crd.antrea.io/v1beta1 kind: Traceflow metadata: name: tf-test @@ -98,7 +98,7 @@ of destination Pod named `tcp-sts-2` using TCP protocol. Antrea Traceflow supports IPv6 traffic. An example YAML file of Traceflow CRD might look like this: ```yaml -apiVersion: crd.antrea.io/v1alpha1 +apiVersion: crd.antrea.io/v1beta1 kind: Traceflow metadata: name: tf-test-ipv6 @@ -149,7 +149,7 @@ The following example is a live-traffic Traceflow that captures a dropped UDP packet to UDP port 1234 of Pod udp-server, within 1 minute: ```yaml -apiVersion: crd.antrea.io/v1alpha1 +apiVersion: crd.antrea.io/v1beta1 kind: Traceflow metadata: name: tf-test diff --git a/pkg/agent/controller/traceflow/packetin.go b/pkg/agent/controller/traceflow/packetin.go index 766e56212a0..a9220117594 100644 --- a/pkg/agent/controller/traceflow/packetin.go +++ b/pkg/agent/controller/traceflow/packetin.go @@ -28,9 +28,11 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" "k8s.io/klog/v2" + "k8s.io/utils/pointer" "antrea.io/antrea/pkg/agent/openflow" crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" binding "antrea.io/antrea/pkg/ovs/openflow" ) @@ -59,7 +61,7 @@ func (c *Controller) HandlePacketIn(pktIn *ofctrl.PacketIn) error { if packet != nil { update.Status.CapturedPacket = packet } - _, err = c.traceflowClient.CrdV1alpha1().Traceflows().UpdateStatus(context.TODO(), update, v1.UpdateOptions{}) + _, err = c.traceflowClient.CrdV1beta1().Traceflows().UpdateStatus(context.TODO(), update, v1.UpdateOptions{}) if err != nil { return fmt.Errorf("update Traceflow failed: %w", err) } @@ -72,7 +74,7 @@ func (c *Controller) HandlePacketIn(pktIn *ofctrl.PacketIn) error { return nil } -func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Traceflow, *crdv1alpha1.NodeResult, *crdv1alpha1.Packet, error) { +func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1beta1.Traceflow, *crdv1beta1.NodeResult, *crdv1beta1.Packet, error) { matchers := pktIn.GetMatches() // Get data plane tag. @@ -132,7 +134,7 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl return nil, nil, nil, fmt.Errorf("Traceflow for dataplane tag %d not found in cache", tag) } - var capturedPacket *crdv1alpha1.Packet + var capturedPacket *crdv1beta1.Packet if tfState.liveTraffic { // Live Traceflow only considers the first packet of each // connection. However, it is possible for 2 connections to @@ -166,17 +168,17 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl ns = tf.Spec.Source.Namespace srcPod = tf.Spec.Source.Pod - obs := []crdv1alpha1.Observation{} + obs := []crdv1beta1.Observation{} tableID := pktIn.TableId if tfState.isSender { - ob := new(crdv1alpha1.Observation) - ob.Component = crdv1alpha1.ComponentSpoofGuard - ob.Action = crdv1alpha1.ActionForwarded + ob := new(crdv1beta1.Observation) + ob.Component = crdv1beta1.ComponentSpoofGuard + ob.Action = crdv1beta1.ActionForwarded obs = append(obs, *ob) } else { - ob := new(crdv1alpha1.Observation) - ob.Component = crdv1alpha1.ComponentForwarding - ob.Action = crdv1alpha1.ActionReceived + ob := new(crdv1beta1.Observation) + ob.Component = crdv1beta1.ComponentForwarding + ob.Action = crdv1beta1.ActionReceived obs = append(obs, *ob) } @@ -186,9 +188,9 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl // state is that ipSrc != ctNwSrc (in SNAT CT zone). The state in DNAT CT zone cannot be recognized in SNAT CT zone. if !tfState.receiverOnly { if isValidCtNw(ctNwDst) && ipDst != ctNwDst || isValidCtNw(ctNwSrc) && ipSrc != ctNwSrc { - ob := &crdv1alpha1.Observation{ - Component: crdv1alpha1.ComponentLB, - Action: crdv1alpha1.ActionForwarded, + ob := &crdv1beta1.Observation{ + Component: crdv1beta1.ComponentLB, + Action: crdv1beta1.ActionForwarded, TranslatedDstIP: ipDst, } if isValidCtNw(ctNwSrc) && ipSrc != ctNwSrc { @@ -238,7 +240,7 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl ob.NetworkPolicy = npRef.ToString() } if ruleRef.Action != nil && *ruleRef.Action == crdv1alpha1.RuleActionReject { - ob.Action = crdv1alpha1.ActionRejected + ob.Action = crdv1beta1.ActionRejected } } } @@ -250,7 +252,7 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl // Get output table. if tableID == openflow.L2ForwardingOutTable.GetID() { - ob := new(crdv1alpha1.Observation) + ob := new(crdv1beta1.Observation) tunnelDstIP := "" // decide according to packet. isIPv6 := etherData.Ethertype == protocol.IPv6_MSG @@ -290,9 +292,9 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl obs = append(obs, *obEgress) } ob.TunnelDstIP = tunnelDstIP - ob.Action = crdv1alpha1.ActionForwarded + ob.Action = crdv1beta1.ActionForwarded } else if ipDst == gatewayIP.String() && outputPort == gwPort { - ob.Action = crdv1alpha1.ActionDelivered + ob.Action = crdv1beta1.ActionDelivered } else if c.networkConfig.TrafficEncapMode.SupportsEncap() && outputPort == gwPort { var pktMark uint32 if match := getMatchPktMarkField(matchers); match != nil { @@ -316,19 +318,19 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1alpha1.Tracefl obEgress := getEgressObservation(true, egressIP, egress) obs = append(obs, *obEgress) } - ob.Action = crdv1alpha1.ActionForwardedOutOfOverlay + ob.Action = crdv1beta1.ActionForwardedOutOfOverlay } else if outputPort == gwPort { // noEncap - ob.Action = crdv1alpha1.ActionForwarded + ob.Action = crdv1beta1.ActionForwarded } else { // Output port is Pod port, packet is delivered. - ob.Action = crdv1alpha1.ActionDelivered + ob.Action = crdv1beta1.ActionDelivered } ob.ComponentInfo = openflow.L2ForwardingOutTable.GetName() - ob.Component = crdv1alpha1.ComponentForwarding + ob.Component = crdv1beta1.ComponentForwarding obs = append(obs, *ob) } - nodeResult := crdv1alpha1.NodeResult{Node: c.nodeConfig.Name, Timestamp: time.Now().Unix(), Observations: obs} + nodeResult := crdv1beta1.NodeResult{Node: c.nodeConfig.Name, Timestamp: time.Now().Unix(), Observations: obs} return tf, &nodeResult, capturedPacket, nil } @@ -408,36 +410,36 @@ func getCTSrcValue(matchers *ofctrl.Matchers, isIPv6 bool) (string, error) { return regValue.String(), nil } -func getNetworkPolicyObservation(tableID uint8, ingress bool) *crdv1alpha1.Observation { - ob := new(crdv1alpha1.Observation) - ob.Component = crdv1alpha1.ComponentNetworkPolicy +func getNetworkPolicyObservation(tableID uint8, ingress bool) *crdv1beta1.Observation { + ob := new(crdv1beta1.Observation) + ob.Component = crdv1beta1.ComponentNetworkPolicy if ingress { switch tableID { case openflow.IngressMetricTable.GetID(): // Packet dropped by ANP/default drop rule ob.ComponentInfo = openflow.IngressMetricTable.GetName() - ob.Action = crdv1alpha1.ActionDropped + ob.Action = crdv1beta1.ActionDropped case openflow.IngressDefaultTable.GetID(): // Packet dropped by ANP/default drop rule ob.ComponentInfo = openflow.IngressDefaultTable.GetName() - ob.Action = crdv1alpha1.ActionDropped + ob.Action = crdv1beta1.ActionDropped default: ob.ComponentInfo = openflow.IngressRuleTable.GetName() - ob.Action = crdv1alpha1.ActionForwarded + ob.Action = crdv1beta1.ActionForwarded } } else { switch tableID { case openflow.EgressMetricTable.GetID(): // Packet dropped by ANP/default drop rule ob.ComponentInfo = openflow.EgressMetricTable.GetName() - ob.Action = crdv1alpha1.ActionDropped + ob.Action = crdv1beta1.ActionDropped case openflow.EgressDefaultTable.GetID(): // Packet dropped by ANP/default drop rule ob.ComponentInfo = openflow.EgressDefaultTable.GetName() - ob.Action = crdv1alpha1.ActionDropped + ob.Action = crdv1beta1.ActionDropped default: ob.ComponentInfo = openflow.EgressRuleTable.GetName() - ob.Action = crdv1alpha1.ActionForwarded + ob.Action = crdv1beta1.ActionForwarded } } return ob @@ -456,36 +458,34 @@ func isValidCtNw(ipStr string) bool { return true } -func parseCapturedPacket(pktIn *ofctrl.PacketIn) *crdv1alpha1.Packet { +func parseCapturedPacket(pktIn *ofctrl.PacketIn) *crdv1beta1.Packet { pkt, _ := binding.ParsePacketIn(pktIn) - capturedPacket := crdv1alpha1.Packet{SrcIP: pkt.SourceIP.String(), DstIP: pkt.DestinationIP.String(), Length: pkt.IPLength} + capturedPacket := crdv1beta1.Packet{SrcIP: pkt.SourceIP.String(), DstIP: pkt.DestinationIP.String(), Length: pkt.IPLength} if pkt.IsIPv6 { ipProto := int32(pkt.IPProto) - capturedPacket.IPv6Header = &crdv1alpha1.IPv6Header{NextHeader: &ipProto, HopLimit: int32(pkt.TTL)} + capturedPacket.IPv6Header = &crdv1beta1.IPv6Header{NextHeader: &ipProto, HopLimit: int32(pkt.TTL)} } else { - capturedPacket.IPHeader.Protocol = int32(pkt.IPProto) - capturedPacket.IPHeader.TTL = int32(pkt.TTL) - capturedPacket.IPHeader.Flags = int32(pkt.IPFlags) + capturedPacket.IPHeader = &crdv1beta1.IPHeader{Protocol: int32(pkt.IPProto), TTL: int32(pkt.TTL), Flags: int32(pkt.IPFlags)} } if pkt.IPProto == protocol.Type_TCP { - capturedPacket.TransportHeader.TCP = &crdv1alpha1.TCPHeader{SrcPort: int32(pkt.SourcePort), DstPort: int32(pkt.DestinationPort), Flags: int32(pkt.TCPFlags)} + capturedPacket.TransportHeader.TCP = &crdv1beta1.TCPHeader{SrcPort: int32(pkt.SourcePort), DstPort: int32(pkt.DestinationPort), Flags: pointer.Int32(int32(pkt.TCPFlags))} } else if pkt.IPProto == protocol.Type_UDP { - capturedPacket.TransportHeader.UDP = &crdv1alpha1.UDPHeader{SrcPort: int32(pkt.SourcePort), DstPort: int32(pkt.DestinationPort)} + capturedPacket.TransportHeader.UDP = &crdv1beta1.UDPHeader{SrcPort: int32(pkt.SourcePort), DstPort: int32(pkt.DestinationPort)} } else if pkt.IPProto == protocol.Type_ICMP || pkt.IPProto == protocol.Type_IPv6ICMP { - capturedPacket.TransportHeader.ICMP = &crdv1alpha1.ICMPEchoRequestHeader{ID: int32(pkt.ICMPEchoID), Sequence: int32(pkt.ICMPEchoSeq)} + capturedPacket.TransportHeader.ICMP = &crdv1beta1.ICMPEchoRequestHeader{ID: int32(pkt.ICMPEchoID), Sequence: int32(pkt.ICMPEchoSeq)} } return &capturedPacket } -func getEgressObservation(isEgressNode bool, egressIP, egressName string) *crdv1alpha1.Observation { - ob := new(crdv1alpha1.Observation) - ob.Component = crdv1alpha1.ComponentEgress +func getEgressObservation(isEgressNode bool, egressIP, egressName string) *crdv1beta1.Observation { + ob := new(crdv1beta1.Observation) + ob.Component = crdv1beta1.ComponentEgress ob.EgressIP = egressIP ob.Egress = egressName if isEgressNode { - ob.Action = crdv1alpha1.ActionMarkedForSNAT + ob.Action = crdv1beta1.ActionMarkedForSNAT } else { - ob.Action = crdv1alpha1.ActionForwardedToEgressNode + ob.Action = crdv1beta1.ActionForwardedToEgressNode } return ob } diff --git a/pkg/agent/controller/traceflow/packetin_test.go b/pkg/agent/controller/traceflow/packetin_test.go index cca9b9e58c8..5d7f97d07f5 100644 --- a/pkg/agent/controller/traceflow/packetin_test.go +++ b/pkg/agent/controller/traceflow/packetin_test.go @@ -28,10 +28,11 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" "antrea.io/antrea/pkg/agent/config" "antrea.io/antrea/pkg/agent/openflow" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" ) var ( @@ -77,7 +78,7 @@ func Test_getNetworkPolicyObservation(t *testing.T) { tests := []struct { name string args args - want *crdv1alpha1.Observation + want *crdv1beta1.Observation }{ { name: "ingress metric drop", @@ -85,10 +86,10 @@ func Test_getNetworkPolicyObservation(t *testing.T) { tableID: openflow.IngressMetricTable.GetID(), ingress: true, }, - want: &crdv1alpha1.Observation{ - Component: crdv1alpha1.ComponentNetworkPolicy, + want: &crdv1beta1.Observation{ + Component: crdv1beta1.ComponentNetworkPolicy, ComponentInfo: "IngressMetric", - Action: crdv1alpha1.ActionDropped, + Action: crdv1beta1.ActionDropped, }, }, { @@ -97,10 +98,10 @@ func Test_getNetworkPolicyObservation(t *testing.T) { tableID: openflow.L2ForwardingOutTable.GetID(), ingress: true, }, - want: &crdv1alpha1.Observation{ - Component: crdv1alpha1.ComponentNetworkPolicy, + want: &crdv1beta1.Observation{ + Component: crdv1beta1.ComponentNetworkPolicy, ComponentInfo: "IngressRule", - Action: crdv1alpha1.ActionForwarded, + Action: crdv1beta1.ActionForwarded, }, }, { @@ -109,10 +110,10 @@ func Test_getNetworkPolicyObservation(t *testing.T) { tableID: openflow.EgressDefaultTable.GetID(), ingress: false, }, - want: &crdv1alpha1.Observation{ - Component: crdv1alpha1.ComponentNetworkPolicy, + want: &crdv1beta1.Observation{ + Component: crdv1beta1.ComponentNetworkPolicy, ComponentInfo: "EgressDefaultRule", - Action: crdv1alpha1.ActionDropped, + Action: crdv1beta1.ActionDropped, }, }, { @@ -121,10 +122,10 @@ func Test_getNetworkPolicyObservation(t *testing.T) { tableID: openflow.L2ForwardingOutTable.GetID(), ingress: false, }, - want: &crdv1alpha1.Observation{ - Component: crdv1alpha1.ComponentNetworkPolicy, + want: &crdv1beta1.Observation{ + Component: crdv1beta1.ComponentNetworkPolicy, ComponentInfo: "EgressRule", - Action: crdv1alpha1.ActionForwarded, + Action: crdv1beta1.ActionForwarded, }, }, } @@ -149,22 +150,22 @@ func TestParseCapturedPacket(t *testing.T) { bf := new(util.Buffer) bf.UnmarshalBinary(bytes) tcpPktIn.Data = bf - tcpPktCap := crdv1alpha1.Packet{ + tcpPktCap := crdv1beta1.Packet{ SrcIP: tcpPktIn.NWSrc.String(), DstIP: tcpPktIn.NWDst.String(), Length: tcpPktIn.Length, - IPHeader: crdv1alpha1.IPHeader{Protocol: int32(tcpPktIn.Protocol), TTL: int32(tcpPktIn.TTL), Flags: int32(tcpPktIn.Flags)}, - TransportHeader: crdv1alpha1.TransportHeader{ - TCP: &crdv1alpha1.TCPHeader{SrcPort: int32(tcp.PortSrc), DstPort: int32(tcp.PortDst), Flags: int32(tcp.Code)}, + IPHeader: &crdv1beta1.IPHeader{Protocol: int32(tcpPktIn.Protocol), TTL: int32(tcpPktIn.TTL), Flags: int32(tcpPktIn.Flags)}, + TransportHeader: crdv1beta1.TransportHeader{ + TCP: &crdv1beta1.TCPHeader{SrcPort: int32(tcp.PortSrc), DstPort: int32(tcp.PortDst), Flags: pointer.Int32(int32(tcp.Code))}, }, } udpPktIn := protocol.IPv4{Length: 50, Flags: 0, TTL: 128, NWSrc: srcIPv4, NWDst: dstIPv4, Protocol: protocol.Type_UDP} udp := protocol.UDP{PortSrc: 1080, PortDst: 80} udpPktIn.Data = &udp - udpPktCap := crdv1alpha1.Packet{ + udpPktCap := crdv1beta1.Packet{ SrcIP: udpPktIn.NWSrc.String(), DstIP: udpPktIn.NWDst.String(), Length: udpPktIn.Length, - IPHeader: crdv1alpha1.IPHeader{Protocol: int32(udpPktIn.Protocol), TTL: int32(udpPktIn.TTL), Flags: int32(udpPktIn.Flags)}, - TransportHeader: crdv1alpha1.TransportHeader{ - UDP: &crdv1alpha1.UDPHeader{SrcPort: int32(udp.PortSrc), DstPort: int32(udp.PortDst)}, + IPHeader: &crdv1beta1.IPHeader{Protocol: int32(udpPktIn.Protocol), TTL: int32(udpPktIn.TTL), Flags: int32(udpPktIn.Flags)}, + TransportHeader: crdv1beta1.TransportHeader{ + UDP: &crdv1beta1.UDPHeader{SrcPort: int32(udp.PortSrc), DstPort: int32(udp.PortDst)}, }, } @@ -173,16 +174,16 @@ func TestParseCapturedPacket(t *testing.T) { icmp := protocol.ICMP{Type: 128, Code: 0, Data: icmpEchoReq} icmpv6PktIn.Data = &icmp nextHdr := int32(icmpv6PktIn.NextHeader) - icmpv6PktCap := crdv1alpha1.Packet{ + icmpv6PktCap := crdv1beta1.Packet{ SrcIP: icmpv6PktIn.NWSrc.String(), DstIP: icmpv6PktIn.NWDst.String(), Length: icmpv6PktIn.Length + 40, - IPv6Header: &crdv1alpha1.IPv6Header{NextHeader: &nextHdr, HopLimit: int32(icmpv6PktIn.HopLimit)}, - TransportHeader: crdv1alpha1.TransportHeader{ICMP: &crdv1alpha1.ICMPEchoRequestHeader{ID: 1, Sequence: 123}}, + IPv6Header: &crdv1beta1.IPv6Header{NextHeader: &nextHdr, HopLimit: int32(icmpv6PktIn.HopLimit)}, + TransportHeader: crdv1beta1.TransportHeader{ICMP: &crdv1beta1.ICMPEchoRequestHeader{ID: 1, Sequence: 123}}, } tests := []struct { name string pktInData util.Message - pktCap *crdv1alpha1.Packet + pktCap *crdv1beta1.Packet isIPv6 bool }{ {"tcp", &tcpPktIn, &tcpPktCap, false}, @@ -261,8 +262,8 @@ func TestParsePacketIn(t *testing.T) { nodeConfig *config.NodeConfig tfState *traceflowState pktIn *ofctrl.PacketIn - expectedTf *crdv1alpha1.Traceflow - expectedNodeResult *crdv1alpha1.NodeResult + expectedTf *crdv1beta1.Traceflow + expectedNodeResult *crdv1beta1.NodeResult }{ { name: "packet at source Node for local Egress", @@ -289,40 +290,40 @@ func TestParsePacketIn(t *testing.T) { Data: util.NewBuffer(pktBytes), }, }, - expectedTf: &crdv1alpha1.Traceflow{ + expectedTf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "traceflow-pod-to-ipv4", }, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: dstIPv4, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, - expectedNodeResult: &crdv1alpha1.NodeResult{ - Observations: []crdv1alpha1.Observation{ + expectedNodeResult: &crdv1beta1.NodeResult{ + Observations: []crdv1beta1.Observation{ { - Component: crdv1alpha1.ComponentSpoofGuard, - Action: crdv1alpha1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, }, { - Component: crdv1alpha1.ComponentEgress, - Action: crdv1alpha1.ActionMarkedForSNAT, + Component: crdv1beta1.ComponentEgress, + Action: crdv1beta1.ActionMarkedForSNAT, Egress: egressName, EgressIP: egressIP, }, { - Component: crdv1alpha1.ComponentForwarding, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: openflow.L2ForwardingOutTable.GetName(), - Action: crdv1alpha1.ActionForwardedOutOfOverlay, + Action: crdv1beta1.ActionForwardedOutOfOverlay, }, }, }, @@ -352,40 +353,40 @@ func TestParsePacketIn(t *testing.T) { Data: util.NewBuffer(pktBytes), }, }, - expectedTf: &crdv1alpha1.Traceflow{ + expectedTf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "traceflow-pod-to-ipv4", }, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: dstIPv4, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, - expectedNodeResult: &crdv1alpha1.NodeResult{ - Observations: []crdv1alpha1.Observation{ + expectedNodeResult: &crdv1beta1.NodeResult{ + Observations: []crdv1beta1.Observation{ { - Component: crdv1alpha1.ComponentSpoofGuard, - Action: crdv1alpha1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, }, { - Component: crdv1alpha1.ComponentEgress, - Action: crdv1alpha1.ActionForwardedToEgressNode, + Component: crdv1beta1.ComponentEgress, + Action: crdv1beta1.ActionForwardedToEgressNode, Egress: egressName, EgressIP: egressIP, }, { - Component: crdv1alpha1.ComponentForwarding, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: openflow.L2ForwardingOutTable.GetName(), - Action: crdv1alpha1.ActionForwarded, + Action: crdv1beta1.ActionForwarded, TunnelDstIP: egressIP, }, }, @@ -415,39 +416,39 @@ func TestParsePacketIn(t *testing.T) { Data: util.NewBuffer(pktBytes), }, }, - expectedTf: &crdv1alpha1.Traceflow{ + expectedTf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "traceflow-pod-to-ipv4", }, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: dstIPv4, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, - expectedNodeResult: &crdv1alpha1.NodeResult{ - Observations: []crdv1alpha1.Observation{ + expectedNodeResult: &crdv1beta1.NodeResult{ + Observations: []crdv1beta1.Observation{ { - Component: crdv1alpha1.ComponentForwarding, - Action: crdv1alpha1.ActionReceived, + Component: crdv1beta1.ComponentForwarding, + Action: crdv1beta1.ActionReceived, }, { - Component: crdv1alpha1.ComponentEgress, - Action: crdv1alpha1.ActionMarkedForSNAT, + Component: crdv1beta1.ComponentEgress, + Action: crdv1beta1.ActionMarkedForSNAT, EgressIP: egressIP, }, { - Component: crdv1alpha1.ComponentForwarding, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: openflow.L2ForwardingOutTable.GetName(), - Action: crdv1alpha1.ActionForwardedOutOfOverlay, + Action: crdv1beta1.ActionForwardedOutOfOverlay, }, }, }, diff --git a/pkg/agent/controller/traceflow/traceflow_controller.go b/pkg/agent/controller/traceflow/traceflow_controller.go index a9d93b20d69..e46b9a875e4 100644 --- a/pkg/agent/controller/traceflow/traceflow_controller.go +++ b/pkg/agent/controller/traceflow/traceflow_controller.go @@ -39,10 +39,10 @@ import ( "antrea.io/antrea/pkg/agent/interfacestore" "antrea.io/antrea/pkg/agent/openflow" "antrea.io/antrea/pkg/agent/util" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" clientsetversioned "antrea.io/antrea/pkg/client/clientset/versioned" - crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha1" - crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha1" + crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" + crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1beta1" "antrea.io/antrea/pkg/features" binding "antrea.io/antrea/pkg/ovs/openflow" "antrea.io/antrea/pkg/ovs/ovsconfig" @@ -161,7 +161,7 @@ func NewTraceflowController( } // enqueueTraceflow adds an object to the controller work queue. -func (c *Controller) enqueueTraceflow(tf *crdv1alpha1.Traceflow) { +func (c *Controller) enqueueTraceflow(tf *crdv1beta1.Traceflow) { c.queue.Add(tf.Name) } @@ -188,19 +188,19 @@ func (c *Controller) Run(stopCh <-chan struct{}) { } func (c *Controller) addTraceflow(obj interface{}) { - tf := obj.(*crdv1alpha1.Traceflow) + tf := obj.(*crdv1beta1.Traceflow) klog.Infof("Processing Traceflow %s ADD event", tf.Name) c.enqueueTraceflow(tf) } func (c *Controller) updateTraceflow(_, curObj interface{}) { - tf := curObj.(*crdv1alpha1.Traceflow) + tf := curObj.(*crdv1beta1.Traceflow) klog.Infof("Processing Traceflow %s UPDATE event", tf.Name) c.enqueueTraceflow(tf) } func (c *Controller) deleteTraceflow(old interface{}) { - tf := old.(*crdv1alpha1.Traceflow) + tf := old.(*crdv1beta1.Traceflow) klog.Infof("Processing Traceflow %s DELETE event", tf.Name) c.enqueueTraceflow(tf) } @@ -266,7 +266,7 @@ func (c *Controller) syncTraceflow(traceflowName string) error { } switch tf.Status.Phase { - case crdv1alpha1.Running: + case crdv1beta1.Running: if tf.Status.DataplaneTag != 0 { start := false c.runningTraceflowsMutex.Lock() @@ -288,7 +288,7 @@ func (c *Controller) syncTraceflow(traceflowName string) error { // startTraceflow deploys OVS flow entries for Traceflow and inject packet if current Node // is Sender Node. -func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { +func (c *Controller) startTraceflow(tf *crdv1beta1.Traceflow) error { err := c.validateTraceflow(tf) defer func() { if err != nil { @@ -357,7 +357,7 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { klog.V(2).Infof("Installing flow entries for Traceflow %s", tf.Name) timeout := tf.Spec.Timeout if timeout == 0 { - timeout = crdv1alpha1.DefaultTraceflowTimeout + timeout = crdv1beta1.DefaultTraceflowTimeout } err = c.ofClient.InstallTraceflowFlows(tfState.tag, liveTraffic, tfState.droppedOnly, receiverOnly, matchPacket, ofPort, timeout) if err != nil { @@ -382,7 +382,7 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { return err } -func (c *Controller) validateTraceflow(tf *crdv1alpha1.Traceflow) error { +func (c *Controller) validateTraceflow(tf *crdv1beta1.Traceflow) error { if tf.Spec.Destination.Service != "" && !features.DefaultFeatureGate.Enabled(features.AntreaProxy) { return errors.New("using Service destination requires AntreaProxy feature enabled") } @@ -400,7 +400,7 @@ func (c *Controller) validateTraceflow(tf *crdv1alpha1.Traceflow) error { return nil } -func (c *Controller) preparePacket(tf *crdv1alpha1.Traceflow, intf *interfacestore.InterfaceConfig, receiverOnly bool) (*binding.Packet, error) { +func (c *Controller) preparePacket(tf *crdv1beta1.Traceflow, intf *interfacestore.InterfaceConfig, receiverOnly bool) (*binding.Packet, error) { liveTraffic := tf.Spec.LiveTraffic isICMP := false packet := new(binding.Packet) @@ -511,7 +511,7 @@ func (c *Controller) preparePacket(tf *crdv1alpha1.Traceflow, intf *interfacesto packet.TTL = uint8(tf.Spec.Packet.IPv6Header.HopLimit) packet.IPFlags = 0 } - } else { + } else if tf.Spec.Packet.IPHeader != nil { packet.IPProto = uint8(tf.Spec.Packet.IPHeader.Protocol) if !liveTraffic { packet.TTL = uint8(tf.Spec.Packet.IPHeader.TTL) @@ -527,11 +527,15 @@ func (c *Controller) preparePacket(tf *crdv1alpha1.Traceflow, intf *interfacesto packet.IPProto = protocol.Type_TCP packet.SourcePort = uint16(tf.Spec.Packet.TransportHeader.TCP.SrcPort) packet.DestinationPort = uint16(tf.Spec.Packet.TransportHeader.TCP.DstPort) - if tf.Spec.Packet.TransportHeader.TCP.Flags != 0 { - packet.TCPFlags = uint8(tf.Spec.Packet.TransportHeader.TCP.Flags) + if tf.Spec.Packet.TransportHeader.TCP.Flags != nil { + packet.TCPFlags = uint8(*tf.Spec.Packet.TransportHeader.TCP.Flags) } - if !liveTraffic && tf.Spec.Packet.TransportHeader.TCP.Flags == 0 { - packet.TCPFlags = uint8(2) + if !liveTraffic { + if tf.Spec.Packet.TransportHeader.TCP.Flags == nil { + packet.TCPFlags = uint8(2) + } else { + packet.TCPFlags = uint8(*tf.Spec.Packet.TransportHeader.TCP.Flags) + } } } else if tf.Spec.Packet.TransportHeader.UDP != nil { packet.IPProto = protocol.Type_UDP @@ -569,15 +573,15 @@ func (c *Controller) preparePacket(tf *crdv1alpha1.Traceflow, intf *interfacesto return packet, nil } -func (c *Controller) errorTraceflowCRD(tf *crdv1alpha1.Traceflow, reason string) (*crdv1alpha1.Traceflow, error) { - tf.Status.Phase = crdv1alpha1.Failed +func (c *Controller) errorTraceflowCRD(tf *crdv1beta1.Traceflow, reason string) (*crdv1beta1.Traceflow, error) { + tf.Status.Phase = crdv1beta1.Failed type Traceflow struct { - Status crdv1alpha1.TraceflowStatus `json:"status,omitempty"` + Status crdv1beta1.TraceflowStatus `json:"status,omitempty"` } - patchData := Traceflow{Status: crdv1alpha1.TraceflowStatus{Phase: tf.Status.Phase, Reason: reason}} + patchData := Traceflow{Status: crdv1beta1.TraceflowStatus{Phase: tf.Status.Phase, Reason: reason}} payloads, _ := json.Marshal(patchData) - return c.traceflowClient.CrdV1alpha1().Traceflows().Patch(context.TODO(), tf.Name, types.MergePatchType, payloads, metav1.PatchOptions{}, "status") + return c.traceflowClient.CrdV1beta1().Traceflows().Patch(context.TODO(), tf.Name, types.MergePatchType, payloads, metav1.PatchOptions{}, "status") } // Delete Traceflow from cache. diff --git a/pkg/agent/controller/traceflow/traceflow_controller_test.go b/pkg/agent/controller/traceflow/traceflow_controller_test.go index dffdd5f3bdd..61203af2c25 100644 --- a/pkg/agent/controller/traceflow/traceflow_controller_test.go +++ b/pkg/agent/controller/traceflow/traceflow_controller_test.go @@ -32,12 +32,13 @@ import ( "k8s.io/client-go/util/workqueue" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/klog/v2" + "k8s.io/utils/pointer" "antrea.io/antrea/pkg/agent/config" "antrea.io/antrea/pkg/agent/interfacestore" openflowtest "antrea.io/antrea/pkg/agent/openflow/testing" "antrea.io/antrea/pkg/agent/util" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake" crdinformers "antrea.io/antrea/pkg/client/informers/externalversions" "antrea.io/antrea/pkg/features" @@ -99,7 +100,7 @@ func newFakeTraceflowController(t *testing.T, initObjects []runtime.Object, netw mockOFClient := openflowtest.NewMockClient(controller) crdClient := fakeversioned.NewSimpleClientset(initObjects...) crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, 0) - traceflowInformer := crdInformerFactory.Crd().V1alpha1().Traceflows() + traceflowInformer := crdInformerFactory.Crd().V1beta1().Traceflows() ovsClient := ovsconfigtest.NewMockOVSBridgeClient(controller) ifaceStore := interfacestore.NewInterfaceStore() @@ -153,7 +154,7 @@ func addPodInterface(ifaceStore interfacestore.InterfaceStore, podNamespace, pod func TestPreparePacket(t *testing.T) { tcs := []struct { name string - tf *crdv1alpha1.Traceflow + tf *crdv1beta1.Traceflow intf *interfacestore.InterfaceConfig receiverOnly bool expectedPacket *binding.Packet @@ -161,14 +162,14 @@ func TestPreparePacket(t *testing.T) { }{ { name: "invalid destination IPv4", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf1", UID: "uid1"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: "1.1.1.300", }, }, @@ -177,10 +178,10 @@ func TestPreparePacket(t *testing.T) { }, { name: "empty destination with no live traffic", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf2", UID: "uid2"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, @@ -190,16 +191,17 @@ func TestPreparePacket(t *testing.T) { }, { name: "receive only from a source IPv4 to destination Pod1 in live traffic traceflow", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf3", UID: "uid3"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ IP: "192.168.12.4", }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Pod: pod1.Name, }, LiveTraffic: true, + Packet: crdv1beta1.Packet{IPHeader: &crdv1beta1.IPHeader{}}, }, }, receiverOnly: true, @@ -210,23 +212,23 @@ func TestPreparePacket(t *testing.T) { }, { name: "tcp packet", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf4", UID: "uid4"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, - Packet: crdv1alpha1.Packet{ - TransportHeader: crdv1alpha1.TransportHeader{ - TCP: &crdv1alpha1.TCPHeader{ + Packet: crdv1beta1.Packet{ + TransportHeader: crdv1beta1.TransportHeader{ + TCP: &crdv1beta1.TCPHeader{ SrcPort: 80, DstPort: 81, - Flags: 11, + Flags: pointer.Int32(11), }, }, }, @@ -246,20 +248,20 @@ func TestPreparePacket(t *testing.T) { }, { name: "tcp packet without flag", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf4", UID: "uid4"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, - Packet: crdv1alpha1.Packet{ - TransportHeader: crdv1alpha1.TransportHeader{ - TCP: &crdv1alpha1.TCPHeader{ + Packet: crdv1beta1.Packet{ + TransportHeader: crdv1beta1.TransportHeader{ + TCP: &crdv1beta1.TCPHeader{ SrcPort: 80, DstPort: 81, }, @@ -281,20 +283,20 @@ func TestPreparePacket(t *testing.T) { }, { name: "udp packet", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf5", UID: "uid5"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, - Packet: crdv1alpha1.Packet{ - TransportHeader: crdv1alpha1.TransportHeader{ - UDP: &crdv1alpha1.UDPHeader{ + Packet: crdv1beta1.Packet{ + TransportHeader: crdv1beta1.TransportHeader{ + UDP: &crdv1beta1.UDPHeader{ SrcPort: 90, DstPort: 100, }, @@ -315,20 +317,20 @@ func TestPreparePacket(t *testing.T) { }, { name: "icmp packet", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf6", UID: "uid6"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, - Packet: crdv1alpha1.Packet{ - TransportHeader: crdv1alpha1.TransportHeader{ - ICMP: &crdv1alpha1.ICMPEchoRequestHeader{ + Packet: crdv1beta1.Packet{ + TransportHeader: crdv1beta1.TransportHeader{ + ICMP: &crdv1beta1.ICMPEchoRequestHeader{ ID: 10, Sequence: 20, }, @@ -350,7 +352,7 @@ func TestPreparePacket(t *testing.T) { }, { name: "source Pod without IPv4 address", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf7", UID: "uid7"}, }, intf: &interfacestore.InterfaceConfig{}, @@ -358,11 +360,11 @@ func TestPreparePacket(t *testing.T) { }, { name: "source Pod without IPv6 address", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf8", UID: "uid8"}, - Spec: crdv1alpha1.TraceflowSpec{ - Packet: crdv1alpha1.Packet{ - IPv6Header: &crdv1alpha1.IPv6Header{}, + Spec: crdv1beta1.TraceflowSpec{ + Packet: crdv1beta1.Packet{ + IPv6Header: &crdv1beta1.IPv6Header{}, }, }, }, @@ -371,15 +373,15 @@ func TestPreparePacket(t *testing.T) { }, { name: "destination IP family different from packet", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf9", UID: "uid9"}, - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ IP: "192.168.1.2", }, LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPv6Header: &crdv1alpha1.IPv6Header{}, + Packet: crdv1beta1.Packet{ + IPv6Header: &crdv1beta1.IPv6Header{}, }, }, }, @@ -387,15 +389,15 @@ func TestPreparePacket(t *testing.T) { }, { name: "source IP family different from packet for receiver only case", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf10", UID: "uid10"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ IP: "192.168.1.2", }, LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPv6Header: &crdv1alpha1.IPv6Header{}, + Packet: crdv1beta1.Packet{ + IPv6Header: &crdv1beta1.IPv6Header{}, }, }, }, @@ -404,10 +406,10 @@ func TestPreparePacket(t *testing.T) { }, { name: "destination Pod unavailable", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf11", UID: "uid11"}, - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ Pod: "unknown pod", Namespace: "default", }, @@ -417,10 +419,10 @@ func TestPreparePacket(t *testing.T) { }, { name: "destination Pod without IPv4 address in live traffic traceflow", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf12", UID: "uid12"}, - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ Pod: pod3.Name, Namespace: pod3.Namespace, }, @@ -431,16 +433,16 @@ func TestPreparePacket(t *testing.T) { }, { name: "destination Pod without IPv6 address in live traffic traceflow", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf13", UID: "uid13"}, - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ Pod: pod3.Name, Namespace: pod3.Namespace, }, LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPv6Header: &crdv1alpha1.IPv6Header{}, + Packet: crdv1beta1.Packet{ + IPv6Header: &crdv1beta1.IPv6Header{}, }, }, }, @@ -448,19 +450,19 @@ func TestPreparePacket(t *testing.T) { }, { name: "Pod-to-IPv6 liveTraffic traceflow", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf14", UID: "uid14"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: "2001:db8::68", }, LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPv6Header: &crdv1alpha1.IPv6Header{ + Packet: crdv1beta1.Packet{ + IPv6Header: &crdv1beta1.IPv6Header{ NextHeader: &protocolICMPv6, }, }, @@ -495,29 +497,29 @@ func TestPreparePacket(t *testing.T) { } func TestErrTraceflowCRD(t *testing.T) { - tf := &crdv1alpha1.Traceflow{ + tf := &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "tf", UID: "uid", }, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, } expectedTf := tf reason := "failed" - expectedTf.Status.Phase = crdv1alpha1.Failed + expectedTf.Status.Phase = crdv1beta1.Failed expectedTf.Status.Reason = reason tfc := newFakeTraceflowController(t, []runtime.Object{tf}, nil, nil, nil, nil) @@ -530,7 +532,7 @@ func TestErrTraceflowCRD(t *testing.T) { func TestStartTraceflow(t *testing.T) { tcs := []struct { name string - tf *crdv1alpha1.Traceflow + tf *crdv1beta1.Traceflow ofPort uint32 receiverOnly bool packet *binding.Packet @@ -541,20 +543,20 @@ func TestStartTraceflow(t *testing.T) { }{ { name: "Pod-to-Pod traceflow", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf1", UID: "uid1"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, @@ -569,7 +571,7 @@ func TestStartTraceflow(t *testing.T) { ICMPType: 8, }, expectedCalls: func(mockOFClient *openflowtest.MockClient) { - mockOFClient.EXPECT().InstallTraceflowFlows(uint8(1), false, false, false, nil, ofPortPod1, crdv1alpha1.DefaultTraceflowTimeout) + mockOFClient.EXPECT().InstallTraceflowFlows(uint8(1), false, false, false, nil, ofPortPod1, crdv1beta1.DefaultTraceflowTimeout) mockOFClient.EXPECT().SendTraceflowPacket(uint8(1), &binding.Packet{ SourceIP: net.ParseIP(pod1IPv4), SourceMAC: pod1MAC, @@ -583,19 +585,19 @@ func TestStartTraceflow(t *testing.T) { }, { name: "Pod-to-IPv4 traceflow", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf2", UID: "uid2"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: dstIPv4, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, @@ -609,7 +611,7 @@ func TestStartTraceflow(t *testing.T) { ICMPType: 8, }, expectedCalls: func(mockOFClient *openflowtest.MockClient) { - mockOFClient.EXPECT().InstallTraceflowFlows(uint8(1), false, false, false, nil, ofPortPod1, crdv1alpha1.DefaultTraceflowTimeout) + mockOFClient.EXPECT().InstallTraceflowFlows(uint8(1), false, false, false, nil, ofPortPod1, crdv1beta1.DefaultTraceflowTimeout) mockOFClient.EXPECT().SendTraceflowPacket(uint8(1), &binding.Packet{ SourceIP: net.ParseIP(pod1IPv4), SourceMAC: pod1MAC, @@ -622,17 +624,17 @@ func TestStartTraceflow(t *testing.T) { }, { name: "empty source and destination Pod", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf3", UID: "uid3"}, }, expectedErrLog: "Traceflow tf3 has neither source nor destination Pod specified", }, { name: "empty source Pod", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf4", UID: "uid4"}, - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, @@ -642,19 +644,19 @@ func TestStartTraceflow(t *testing.T) { }, { name: "invalid destination IPv4", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf5", UID: "uid5"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: "192.168.1.300", }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, @@ -665,23 +667,23 @@ func TestStartTraceflow(t *testing.T) { }, { name: "live traceflow receive only", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf6", UID: "uid6"}, - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, LiveTraffic: true, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, ofPort: ofPortPod2, expectedCalls: func(mockOFClient *openflowtest.MockClient) { - mockOFClient.EXPECT().InstallTraceflowFlows(uint8(1), true, false, true, &binding.Packet{DestinationMAC: pod2MAC}, ofPortPod2, crdv1alpha1.DefaultTraceflowTimeout) + mockOFClient.EXPECT().InstallTraceflowFlows(uint8(1), true, false, true, &binding.Packet{DestinationMAC: pod2MAC}, ofPortPod2, crdv1beta1.DefaultTraceflowTimeout) }, }, } @@ -717,26 +719,26 @@ func TestStartTraceflow(t *testing.T) { func TestSyncTraceflow(t *testing.T) { tcs := []struct { name string - tf *crdv1alpha1.Traceflow + tf *crdv1beta1.Traceflow tfState *traceflowState expectedCalls func(mockOFClient *openflowtest.MockClient) }{ { name: "traceflow in running phase", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf1", UID: "uid1"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, @@ -747,20 +749,20 @@ func TestSyncTraceflow(t *testing.T) { }, { name: "traceflow in failed phase", - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf1", UID: "uid1"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Failed, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Failed, DataplaneTag: 1, }, }, @@ -795,26 +797,26 @@ func TestSyncTraceflow(t *testing.T) { func TestProcessTraceflowItem(t *testing.T) { tc := struct { - tf *crdv1alpha1.Traceflow + tf *crdv1beta1.Traceflow ofPort uint32 receiverOnly bool packet *binding.Packet expected bool }{ - tf: &crdv1alpha1.Traceflow{ + tf: &crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf1", UID: "uid1"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{ + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{ Namespace: pod1.Namespace, Pod: pod1.Name, }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: pod2.Namespace, Pod: pod2.Name, }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Running, + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Running, DataplaneTag: 1, }, }, @@ -837,7 +839,7 @@ func TestProcessTraceflowItem(t *testing.T) { tfc.crdInformerFactory.Start(stopCh) tfc.crdInformerFactory.WaitForCacheSync(stopCh) - tfc.mockOFClient.EXPECT().InstallTraceflowFlows(tc.tf.Status.DataplaneTag, tc.tf.Spec.LiveTraffic, tc.tf.Spec.DroppedOnly, tc.receiverOnly, nil, tc.ofPort, crdv1alpha1.DefaultTraceflowTimeout) + tfc.mockOFClient.EXPECT().InstallTraceflowFlows(tc.tf.Status.DataplaneTag, tc.tf.Spec.LiveTraffic, tc.tf.Spec.DroppedOnly, tc.receiverOnly, nil, tc.ofPort, crdv1beta1.DefaultTraceflowTimeout) tfc.mockOFClient.EXPECT().SendTraceflowPacket(tc.tf.Status.DataplaneTag, tc.packet, tc.ofPort, int32(-1)) tfc.enqueueTraceflow(tc.tf) got := tfc.processTraceflowItem() @@ -847,15 +849,15 @@ func TestProcessTraceflowItem(t *testing.T) { func TestValidateTraceflow(t *testing.T) { tcs := []struct { name string - tf *crdv1alpha1.Traceflow + tf *crdv1beta1.Traceflow antreaProxyEnabled bool expectedErr string }{ { name: "AntreaProxy feature disabled with destination as service", - tf: &crdv1alpha1.Traceflow{ - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + tf: &crdv1beta1.Traceflow{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ Service: "svcTest", }, }, @@ -864,9 +866,9 @@ func TestValidateTraceflow(t *testing.T) { }, { name: "invalid destination IPv4", - tf: &crdv1alpha1.Traceflow{ - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + tf: &crdv1beta1.Traceflow{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ IP: "192.168.1.300", }, }, @@ -876,9 +878,9 @@ func TestValidateTraceflow(t *testing.T) { }, { name: "AntreaProxy feature disabled with ClusterIP destination", - tf: &crdv1alpha1.Traceflow{ - Spec: crdv1alpha1.TraceflowSpec{ - Destination: crdv1alpha1.Destination{ + tf: &crdv1beta1.Traceflow{ + Spec: crdv1beta1.TraceflowSpec{ + Destination: crdv1beta1.Destination{ IP: "10.96.1.1", }, }, diff --git a/pkg/apis/crd/v1beta1/register.go b/pkg/apis/crd/v1beta1/register.go index 7ff2c5e2d64..43c283d31e9 100644 --- a/pkg/apis/crd/v1beta1/register.go +++ b/pkg/apis/crd/v1beta1/register.go @@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &AntreaControllerInfoList{}, &AntreaAgentInfo{}, &AntreaAgentInfoList{}, + &Traceflow{}, + &TraceflowList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1beta1/traceflow_types.go b/pkg/apis/crd/v1beta1/traceflow_types.go new file mode 100644 index 00000000000..c2dfa32dfd0 --- /dev/null +++ b/pkg/apis/crd/v1beta1/traceflow_types.go @@ -0,0 +1,283 @@ +// Copyright 2023 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. + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type TraceflowPhase string + +const ( + // Pending is not used anymore + Pending TraceflowPhase = "Pending" + Running TraceflowPhase = "Running" + Succeeded TraceflowPhase = "Succeeded" + Failed TraceflowPhase = "Failed" +) + +type TraceflowComponent string + +const ( + ComponentSpoofGuard TraceflowComponent = "SpoofGuard" + ComponentLB TraceflowComponent = "LB" + ComponentRouting TraceflowComponent = "Routing" + ComponentNetworkPolicy TraceflowComponent = "NetworkPolicy" + ComponentForwarding TraceflowComponent = "Forwarding" + ComponentEgress TraceflowComponent = "Egress" +) + +type TraceflowAction string + +const ( + ActionDelivered TraceflowAction = "Delivered" + ActionReceived TraceflowAction = "Received" + ActionForwarded TraceflowAction = "Forwarded" + ActionDropped TraceflowAction = "Dropped" + ActionRejected TraceflowAction = "Rejected" + // ActionForwardedOutOfOverlay indicates that the packet has been forwarded out of the network + // managed by Antrea. This indicates that the Traceflow request can be considered complete. + ActionForwardedOutOfOverlay TraceflowAction = "ForwardedOutOfOverlay" + ActionMarkedForSNAT TraceflowAction = "MarkedForSNAT" + ActionForwardedToEgressNode TraceflowAction = "ForwardedToEgressNode" +) + +// List the supported protocols and their codes in traceflow. +// According to code in Antrea agent and controller, default protocol is ICMP if protocol is not inputted by users. +const ( + ICMPProtocolNumber int32 = 1 + IGMPProtocolNumber int32 = 2 + TCPProtocolNumber int32 = 6 + UDPProtocolNumber int32 = 17 + SCTPProtocolNumber int32 = 132 +) + +var SupportedProtocols = map[string]int32{ + "TCP": TCPProtocolNumber, + "UDP": UDPProtocolNumber, + "ICMP": ICMPProtocolNumber, +} + +var ProtocolsToString = map[int32]string{ + TCPProtocolNumber: "TCP", + UDPProtocolNumber: "UDP", + ICMPProtocolNumber: "ICMP", + IGMPProtocolNumber: "IGMP", + SCTPProtocolNumber: "SCTP", +} + +// List the supported destination types in traceflow. +const ( + DstTypePod = "Pod" + DstTypeService = "Service" + DstTypeIPv4 = "IPv4" +) + +var SupportedDestinationTypes = []string{ + DstTypePod, + DstTypeService, + DstTypeIPv4, +} + +// List the ethernet types. +const ( + EtherTypeIPv4 uint16 = 0x0800 + EtherTypeIPv6 uint16 = 0x86DD +) + +// Default timeout in seconds. +const DefaultTraceflowTimeout uint16 = 20 + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type Traceflow struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec TraceflowSpec `json:"spec,omitempty"` + Status TraceflowStatus `json:"status,omitempty"` +} + +// TraceflowSpec describes the spec of the traceflow. +type TraceflowSpec struct { + Source Source `json:"source,omitempty"` + Destination Destination `json:"destination,omitempty"` + Packet Packet `json:"packet,omitempty"` + // LiveTraffic indicates the Traceflow is to trace the live traffic + // rather than an injected packet, when set to true. The first packet of + // the first connection that matches the packet spec will be traced. + LiveTraffic bool `json:"liveTraffic,omitempty"` + // DroppedOnly indicates only the dropped packet should be captured in a + // live-traffic Traceflow. + DroppedOnly bool `json:"droppedOnly,omitempty"` + // Timeout specifies the timeout of the Traceflow in seconds. Defaults + // to 20 seconds if not set. + Timeout uint16 `json:"timeout,omitempty"` +} + +// Source describes the source spec of the traceflow. +type Source struct { + // Namespace is the source namespace. + Namespace string `json:"namespace,omitempty"` + // Pod is the source pod. + Pod string `json:"pod,omitempty"` + // IP is the source IPv4 or IPv6 address. IP as the source is supported + // only for live-traffic Traceflow. + IP string `json:"ip,omitempty"` +} + +// Destination describes the destination spec of the traceflow. +type Destination struct { + // Namespace is the destination namespace. + Namespace string `json:"namespace,omitempty"` + // Pod is the destination pod, exclusive with destination service. + Pod string `json:"pod,omitempty"` + // Service is the destination service, exclusive with destination pod. + Service string `json:"service,omitempty"` + // IP is the destination IPv4 or IPv6 address. + IP string `json:"ip,omitempty"` +} + +// IPHeader describes spec of an IPv4 header. +type IPHeader struct { + // Protocol is the IP protocol. + Protocol int32 `json:"protocol,omitempty" yaml:"protocol,omitempty"` + // TTL is the IP TTL. + TTL int32 `json:"ttl,omitempty" yaml:"ttl,omitempty"` + // Flags is the flags for IP. + Flags int32 `json:"flags,omitempty" yaml:"flags,omitempty"` +} + +// IPv6Header describes spec of an IPv6 header. +type IPv6Header struct { + // NextHeader is the IPv6 protocol. + NextHeader *int32 `json:"nextHeader,omitempty" yaml:"nextHeader,omitempty"` + // HopLimit is the IPv6 Hop Limit. + HopLimit int32 `json:"hopLimit,omitempty" yaml:"hopLimit,omitempty"` +} + +// TransportHeader describes spec of a TransportHeader. +type TransportHeader struct { + ICMP *ICMPEchoRequestHeader `json:"icmp,omitempty" yaml:"icmp,omitempty"` + UDP *UDPHeader `json:"udp,omitempty" yaml:"udp,omitempty"` + TCP *TCPHeader `json:"tcp,omitempty" yaml:"tcp,omitempty"` +} + +// ICMPEchoRequestHeader describes spec of an ICMP echo request header. +type ICMPEchoRequestHeader struct { + // ID is the ICMPEchoRequestHeader ID. + ID int32 `json:"id,omitempty"` + // Sequence is the ICMPEchoRequestHeader sequence. + Sequence int32 `json:"sequence,omitempty"` +} + +// UDPHeader describes spec of a UDP header. +type UDPHeader struct { + // SrcPort is the source port. + SrcPort int32 `json:"srcPort,omitempty"` + // DstPort is the destination port. + DstPort int32 `json:"dstPort,omitempty"` +} + +// TCPHeader describes spec of a TCP header. +type TCPHeader struct { + // SrcPort is the source port. + SrcPort int32 `json:"srcPort,omitempty"` + // DstPort is the destination port. + DstPort int32 `json:"dstPort,omitempty"` + // Flags are flags in the header. + Flags *int32 `json:"flags,omitempty"` +} + +// Packet includes header info. +type Packet struct { + SrcIP string `json:"srcIP,omitempty"` + DstIP string `json:"dstIP,omitempty"` + // Length is the IP packet length (includes the IPv4 or IPv6 header length). + Length uint16 `json:"length,omitempty"` + IPHeader *IPHeader `json:"ipHeader,omitempty"` + IPv6Header *IPv6Header `json:"ipv6Header,omitempty"` + TransportHeader TransportHeader `json:"transportHeader,omitempty"` +} + +// TraceflowStatus describes current status of the traceflow. +type TraceflowStatus struct { + // Phase is the Traceflow phase. + Phase TraceflowPhase `json:"phase,omitempty"` + // Reason is a message indicating the reason of the traceflow's current phase. + Reason string `json:"reason,omitempty"` + // StartTime is the time at which the Traceflow as started by the Antrea Controller. + // Before K8s v1.20, null values (field not set) are not pruned, and a CR where a + // metav1.Time field is not set would fail OpenAPI validation (type string). The + // recommendation seems to be to use a pointer instead, and the field will be omitted when + // serializing. + // See https://github.com/kubernetes/kubernetes/issues/86811 + StartTime *metav1.Time `json:"startTime,omitempty"` + // DataplaneTag is a tag to identify a traceflow session across Nodes. + DataplaneTag uint8 `json:"dataplaneTag,omitempty"` + // Results is the collection of all observations on different nodes. + Results []NodeResult `json:"results,omitempty"` + // CapturedPacket is the captured packet in live-traffic Traceflow. + CapturedPacket *Packet `json:"capturedPacket,omitempty"` +} + +type NodeResult struct { + // Node is the node of the observation. + Node string `json:"node,omitempty" yaml:"node,omitempty"` + // Role of the node like sender, receiver, etc. + Role string `json:"role,omitempty" yaml:"role,omitempty"` + // Timestamp is the timestamp of the observations on the node. + Timestamp int64 `json:"timestamp,omitempty" yaml:"timestamp,omitempty"` + // Observations includes all observations from sender nodes, receiver ones, etc. + Observations []Observation `json:"observations,omitempty" yaml:"observations,omitempty"` +} + +// Observation describes those from sender nodes or receiver nodes. +type Observation struct { + // Component is the observation component. + Component TraceflowComponent `json:"component,omitempty" yaml:"component,omitempty"` + // ComponentInfo is the extension of Component field. + ComponentInfo string `json:"componentInfo,omitempty" yaml:"componentInfo,omitempty"` + // Action is the action to the observation. + Action TraceflowAction `json:"action,omitempty" yaml:"action,omitempty"` + // Pod is the combination of Pod name and Pod Namespace. + Pod string `json:"pod,omitempty" yaml:"pod,omitempty"` + // DstMAC is the destination MAC. + DstMAC string `json:"dstMAC,omitempty" yaml:"dstMAC,omitempty"` + // NetworkPolicy is the combination of Namespace and NetworkPolicyName. + NetworkPolicy string `json:"networkPolicy,omitempty" yaml:"networkPolicy,omitempty"` + // Egress is the name of the Egress. + Egress string `json:"egress,omitempty" yaml:"egress,omitempty"` + // TTL is the observation TTL. + TTL int32 `json:"ttl,omitempty" yaml:"ttl,omitempty"` + // TranslatedSrcIP is the translated source IP. + TranslatedSrcIP string `json:"translatedSrcIP,omitempty" yaml:"translatedSrcIP,omitempty"` + // TranslatedDstIP is the translated destination IP. + TranslatedDstIP string `json:"translatedDstIP,omitempty" yaml:"translatedDstIP,omitempty"` + // TunnelDstIP is the tunnel destination IP. + TunnelDstIP string `json:"tunnelDstIP,omitempty" yaml:"tunnelDstIP,omitempty"` + EgressIP string `json:"egressIP,omitempty" yaml:"egressIP,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type TraceflowList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + + Items []Traceflow `json:"items"` +} diff --git a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go index a66a7eb4be8..21f646a0da5 100644 --- a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -202,6 +202,75 @@ func (in *ControllerCondition) DeepCopy() *ControllerCondition { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Destination) DeepCopyInto(out *Destination) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Destination. +func (in *Destination) DeepCopy() *Destination { + if in == nil { + return nil + } + out := new(Destination) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ICMPEchoRequestHeader) DeepCopyInto(out *ICMPEchoRequestHeader) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ICMPEchoRequestHeader. +func (in *ICMPEchoRequestHeader) DeepCopy() *ICMPEchoRequestHeader { + if in == nil { + return nil + } + out := new(ICMPEchoRequestHeader) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPHeader) DeepCopyInto(out *IPHeader) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPHeader. +func (in *IPHeader) DeepCopy() *IPHeader { + if in == nil { + return nil + } + out := new(IPHeader) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPv6Header) DeepCopyInto(out *IPv6Header) { + *out = *in + if in.NextHeader != nil { + in, out := &in.NextHeader, &out.NextHeader + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPv6Header. +func (in *IPv6Header) DeepCopy() *IPv6Header { + if in == nil { + return nil + } + out := new(IPv6Header) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkPolicyControllerInfo) DeepCopyInto(out *NetworkPolicyControllerInfo) { *out = *in @@ -218,6 +287,27 @@ func (in *NetworkPolicyControllerInfo) DeepCopy() *NetworkPolicyControllerInfo { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeResult) DeepCopyInto(out *NodeResult) { + *out = *in + if in.Observations != nil { + in, out := &in.Observations, &out.Observations + *out = make([]Observation, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeResult. +func (in *NodeResult) DeepCopy() *NodeResult { + if in == nil { + return nil + } + out := new(NodeResult) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OVSInfo) DeepCopyInto(out *OVSInfo) { *out = *in @@ -240,3 +330,237 @@ func (in *OVSInfo) DeepCopy() *OVSInfo { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Observation) DeepCopyInto(out *Observation) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Observation. +func (in *Observation) DeepCopy() *Observation { + if in == nil { + return nil + } + out := new(Observation) + in.DeepCopyInto(out) + 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.IPHeader != nil { + in, out := &in.IPHeader, &out.IPHeader + *out = new(IPHeader) + **out = **in + } + if in.IPv6Header != nil { + in, out := &in.IPv6Header, &out.IPv6Header + *out = new(IPv6Header) + (*in).DeepCopyInto(*out) + } + 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 *Source) DeepCopyInto(out *Source) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Source. +func (in *Source) DeepCopy() *Source { + if in == nil { + return nil + } + out := new(Source) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TCPHeader) DeepCopyInto(out *TCPHeader) { + *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 *Traceflow) DeepCopyInto(out *Traceflow) { + *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 Traceflow. +func (in *Traceflow) DeepCopy() *Traceflow { + if in == nil { + return nil + } + out := new(Traceflow) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Traceflow) 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 *TraceflowList) DeepCopyInto(out *TraceflowList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Traceflow, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TraceflowList. +func (in *TraceflowList) DeepCopy() *TraceflowList { + if in == nil { + return nil + } + out := new(TraceflowList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TraceflowList) 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 *TraceflowSpec) DeepCopyInto(out *TraceflowSpec) { + *out = *in + out.Source = in.Source + out.Destination = in.Destination + in.Packet.DeepCopyInto(&out.Packet) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TraceflowSpec. +func (in *TraceflowSpec) DeepCopy() *TraceflowSpec { + if in == nil { + return nil + } + out := new(TraceflowSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TraceflowStatus) DeepCopyInto(out *TraceflowStatus) { + *out = *in + if in.StartTime != nil { + in, out := &in.StartTime, &out.StartTime + *out = (*in).DeepCopy() + } + if in.Results != nil { + in, out := &in.Results, &out.Results + *out = make([]NodeResult, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.CapturedPacket != nil { + in, out := &in.CapturedPacket, &out.CapturedPacket + *out = new(Packet) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TraceflowStatus. +func (in *TraceflowStatus) DeepCopy() *TraceflowStatus { + if in == nil { + return nil + } + out := new(TraceflowStatus) + 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.ICMP != nil { + in, out := &in.ICMP, &out.ICMP + *out = new(ICMPEchoRequestHeader) + **out = **in + } + if in.UDP != nil { + in, out := &in.UDP, &out.UDP + *out = new(UDPHeader) + **out = **in + } + if in.TCP != nil { + in, out := &in.TCP, &out.TCP + *out = new(TCPHeader) + **out = **in + } + 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 + 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/apiserver/openapi/zz_generated.openapi.go b/pkg/apiserver/openapi/zz_generated.openapi.go index 77166dea850..237679c783d 100644 --- a/pkg/apiserver/openapi/zz_generated.openapi.go +++ b/pkg/apiserver/openapi/zz_generated.openapi.go @@ -78,8 +78,23 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "antrea.io/antrea/pkg/apis/crd/v1beta1.AntreaControllerInfo": schema_pkg_apis_crd_v1beta1_AntreaControllerInfo(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.AntreaControllerInfoList": schema_pkg_apis_crd_v1beta1_AntreaControllerInfoList(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.ControllerCondition": schema_pkg_apis_crd_v1beta1_ControllerCondition(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.Destination": schema_pkg_apis_crd_v1beta1_Destination(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.ICMPEchoRequestHeader": schema_pkg_apis_crd_v1beta1_ICMPEchoRequestHeader(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPHeader": schema_pkg_apis_crd_v1beta1_IPHeader(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPv6Header": schema_pkg_apis_crd_v1beta1_IPv6Header(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.NetworkPolicyControllerInfo": schema_pkg_apis_crd_v1beta1_NetworkPolicyControllerInfo(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.NodeResult": schema_pkg_apis_crd_v1beta1_NodeResult(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.OVSInfo": schema_pkg_apis_crd_v1beta1_OVSInfo(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.Observation": schema_pkg_apis_crd_v1beta1_Observation(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.Packet": schema_pkg_apis_crd_v1beta1_Packet(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.Source": schema_pkg_apis_crd_v1beta1_Source(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TCPHeader": schema_pkg_apis_crd_v1beta1_TCPHeader(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.Traceflow": schema_pkg_apis_crd_v1beta1_Traceflow(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowList": schema_pkg_apis_crd_v1beta1_TraceflowList(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowSpec": schema_pkg_apis_crd_v1beta1_TraceflowSpec(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowStatus": schema_pkg_apis_crd_v1beta1_TraceflowStatus(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TransportHeader": schema_pkg_apis_crd_v1beta1_TransportHeader(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.UDPHeader": schema_pkg_apis_crd_v1beta1_UDPHeader(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaClusterNetworkPolicyStats": schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStats(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaClusterNetworkPolicyStatsList": schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStatsList(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaNetworkPolicyStats": schema_pkg_apis_stats_v1alpha1_AntreaNetworkPolicyStats(ref), @@ -2814,6 +2829,135 @@ func schema_pkg_apis_crd_v1beta1_ControllerCondition(ref common.ReferenceCallbac } } +func schema_pkg_apis_crd_v1beta1_Destination(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Destination describes the destination spec of the traceflow.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "namespace": { + SchemaProps: spec.SchemaProps{ + Description: "Namespace is the destination namespace.", + Type: []string{"string"}, + Format: "", + }, + }, + "pod": { + SchemaProps: spec.SchemaProps{ + Description: "Pod is the destination pod, exclusive with destination service.", + Type: []string{"string"}, + Format: "", + }, + }, + "service": { + SchemaProps: spec.SchemaProps{ + Description: "Service is the destination service, exclusive with destination pod.", + Type: []string{"string"}, + Format: "", + }, + }, + "ip": { + SchemaProps: spec.SchemaProps{ + Description: "IP is the destination IPv4 or IPv6 address.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_ICMPEchoRequestHeader(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "ICMPEchoRequestHeader describes spec of an ICMP echo request header.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "id": { + SchemaProps: spec.SchemaProps{ + Description: "ID is the ICMPEchoRequestHeader ID.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "sequence": { + SchemaProps: spec.SchemaProps{ + Description: "Sequence is the ICMPEchoRequestHeader sequence.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_IPHeader(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "IPHeader describes spec of an IPv4 header.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "protocol": { + SchemaProps: spec.SchemaProps{ + Description: "Protocol is the IP protocol.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "ttl": { + SchemaProps: spec.SchemaProps{ + Description: "TTL is the IP TTL.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "flags": { + SchemaProps: spec.SchemaProps{ + Description: "Flags is the flags for IP.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_IPv6Header(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "IPv6Header describes spec of an IPv6 header.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "nextHeader": { + SchemaProps: spec.SchemaProps{ + Description: "NextHeader is the IPv6 protocol.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "hopLimit": { + SchemaProps: spec.SchemaProps{ + Description: "HopLimit is the IPv6 Hop Limit.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_crd_v1beta1_NetworkPolicyControllerInfo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -2844,6 +2988,55 @@ func schema_pkg_apis_crd_v1beta1_NetworkPolicyControllerInfo(ref common.Referenc } } +func schema_pkg_apis_crd_v1beta1_NodeResult(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "node": { + SchemaProps: spec.SchemaProps{ + Description: "Node is the node of the observation.", + Type: []string{"string"}, + Format: "", + }, + }, + "role": { + SchemaProps: spec.SchemaProps{ + Description: "Role of the node like sender, receiver, etc.", + Type: []string{"string"}, + Format: "", + }, + }, + "timestamp": { + SchemaProps: spec.SchemaProps{ + Description: "Timestamp is the timestamp of the observations on the node.", + Type: []string{"integer"}, + Format: "int64", + }, + }, + "observations": { + SchemaProps: spec.SchemaProps{ + Description: "Observations includes all observations from sender nodes, receiver ones, etc.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Observation"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.Observation"}, + } +} + func schema_pkg_apis_crd_v1beta1_OVSInfo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -2884,6 +3077,487 @@ func schema_pkg_apis_crd_v1beta1_OVSInfo(ref common.ReferenceCallback) common.Op } } +func schema_pkg_apis_crd_v1beta1_Observation(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Observation describes those from sender nodes or receiver nodes.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "component": { + SchemaProps: spec.SchemaProps{ + Description: "Component is the observation component.", + Type: []string{"string"}, + Format: "", + }, + }, + "componentInfo": { + SchemaProps: spec.SchemaProps{ + Description: "ComponentInfo is the extension of Component field.", + Type: []string{"string"}, + Format: "", + }, + }, + "action": { + SchemaProps: spec.SchemaProps{ + Description: "Action is the action to the observation.", + Type: []string{"string"}, + Format: "", + }, + }, + "pod": { + SchemaProps: spec.SchemaProps{ + Description: "Pod is the combination of Pod name and Pod Namespace.", + Type: []string{"string"}, + Format: "", + }, + }, + "dstMAC": { + SchemaProps: spec.SchemaProps{ + Description: "DstMAC is the destination MAC.", + Type: []string{"string"}, + Format: "", + }, + }, + "networkPolicy": { + SchemaProps: spec.SchemaProps{ + Description: "NetworkPolicy is the combination of Namespace and NetworkPolicyName.", + Type: []string{"string"}, + Format: "", + }, + }, + "egress": { + SchemaProps: spec.SchemaProps{ + Description: "Egress is the name of the Egress.", + Type: []string{"string"}, + Format: "", + }, + }, + "ttl": { + SchemaProps: spec.SchemaProps{ + Description: "TTL is the observation TTL.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "translatedSrcIP": { + SchemaProps: spec.SchemaProps{ + Description: "TranslatedSrcIP is the translated source IP.", + Type: []string{"string"}, + Format: "", + }, + }, + "translatedDstIP": { + SchemaProps: spec.SchemaProps{ + Description: "TranslatedDstIP is the translated destination IP.", + Type: []string{"string"}, + Format: "", + }, + }, + "tunnelDstIP": { + SchemaProps: spec.SchemaProps{ + Description: "TunnelDstIP is the tunnel destination IP.", + Type: []string{"string"}, + Format: "", + }, + }, + "egressIP": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_Packet(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Packet includes header info.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "srcIP": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "dstIP": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "length": { + SchemaProps: spec.SchemaProps{ + Description: "Length is the IP packet length (includes the IPv4 or IPv6 header length).", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "ipHeader": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPHeader"), + }, + }, + "ipv6Header": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPv6Header"), + }, + }, + "transportHeader": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.TransportHeader"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPHeader", "antrea.io/antrea/pkg/apis/crd/v1beta1.IPv6Header", "antrea.io/antrea/pkg/apis/crd/v1beta1.TransportHeader"}, + } +} + +func schema_pkg_apis_crd_v1beta1_Source(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Source describes the source spec of the traceflow.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "namespace": { + SchemaProps: spec.SchemaProps{ + Description: "Namespace is the source namespace.", + Type: []string{"string"}, + Format: "", + }, + }, + "pod": { + SchemaProps: spec.SchemaProps{ + Description: "Pod is the source pod.", + Type: []string{"string"}, + Format: "", + }, + }, + "ip": { + SchemaProps: spec.SchemaProps{ + Description: "IP is the source IPv4 or IPv6 address. IP as the source is supported only for live-traffic Traceflow.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_TCPHeader(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TCPHeader describes spec of a TCP header.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "srcPort": { + SchemaProps: spec.SchemaProps{ + Description: "SrcPort is the source port.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "dstPort": { + SchemaProps: spec.SchemaProps{ + Description: "DstPort is the destination port.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "flags": { + SchemaProps: spec.SchemaProps{ + Description: "Flags are flags in the header.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_Traceflow(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowStatus"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowSpec", "antrea.io/antrea/pkg/apis/crd/v1beta1.TraceflowStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_TraceflowList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Traceflow"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.Traceflow", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_TraceflowSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TraceflowSpec describes the spec of the traceflow.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "source": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Source"), + }, + }, + "destination": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Destination"), + }, + }, + "packet": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Packet"), + }, + }, + "liveTraffic": { + SchemaProps: spec.SchemaProps{ + Description: "LiveTraffic indicates the Traceflow is to trace the live traffic rather than an injected packet, when set to true. The first packet of the first connection that matches the packet spec will be traced.", + Type: []string{"boolean"}, + Format: "", + }, + }, + "droppedOnly": { + SchemaProps: spec.SchemaProps{ + Description: "DroppedOnly indicates only the dropped packet should be captured in a live-traffic Traceflow.", + Type: []string{"boolean"}, + Format: "", + }, + }, + "timeout": { + SchemaProps: spec.SchemaProps{ + Description: "Timeout specifies the timeout of the Traceflow in seconds. Defaults to 20 seconds if not set.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.Destination", "antrea.io/antrea/pkg/apis/crd/v1beta1.Packet", "antrea.io/antrea/pkg/apis/crd/v1beta1.Source"}, + } +} + +func schema_pkg_apis_crd_v1beta1_TraceflowStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TraceflowStatus describes current status of the traceflow.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "phase": { + SchemaProps: spec.SchemaProps{ + Description: "Phase is the Traceflow phase.", + Type: []string{"string"}, + Format: "", + }, + }, + "reason": { + SchemaProps: spec.SchemaProps{ + Description: "Reason is a message indicating the reason of the traceflow's current phase.", + Type: []string{"string"}, + Format: "", + }, + }, + "startTime": { + SchemaProps: spec.SchemaProps{ + Description: "StartTime is the time at which the Traceflow as started by the Antrea Controller. Before K8s v1.20, null values (field not set) are not pruned, and a CR where a metav1.Time field is not set would fail OpenAPI validation (type string). The recommendation seems to be to use a pointer instead, and the field will be omitted when serializing. See https://github.com/kubernetes/kubernetes/issues/86811", + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), + }, + }, + "dataplaneTag": { + SchemaProps: spec.SchemaProps{ + Description: "DataplaneTag is a tag to identify a traceflow session across Nodes.", + Type: []string{"integer"}, + Format: "byte", + }, + }, + "results": { + SchemaProps: spec.SchemaProps{ + Description: "Results is the collection of all observations on different nodes.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.NodeResult"), + }, + }, + }, + }, + }, + "capturedPacket": { + SchemaProps: spec.SchemaProps{ + Description: "CapturedPacket is the captured packet in live-traffic Traceflow.", + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Packet"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.NodeResult", "antrea.io/antrea/pkg/apis/crd/v1beta1.Packet", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + } +} + +func schema_pkg_apis_crd_v1beta1_TransportHeader(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TransportHeader describes spec of a TransportHeader.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "icmp": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.ICMPEchoRequestHeader"), + }, + }, + "udp": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.UDPHeader"), + }, + }, + "tcp": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.TCPHeader"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.ICMPEchoRequestHeader", "antrea.io/antrea/pkg/apis/crd/v1beta1.TCPHeader", "antrea.io/antrea/pkg/apis/crd/v1beta1.UDPHeader"}, + } +} + +func schema_pkg_apis_crd_v1beta1_UDPHeader(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "UDPHeader describes spec of a UDP header.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "srcPort": { + SchemaProps: spec.SchemaProps{ + Description: "SrcPort is the source port.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "dstPort": { + SchemaProps: spec.SchemaProps{ + Description: "DstPort is the destination port.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStats(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go index 672e970dcba..019c122eb67 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ type CrdV1beta1Interface interface { RESTClient() rest.Interface AntreaAgentInfosGetter AntreaControllerInfosGetter + TraceflowsGetter } // CrdV1beta1Client is used to interact with features provided by the crd.antrea.io group. @@ -43,6 +44,10 @@ func (c *CrdV1beta1Client) AntreaControllerInfos() AntreaControllerInfoInterface return newAntreaControllerInfos(c) } +func (c *CrdV1beta1Client) Traceflows() TraceflowInterface { + return newTraceflows(c) +} + // NewForConfig creates a new CrdV1beta1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go index cc16e366e0b..affc3beefc8 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,6 +34,10 @@ func (c *FakeCrdV1beta1) AntreaControllerInfos() v1beta1.AntreaControllerInfoInt return &FakeAntreaControllerInfos{c} } +func (c *FakeCrdV1beta1) Traceflows() v1beta1.TraceflowInterface { + return &FakeTraceflows{c} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeCrdV1beta1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_traceflow.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_traceflow.go new file mode 100644 index 00000000000..4e7e530ac73 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_traceflow.go @@ -0,0 +1,131 @@ +// Copyright 2023 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" + + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeTraceflows implements TraceflowInterface +type FakeTraceflows struct { + Fake *FakeCrdV1beta1 +} + +var traceflowsResource = schema.GroupVersionResource{Group: "crd.antrea.io", Version: "v1beta1", Resource: "traceflows"} + +var traceflowsKind = schema.GroupVersionKind{Group: "crd.antrea.io", Version: "v1beta1", Kind: "Traceflow"} + +// Get takes name of the traceflow, and returns the corresponding traceflow object, and an error if there is any. +func (c *FakeTraceflows) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Traceflow, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(traceflowsResource, name), &v1beta1.Traceflow{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Traceflow), err +} + +// List takes label and field selectors, and returns the list of Traceflows that match those selectors. +func (c *FakeTraceflows) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TraceflowList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(traceflowsResource, traceflowsKind, opts), &v1beta1.TraceflowList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.TraceflowList{ListMeta: obj.(*v1beta1.TraceflowList).ListMeta} + for _, item := range obj.(*v1beta1.TraceflowList).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 traceflows. +func (c *FakeTraceflows) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(traceflowsResource, opts)) +} + +// Create takes the representation of a traceflow and creates it. Returns the server's representation of the traceflow, and an error, if there is any. +func (c *FakeTraceflows) Create(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.CreateOptions) (result *v1beta1.Traceflow, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(traceflowsResource, traceflow), &v1beta1.Traceflow{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Traceflow), err +} + +// Update takes the representation of a traceflow and updates it. Returns the server's representation of the traceflow, and an error, if there is any. +func (c *FakeTraceflows) Update(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.UpdateOptions) (result *v1beta1.Traceflow, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(traceflowsResource, traceflow), &v1beta1.Traceflow{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Traceflow), 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 *FakeTraceflows) UpdateStatus(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.UpdateOptions) (*v1beta1.Traceflow, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(traceflowsResource, "status", traceflow), &v1beta1.Traceflow{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Traceflow), err +} + +// Delete takes name of the traceflow and deletes it. Returns an error if one occurs. +func (c *FakeTraceflows) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(traceflowsResource, name, opts), &v1beta1.Traceflow{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTraceflows) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(traceflowsResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.TraceflowList{}) + return err +} + +// Patch applies the patch and returns the patched traceflow. +func (c *FakeTraceflows) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Traceflow, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(traceflowsResource, name, pt, data, subresources...), &v1beta1.Traceflow{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Traceflow), err +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go index 9e4c79f4934..931f6c017f3 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,3 +19,5 @@ package v1beta1 type AntreaAgentInfoExpansion interface{} type AntreaControllerInfoExpansion interface{} + +type TraceflowExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/traceflow.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/traceflow.go new file mode 100644 index 00000000000..7145d5411e1 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/traceflow.go @@ -0,0 +1,182 @@ +// Copyright 2023 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 v1beta1 + +import ( + "context" + "time" + + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + 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" +) + +// TraceflowsGetter has a method to return a TraceflowInterface. +// A group's client should implement this interface. +type TraceflowsGetter interface { + Traceflows() TraceflowInterface +} + +// TraceflowInterface has methods to work with Traceflow resources. +type TraceflowInterface interface { + Create(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.CreateOptions) (*v1beta1.Traceflow, error) + Update(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.UpdateOptions) (*v1beta1.Traceflow, error) + UpdateStatus(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.UpdateOptions) (*v1beta1.Traceflow, 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) (*v1beta1.Traceflow, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.TraceflowList, 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 *v1beta1.Traceflow, err error) + TraceflowExpansion +} + +// traceflows implements TraceflowInterface +type traceflows struct { + client rest.Interface +} + +// newTraceflows returns a Traceflows +func newTraceflows(c *CrdV1beta1Client) *traceflows { + return &traceflows{ + client: c.RESTClient(), + } +} + +// Get takes name of the traceflow, and returns the corresponding traceflow object, and an error if there is any. +func (c *traceflows) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Traceflow, err error) { + result = &v1beta1.Traceflow{} + err = c.client.Get(). + Resource("traceflows"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Traceflows that match those selectors. +func (c *traceflows) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TraceflowList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.TraceflowList{} + err = c.client.Get(). + Resource("traceflows"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested traceflows. +func (c *traceflows) 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("traceflows"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a traceflow and creates it. Returns the server's representation of the traceflow, and an error, if there is any. +func (c *traceflows) Create(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.CreateOptions) (result *v1beta1.Traceflow, err error) { + result = &v1beta1.Traceflow{} + err = c.client.Post(). + Resource("traceflows"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(traceflow). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a traceflow and updates it. Returns the server's representation of the traceflow, and an error, if there is any. +func (c *traceflows) Update(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.UpdateOptions) (result *v1beta1.Traceflow, err error) { + result = &v1beta1.Traceflow{} + err = c.client.Put(). + Resource("traceflows"). + Name(traceflow.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(traceflow). + 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 *traceflows) UpdateStatus(ctx context.Context, traceflow *v1beta1.Traceflow, opts v1.UpdateOptions) (result *v1beta1.Traceflow, err error) { + result = &v1beta1.Traceflow{} + err = c.client.Put(). + Resource("traceflows"). + Name(traceflow.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(traceflow). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the traceflow and deletes it. Returns an error if one occurs. +func (c *traceflows) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("traceflows"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *traceflows) 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("traceflows"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched traceflow. +func (c *traceflows) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Traceflow, err error) { + result = &v1beta1.Traceflow{} + err = c.client.Patch(pt). + Resource("traceflows"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/interface.go b/pkg/client/informers/externalversions/crd/v1beta1/interface.go index 79585d9e5c5..a8a8f9847bd 100644 --- a/pkg/client/informers/externalversions/crd/v1beta1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1beta1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ type Interface interface { AntreaAgentInfos() AntreaAgentInfoInformer // AntreaControllerInfos returns a AntreaControllerInfoInformer. AntreaControllerInfos() AntreaControllerInfoInformer + // Traceflows returns a TraceflowInformer. + Traceflows() TraceflowInformer } type version struct { @@ -48,3 +50,8 @@ func (v *version) AntreaAgentInfos() AntreaAgentInfoInformer { func (v *version) AntreaControllerInfos() AntreaControllerInfoInformer { return &antreaControllerInfoInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// Traceflows returns a TraceflowInformer. +func (v *version) Traceflows() TraceflowInformer { + return &traceflowInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/traceflow.go b/pkg/client/informers/externalversions/crd/v1beta1/traceflow.go new file mode 100644 index 00000000000..edf267ecf1e --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1beta1/traceflow.go @@ -0,0 +1,87 @@ +// Copyright 2023 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 v1beta1 + +import ( + "context" + time "time" + + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + versioned "antrea.io/antrea/pkg/client/clientset/versioned" + internalinterfaces "antrea.io/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1beta1 "antrea.io/antrea/pkg/client/listers/crd/v1beta1" + 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" +) + +// TraceflowInformer provides access to a shared informer and lister for +// Traceflows. +type TraceflowInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.TraceflowLister +} + +type traceflowInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTraceflowInformer constructs a new informer for Traceflow 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 NewTraceflowInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTraceflowInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTraceflowInformer constructs a new informer for Traceflow 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 NewFilteredTraceflowInformer(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.CrdV1beta1().Traceflows().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1beta1().Traceflows().Watch(context.TODO(), options) + }, + }, + &crdv1beta1.Traceflow{}, + resyncPeriod, + indexers, + ) +} + +func (f *traceflowInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTraceflowInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *traceflowInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1beta1.Traceflow{}, f.defaultInformer) +} + +func (f *traceflowInformer) Lister() v1beta1.TraceflowLister { + return v1beta1.NewTraceflowLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index c706d13834c..e2c2debb37d 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -92,6 +92,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().AntreaAgentInfos().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("antreacontrollerinfos"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().AntreaControllerInfos().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("traceflows"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().Traceflows().Informer()}, nil } diff --git a/pkg/client/listers/crd/v1beta1/expansion_generated.go b/pkg/client/listers/crd/v1beta1/expansion_generated.go index 2181551a0c7..3f6db2377c2 100644 --- a/pkg/client/listers/crd/v1beta1/expansion_generated.go +++ b/pkg/client/listers/crd/v1beta1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,3 +23,7 @@ type AntreaAgentInfoListerExpansion interface{} // AntreaControllerInfoListerExpansion allows custom methods to be added to // AntreaControllerInfoLister. type AntreaControllerInfoListerExpansion interface{} + +// TraceflowListerExpansion allows custom methods to be added to +// TraceflowLister. +type TraceflowListerExpansion interface{} diff --git a/pkg/client/listers/crd/v1beta1/traceflow.go b/pkg/client/listers/crd/v1beta1/traceflow.go new file mode 100644 index 00000000000..df1fc9a671f --- /dev/null +++ b/pkg/client/listers/crd/v1beta1/traceflow.go @@ -0,0 +1,66 @@ +// Copyright 2023 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 v1beta1 + +import ( + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// TraceflowLister helps list Traceflows. +// All objects returned here must be treated as read-only. +type TraceflowLister interface { + // List lists all Traceflows in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.Traceflow, err error) + // Get retrieves the Traceflow from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.Traceflow, error) + TraceflowListerExpansion +} + +// traceflowLister implements the TraceflowLister interface. +type traceflowLister struct { + indexer cache.Indexer +} + +// NewTraceflowLister returns a new TraceflowLister. +func NewTraceflowLister(indexer cache.Indexer) TraceflowLister { + return &traceflowLister{indexer: indexer} +} + +// List lists all Traceflows in the indexer. +func (s *traceflowLister) List(selector labels.Selector) (ret []*v1beta1.Traceflow, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.Traceflow)) + }) + return ret, err +} + +// Get retrieves the Traceflow from the index for a given name. +func (s *traceflowLister) Get(name string) (*v1beta1.Traceflow, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("traceflow"), name) + } + return obj.(*v1beta1.Traceflow), nil +} diff --git a/pkg/controller/traceflow/controller.go b/pkg/controller/traceflow/controller.go index 57e8d7751c6..beb85b85b86 100644 --- a/pkg/controller/traceflow/controller.go +++ b/pkg/controller/traceflow/controller.go @@ -32,10 +32,10 @@ import ( "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned" - crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha1" - crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha1" + crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" + crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1beta1" "antrea.io/antrea/pkg/controller/grouping" "antrea.io/antrea/pkg/util/k8s" ) @@ -64,7 +64,7 @@ const ( traceflowTimeout = "Traceflow timeout" // Traceflow timeout period. - defaultTimeoutDuration = time.Second * time.Duration(crdv1alpha1.DefaultTraceflowTimeout) + defaultTimeoutDuration = time.Second * time.Duration(crdv1beta1.DefaultTraceflowTimeout) ) var ( @@ -108,7 +108,7 @@ func NewTraceflowController(client versioned.Interface, podInformer coreinformer } // enqueueTraceflow adds an object to the controller work queue. -func (c *Controller) enqueueTraceflow(tf *crdv1alpha1.Traceflow) { +func (c *Controller) enqueueTraceflow(tf *crdv1beta1.Traceflow) { c.queue.Add(tf.Name) } @@ -128,7 +128,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) { klog.Errorf("Failed to list all Antrea Traceflows") } for _, tf := range tfs { - if tf.Status.Phase == crdv1alpha1.Running { + if tf.Status.Phase == crdv1beta1.Running { if err := c.occupyTag(tf); err != nil { klog.Errorf("Load Traceflow data plane tag failed %v+: %v", tf, err) } @@ -146,19 +146,19 @@ func (c *Controller) Run(stopCh <-chan struct{}) { } func (c *Controller) addTraceflow(obj interface{}) { - tf := obj.(*crdv1alpha1.Traceflow) + tf := obj.(*crdv1beta1.Traceflow) klog.Infof("Processing Traceflow %s ADD event", tf.Name) c.enqueueTraceflow(tf) } func (c *Controller) updateTraceflow(_, curObj interface{}) { - tf := curObj.(*crdv1alpha1.Traceflow) + tf := curObj.(*crdv1beta1.Traceflow) klog.Infof("Processing Traceflow %s UPDATE event", tf.Name) c.enqueueTraceflow(tf) } func (c *Controller) deleteTraceflow(old interface{}) { - tf := old.(*crdv1alpha1.Traceflow) + tf := old.(*crdv1beta1.Traceflow) klog.Infof("Processing Traceflow %s DELETE event", tf.Name) c.deallocateTagForTF(tf) } @@ -237,21 +237,21 @@ func (c *Controller) syncTraceflow(traceflowName string) error { return err } switch tf.Status.Phase { - case "", crdv1alpha1.Pending: + case "", crdv1beta1.Pending: err = c.startTraceflow(tf) - case crdv1alpha1.Running: + case crdv1beta1.Running: err = c.checkTraceflowStatus(tf) - case crdv1alpha1.Failed: + case crdv1beta1.Failed: // Deallocate tag when agent set Traceflow status to Failed. c.deallocateTagForTF(tf) } return err } -func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { +func (c *Controller) startTraceflow(tf *crdv1beta1.Traceflow) error { if err := c.validateTraceflow(tf); err != nil { klog.ErrorS(err, "Invalid Traceflow request", "request", tf) - return c.updateTraceflowStatus(tf, crdv1alpha1.Failed, fmt.Sprintf("Invalid Traceflow request, err: %+v", err), 0) + return c.updateTraceflowStatus(tf, crdv1beta1.Failed, fmt.Sprintf("Invalid Traceflow request, err: %+v", err), 0) } // Allocate data plane tag. tag, err := c.allocateTag(tf.Name) @@ -262,7 +262,7 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { return nil } - err = c.updateTraceflowStatus(tf, crdv1alpha1.Running, "", tag) + err = c.updateTraceflowStatus(tf, crdv1beta1.Running, "", tag) if err != nil { c.deallocateTag(tf.Name, tag) } @@ -270,7 +270,7 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { } // checkTraceflowStatus is only called for Traceflows in the Running phase -func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { +func (c *Controller) checkTraceflowStatus(tf *crdv1beta1.Traceflow) error { succeeded := false if tf.Spec.LiveTraffic && tf.Spec.DroppedOnly { // There should be only one reported NodeResult for droppedOnly @@ -283,13 +283,13 @@ func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { receiver := false for i, nodeResult := range tf.Status.Results { for j, ob := range nodeResult.Observations { - if ob.Component == crdv1alpha1.ComponentSpoofGuard { + if ob.Component == crdv1beta1.ComponentSpoofGuard { sender = true } - if ob.Action == crdv1alpha1.ActionDelivered || - ob.Action == crdv1alpha1.ActionDropped || - ob.Action == crdv1alpha1.ActionRejected || - ob.Action == crdv1alpha1.ActionForwardedOutOfOverlay { + if ob.Action == crdv1beta1.ActionDelivered || + ob.Action == crdv1beta1.ActionDropped || + ob.Action == crdv1beta1.ActionRejected || + ob.Action == crdv1beta1.ActionForwardedOutOfOverlay { receiver = true } if ob.TranslatedDstIP != "" { @@ -316,7 +316,7 @@ func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { } if succeeded { c.deallocateTagForTF(tf) - return c.updateTraceflowStatus(tf, crdv1alpha1.Succeeded, "", 0) + return c.updateTraceflowStatus(tf, crdv1beta1.Succeeded, "", 0) } var timeout time.Duration @@ -336,15 +336,15 @@ func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { } if startTime.Add(timeout).Before(time.Now()) { c.deallocateTagForTF(tf) - return c.updateTraceflowStatus(tf, crdv1alpha1.Failed, traceflowTimeout, 0) + return c.updateTraceflowStatus(tf, crdv1beta1.Failed, traceflowTimeout, 0) } return nil } -func (c *Controller) updateTraceflowStatus(tf *crdv1alpha1.Traceflow, phase crdv1alpha1.TraceflowPhase, reason string, dataPlaneTag uint8) error { +func (c *Controller) updateTraceflowStatus(tf *crdv1beta1.Traceflow, phase crdv1beta1.TraceflowPhase, reason string, dataPlaneTag uint8) error { update := tf.DeepCopy() update.Status.Phase = phase - if phase == crdv1alpha1.Running && tf.Status.StartTime == nil { + if phase == crdv1beta1.Running && tf.Status.StartTime == nil { t := metav1.Now() update.Status.StartTime = &t } @@ -352,11 +352,11 @@ func (c *Controller) updateTraceflowStatus(tf *crdv1alpha1.Traceflow, phase crdv if reason != "" { update.Status.Reason = reason } - _, err := c.client.CrdV1alpha1().Traceflows().UpdateStatus(context.TODO(), update, metav1.UpdateOptions{}) + _, err := c.client.CrdV1beta1().Traceflows().UpdateStatus(context.TODO(), update, metav1.UpdateOptions{}) return err } -func (c *Controller) occupyTag(tf *crdv1alpha1.Traceflow) error { +func (c *Controller) occupyTag(tf *crdv1beta1.Traceflow) error { tag := tf.Status.DataplaneTag if tag < minTagNum || tag > maxTagNum { return errors.New("this Traceflow CRD's data plane tag is out of range") @@ -398,7 +398,7 @@ func (c *Controller) allocateTag(name string) (uint8, error) { } // Deallocates tag from cache. Ignore DataplaneTag == 0 which is an invalid case. -func (c *Controller) deallocateTagForTF(tf *crdv1alpha1.Traceflow) { +func (c *Controller) deallocateTagForTF(tf *crdv1beta1.Traceflow) { if tf.Status.DataplaneTag != 0 { c.deallocateTag(tf.Name, tf.Status.DataplaneTag) } @@ -414,7 +414,7 @@ func (c *Controller) deallocateTag(name string, tag uint8) { } } -func (c *Controller) validateTraceflow(tf *crdv1alpha1.Traceflow) error { +func (c *Controller) validateTraceflow(tf *crdv1beta1.Traceflow) error { if !tf.Spec.LiveTraffic { srcPod, err := c.podLister.Pods(tf.Spec.Source.Namespace).Get(tf.Spec.Source.Pod) if err != nil { diff --git a/pkg/controller/traceflow/controller_test.go b/pkg/controller/traceflow/controller_test.go index 1515210f1f2..c169f14279a 100644 --- a/pkg/controller/traceflow/controller_test.go +++ b/pkg/controller/traceflow/controller_test.go @@ -31,7 +31,7 @@ import ( "k8s.io/client-go/kubernetes/fake" k8stesting "k8s.io/client-go/testing" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned" fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake" crdinformers "antrea.io/antrea/pkg/client/informers/externalversions" @@ -57,7 +57,7 @@ func newController(k8sObjects ...runtime.Object) *traceflowController { crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, informerDefaultResync) controller := NewTraceflowController(crdClient, informerFactory.Core().V1().Pods(), - crdInformerFactory.Crd().V1alpha1().Traceflows()) + crdInformerFactory.Crd().V1beta1().Traceflows()) controller.traceflowListerSynced = alwaysReady return &traceflowController{ controller, @@ -89,11 +89,11 @@ func TestTraceflow(t *testing.T) { return len(tfc.runningTraceflows) } - tf1 := crdv1alpha1.Traceflow{ + tf1 := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf1", UID: "uid1"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{Namespace: "ns1", Pod: "pod1"}, - Destination: crdv1alpha1.Destination{Namespace: "ns2", Pod: "pod2"}, + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{Namespace: "ns1", Pod: "pod1"}, + Destination: crdv1beta1.Destination{Namespace: "ns2", Pod: "pod2"}, Timeout: 2, // 2 seconds timeout }, } @@ -109,39 +109,39 @@ func TestTraceflow(t *testing.T) { tfc.kubeClient.CoreV1().Pods("ns1").Create(context.TODO(), &pod1, metav1.CreateOptions{}) createdPod, _ := tfc.waitForPodInNamespace("ns1", "pod1", time.Second) require.NotNil(t, createdPod) - tfc.client.CrdV1alpha1().Traceflows().Create(context.TODO(), &tf1, metav1.CreateOptions{}) - res, _ := tfc.waitForTraceflow("tf1", crdv1alpha1.Running, time.Second) + tfc.client.CrdV1beta1().Traceflows().Create(context.TODO(), &tf1, metav1.CreateOptions{}) + res, _ := tfc.waitForTraceflow("tf1", crdv1beta1.Running, time.Second) require.NotNil(t, res) // DataplaneTag should be allocated by Controller. assert.True(t, res.Status.DataplaneTag > 0) assert.Equal(t, numRunningTraceflows(), 1) // Test Controller handling of successful Traceflow. - res.Status.Results = []crdv1alpha1.NodeResult{ + res.Status.Results = []crdv1beta1.NodeResult{ // Sender { - Observations: []crdv1alpha1.Observation{{Component: crdv1alpha1.ComponentSpoofGuard}}, + Observations: []crdv1beta1.Observation{{Component: crdv1beta1.ComponentSpoofGuard}}, }, // Receiver { - Observations: []crdv1alpha1.Observation{{Action: crdv1alpha1.ActionDelivered}}, + Observations: []crdv1beta1.Observation{{Action: crdv1beta1.ActionDelivered}}, }, } - tfc.client.CrdV1alpha1().Traceflows().Update(context.TODO(), res, metav1.UpdateOptions{}) - res, _ = tfc.waitForTraceflow("tf1", crdv1alpha1.Succeeded, time.Second) + tfc.client.CrdV1beta1().Traceflows().Update(context.TODO(), res, metav1.UpdateOptions{}) + res, _ = tfc.waitForTraceflow("tf1", crdv1beta1.Succeeded, time.Second) assert.NotNil(t, res) // DataplaneTag should be deallocated by Controller. assert.True(t, res.Status.DataplaneTag == 0) assert.Equal(t, numRunningTraceflows(), 0) - tfc.client.CrdV1alpha1().Traceflows().Delete(context.TODO(), "tf1", metav1.DeleteOptions{}) + tfc.client.CrdV1beta1().Traceflows().Delete(context.TODO(), "tf1", metav1.DeleteOptions{}) }) t.Run("timeoutTraceflow", func(t *testing.T) { startTime := time.Now() - tfc.client.CrdV1alpha1().Traceflows().Create(context.TODO(), &tf1, metav1.CreateOptions{}) - res, _ := tfc.waitForTraceflow("tf1", crdv1alpha1.Running, time.Second) + tfc.client.CrdV1beta1().Traceflows().Create(context.TODO(), &tf1, metav1.CreateOptions{}) + res, _ := tfc.waitForTraceflow("tf1", crdv1beta1.Running, time.Second) assert.NotNil(t, res) - res, _ = tfc.waitForTraceflow("tf1", crdv1alpha1.Failed, defaultTimeoutDuration*2) + res, _ = tfc.waitForTraceflow("tf1", crdv1beta1.Failed, defaultTimeoutDuration*2) assert.NotNil(t, res) assert.True(t, time.Now().Sub(startTime) >= time.Second*time.Duration(tf1.Spec.Timeout)) assert.Equal(t, res.Status.Reason, traceflowTimeout) @@ -150,11 +150,11 @@ func TestTraceflow(t *testing.T) { }) t.Run("timeoutHostnetworkTraceflow", func(t *testing.T) { - tf2 := crdv1alpha1.Traceflow{ + tf2 := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{Name: "tf2", UID: "uid2"}, - Spec: crdv1alpha1.TraceflowSpec{ - Source: crdv1alpha1.Source{Namespace: "ns1", Pod: "pod2"}, - Destination: crdv1alpha1.Destination{Namespace: "ns2", Pod: "pod2"}, + Spec: crdv1beta1.TraceflowSpec{ + Source: crdv1beta1.Source{Namespace: "ns1", Pod: "pod2"}, + Destination: crdv1beta1.Destination{Namespace: "ns2", Pod: "pod2"}, Timeout: 2, // 2 seconds timeout }, } @@ -169,8 +169,8 @@ func TestTraceflow(t *testing.T) { tfc.kubeClient.CoreV1().Pods("ns1").Create(context.TODO(), &pod2, metav1.CreateOptions{}) createdPod, _ := tfc.waitForPodInNamespace("ns1", "pod2", time.Second) require.NotNil(t, createdPod) - tfc.client.CrdV1alpha1().Traceflows().Create(context.TODO(), &tf2, metav1.CreateOptions{}) - res, _ := tfc.waitForTraceflow("tf2", crdv1alpha1.Failed, time.Second) + tfc.client.CrdV1beta1().Traceflows().Create(context.TODO(), &tf2, metav1.CreateOptions{}) + res, _ := tfc.waitForTraceflow("tf2", crdv1beta1.Failed, time.Second) require.NotNil(t, res) // DataplaneTag should not be allocated by Controller. assert.True(t, res.Status.DataplaneTag == 0) @@ -196,11 +196,11 @@ func (tfc *traceflowController) waitForPodInNamespace(ns string, name string, ti return pod, nil } -func (tfc *traceflowController) waitForTraceflow(name string, phase crdv1alpha1.TraceflowPhase, timeout time.Duration) (*crdv1alpha1.Traceflow, error) { - var tf *crdv1alpha1.Traceflow +func (tfc *traceflowController) waitForTraceflow(name string, phase crdv1beta1.TraceflowPhase, timeout time.Duration) (*crdv1beta1.Traceflow, error) { + var tf *crdv1beta1.Traceflow var err error if err = wait.Poll(100*time.Millisecond, timeout, func() (bool, error) { - tf, err = tfc.client.CrdV1alpha1().Traceflows().Get(context.TODO(), name, metav1.GetOptions{}) + tf, err = tfc.client.CrdV1beta1().Traceflows().Get(context.TODO(), name, metav1.GetOptions{}) if err != nil || tf.Status.Phase != phase { return false, nil } @@ -215,7 +215,7 @@ func newCRDClientset() *fakeversioned.Clientset { client := fakeversioned.NewSimpleClientset() client.PrependReactor("create", "traceflows", k8stesting.ReactionFunc(func(action k8stesting.Action) (bool, runtime.Object, error) { - tf := action.(k8stesting.CreateAction).GetObject().(*crdv1alpha1.Traceflow) + tf := action.(k8stesting.CreateAction).GetObject().(*crdv1beta1.Traceflow) // Fake client does not set CreationTimestamp. if tf.ObjectMeta.CreationTimestamp == (metav1.Time{}) { diff --git a/pkg/graphviz/traceflow.go b/pkg/graphviz/traceflow.go index 175116c3521..3685e3773ff 100644 --- a/pkg/graphviz/traceflow.go +++ b/pkg/graphviz/traceflow.go @@ -21,7 +21,7 @@ import ( "github.com/awalterschulze/gographviz" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" ) const ( @@ -105,21 +105,21 @@ func createClusterWithDefaultStyle(graph *gographviz.Graph, name string) (*gogra return graph.SubGraphs.SubGraphs[name], nil } -func isSender(result *crdv1alpha1.NodeResult) bool { +func isSender(result *crdv1beta1.NodeResult) bool { if len(result.Observations) == 0 { return false } - if result.Observations[0].Component != crdv1alpha1.ComponentSpoofGuard || result.Observations[0].Action != crdv1alpha1.ActionForwarded { + if result.Observations[0].Component != crdv1beta1.ComponentSpoofGuard || result.Observations[0].Action != crdv1beta1.ActionForwarded { return false } return true } -func isReceiver(result *crdv1alpha1.NodeResult) bool { +func isReceiver(result *crdv1beta1.NodeResult) bool { if len(result.Observations) == 0 { return false } - if result.Observations[0].Component != crdv1alpha1.ComponentForwarding || result.Observations[0].Action != crdv1alpha1.ActionReceived { + if result.Observations[0].Component != crdv1beta1.ComponentForwarding || result.Observations[0].Action != crdv1beta1.ActionReceived { return false } return true @@ -136,7 +136,7 @@ func getWrappedStr(str string) string { return `"` + wStr + `"` } -func getNodeResult(tf *crdv1alpha1.Traceflow, fn func(result *crdv1alpha1.NodeResult) bool) *crdv1alpha1.NodeResult { +func getNodeResult(tf *crdv1beta1.Traceflow, fn func(result *crdv1beta1.NodeResult) bool) *crdv1beta1.NodeResult { for i := range tf.Status.Results { result := tf.Status.Results[i] if fn(&result) { @@ -146,7 +146,7 @@ func getNodeResult(tf *crdv1alpha1.Traceflow, fn func(result *crdv1alpha1.NodeRe return nil } -func getSrcNodeName(tf *crdv1alpha1.Traceflow) string { +func getSrcNodeName(tf *crdv1beta1.Traceflow) string { if len(tf.Spec.Source.Namespace) > 0 && len(tf.Spec.Source.Pod) > 0 { return getWrappedStr(tf.Spec.Source.Namespace + "/" + tf.Spec.Source.Pod) } @@ -159,7 +159,7 @@ func getSrcNodeName(tf *crdv1alpha1.Traceflow) string { return "" } -func getDstNodeName(tf *crdv1alpha1.Traceflow) string { +func getDstNodeName(tf *crdv1beta1.Traceflow) string { if len(tf.Spec.Destination.Namespace) > 0 && len(tf.Spec.Destination.Service) > 0 { return getWrappedStr(tf.Spec.Destination.Namespace + "/" + tf.Spec.Destination.Pod + "\nService: " + tf.Spec.Destination.Service) @@ -177,13 +177,13 @@ func getDstNodeName(tf *crdv1alpha1.Traceflow) string { } // getTraceflowMessage gets the shown message string in traceflow graph. -func getTraceflowMessage(o *crdv1alpha1.Observation, spec *crdv1alpha1.TraceflowSpec) string { +func getTraceflowMessage(o *crdv1beta1.Observation, spec *crdv1beta1.TraceflowSpec) string { str := string(o.Component) if len(o.ComponentInfo) > 0 { str += "\n" + o.ComponentInfo } str += "\n" + string(o.Action) - if o.Component == crdv1alpha1.ComponentNetworkPolicy && len(o.NetworkPolicy) > 0 { + if o.Component == crdv1beta1.ComponentNetworkPolicy && len(o.NetworkPolicy) > 0 { str += "\nNetpol: " + o.NetworkPolicy } if len(o.Pod) > 0 { @@ -192,19 +192,19 @@ func getTraceflowMessage(o *crdv1alpha1.Observation, spec *crdv1alpha1.Traceflow spec.Destination.Pod = o.Pod[strings.Index(o.Pod, `/`)+1:] } } - if o.Action != crdv1alpha1.ActionDropped && len(o.TranslatedSrcIP) > 0 { + if o.Action != crdv1beta1.ActionDropped && len(o.TranslatedSrcIP) > 0 { str += "\nTranslated Source IP: " + o.TranslatedSrcIP } - if o.Action != crdv1alpha1.ActionDropped && len(o.TranslatedDstIP) > 0 { + if o.Action != crdv1beta1.ActionDropped && len(o.TranslatedDstIP) > 0 { str += "\nTranslated Destination IP: " + o.TranslatedDstIP } - if o.Action != crdv1alpha1.ActionDropped && len(o.TunnelDstIP) > 0 { + if o.Action != crdv1beta1.ActionDropped && len(o.TunnelDstIP) > 0 { str += "\nTunnel Destination IP : " + o.TunnelDstIP } - if o.Action != crdv1alpha1.ActionDropped && len(o.EgressIP) > 0 { + if o.Action != crdv1beta1.ActionDropped && len(o.EgressIP) > 0 { str += "\nEgress IP : " + o.EgressIP } - if o.Action != crdv1alpha1.ActionDropped && len(o.Egress) > 0 { + if o.Action != crdv1beta1.ActionDropped && len(o.Egress) > 0 { str += "\nEgress : " + o.Egress } return str @@ -250,20 +250,20 @@ func genOutput(graph *gographviz.Graph, isSingleCluster bool) string { return str } -func getTraceflowStatusMessage(tf *crdv1alpha1.Traceflow) string { +func getTraceflowStatusMessage(tf *crdv1beta1.Traceflow) string { switch tf.Status.Phase { - case crdv1alpha1.Failed: + case crdv1beta1.Failed: return getWrappedStr(fmt.Sprintf("Traceflow %s failed: %s", tf.Name, tf.Status.Reason)) - case crdv1alpha1.Running: + case crdv1beta1.Running: return getWrappedStr(fmt.Sprintf("Traceflow %s is running...", tf.Name)) - case crdv1alpha1.Pending: + case crdv1beta1.Pending: return getWrappedStr(fmt.Sprintf("Traceflow %s is pending...", tf.Name)) default: return getWrappedStr("Unknown Traceflow status. Please check whether Antrea is running.") } } -func genSubGraph(graph *gographviz.Graph, cluster *gographviz.SubGraph, result *crdv1alpha1.NodeResult, spec *crdv1alpha1.TraceflowSpec, +func genSubGraph(graph *gographviz.Graph, cluster *gographviz.SubGraph, result *crdv1beta1.NodeResult, spec *crdv1beta1.TraceflowSpec, endpointNodeName string, isForwardDir bool, addNodeNum int) ([]*gographviz.Node, error) { var nodes []*gographviz.Node @@ -289,7 +289,7 @@ func genSubGraph(graph *gographviz.Graph, cluster *gographviz.SubGraph, result * // Reorder the observations according to the direction of edges. // Before that, deep copy observations to prevent possible risks of the original traceflow being modified. - obs := make([]crdv1alpha1.Observation, len(result.Observations)) + obs := make([]crdv1beta1.Observation, len(result.Observations)) copy(obs, result.Observations) if !isForwardDir { for i := len(obs)/2 - 1; i >= 0; i-- { @@ -320,12 +320,12 @@ func genSubGraph(graph *gographviz.Graph, cluster *gographviz.SubGraph, result * } else { edge.Attrs[gographviz.MinLen] = "1" } - if o.Action == crdv1alpha1.ActionDropped && !isForwardDir { + if o.Action == crdv1beta1.ActionDropped && !isForwardDir { edge.Attrs[gographviz.Style] = `"invis"` } } // Set the pattern of node. - if o.Action == crdv1alpha1.ActionDropped { + if o.Action == crdv1beta1.ActionDropped { node.Attrs[gographviz.Color] = fireBrick node.Attrs[gographviz.FillColor] = mistyRose } else { @@ -338,7 +338,7 @@ func genSubGraph(graph *gographviz.Graph, cluster *gographviz.SubGraph, result * return nodes, nil } -func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { +func GenGraph(tf *crdv1beta1.Traceflow) (string, error) { g, _ := gographviz.ParseString(`digraph G {}`) graph := gographviz.NewGraph() if err := gographviz.Analyse(g, graph); err != nil { @@ -354,12 +354,12 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { senderRst := getNodeResult(tf, isSender) receiverRst := getNodeResult(tf, isReceiver) - if tf.Status.Phase != crdv1alpha1.Succeeded { + if tf.Status.Phase != crdv1beta1.Succeeded { graph.Attrs[gographviz.Label] = getTraceflowStatusMessage(tf) } - if tf == nil || senderRst == nil || tf.Status.Phase != crdv1alpha1.Succeeded || len(senderRst.Observations) == 0 { + if tf == nil || senderRst == nil || tf.Status.Phase != crdv1beta1.Succeeded || len(senderRst.Observations) == 0 { // For live traffic, when the source is IP or empty, there is no result from the sender Node result in the traceflow status. - if senderRst == nil && tf.Spec.LiveTraffic && tf.Status.Phase == crdv1alpha1.Succeeded { + if senderRst == nil && tf.Spec.LiveTraffic && tf.Status.Phase == crdv1beta1.Succeeded { // Draw the nodes for the sender. srcCluster, err := createClusterWithDefaultStyle(graph, clusterSrcName) if err != nil { @@ -428,7 +428,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { switch senderRst.Observations[len(senderRst.Observations)-1].Action { // If the last action of the sender is FORWARDED, // then the packet has been sent out by sender, implying that there is a disconnection. - case crdv1alpha1.ActionForwarded: + case crdv1beta1.ActionForwarded: lastNode, err := createEndpointNodeWithDefaultStyle(graph, graph.Name, getDstNodeName(tf)) if err != nil { return "", err @@ -441,7 +441,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { if err != nil { return "", err } - case crdv1alpha1.ActionDelivered: + case crdv1beta1.ActionDelivered: lastNode, err := createEndpointNodeWithDefaultStyle(graph, cluster1.Name, getDstNodeName(tf)) if err != nil { return "", err @@ -451,7 +451,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { return "", err } } - if tf.Spec.LiveTraffic && tf.Status.Phase == crdv1alpha1.Succeeded { + if tf.Spec.LiveTraffic && tf.Status.Phase == crdv1beta1.Succeeded { err = createCapturedPacketNode(graph, cluster1.Name, tf) if err != nil { return "", err @@ -492,7 +492,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { } edge.Attrs[gographviz.Constraint] = "false" } - if tf.Spec.LiveTraffic && tf.Status.Phase == crdv1alpha1.Succeeded { + if tf.Spec.LiveTraffic && tf.Status.Phase == crdv1beta1.Succeeded { err = createCapturedPacketNode(graph, cluster2.Name, tf) if err != nil { return "", err @@ -501,7 +501,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) { return genOutput(graph, false), nil } -func getCapturedPacketLabel(tf *crdv1alpha1.Traceflow) string { +func getCapturedPacketLabel(tf *crdv1beta1.Traceflow) string { label := "Captured Packet:\\lSource IP: " + tf.Status.CapturedPacket.SrcIP + "\\l" + "Destination IP: " + tf.Status.CapturedPacket.DstIP + "\\l" + "Length: " + fmt.Sprintf("%d", tf.Status.CapturedPacket.Length) + "\\l" @@ -517,7 +517,7 @@ func getCapturedPacketLabel(tf *crdv1alpha1.Traceflow) string { " Hop Limit: " + fmt.Sprintf("%d", tf.Status.CapturedPacket.IPv6Header.HopLimit) + "\\l" } - if tf.Status.CapturedPacket.TransportHeader != (crdv1alpha1.TransportHeader{}) { + if tf.Status.CapturedPacket.TransportHeader != (crdv1beta1.TransportHeader{}) { label = label + "Transport Header: \\l" if tf.Status.CapturedPacket.TransportHeader.TCP != nil { label = label + " TCP: " + "\\l" + @@ -539,7 +539,7 @@ func getCapturedPacketLabel(tf *crdv1alpha1.Traceflow) string { return label } -func createCapturedPacketNode(graph *gographviz.Graph, parentGraph string, tf *crdv1alpha1.Traceflow) error { +func createCapturedPacketNode(graph *gographviz.Graph, parentGraph string, tf *crdv1beta1.Traceflow) error { err := graph.AddNode(parentGraph, "capturedPacket", map[string]string{ "shape": "note", "style": `"rounded,filled,solid"`, diff --git a/pkg/graphviz/traceflow_test.go b/pkg/graphviz/traceflow_test.go index e864f9ea557..f0e4e6b3bb1 100644 --- a/pkg/graphviz/traceflow_test.go +++ b/pkg/graphviz/traceflow_test.go @@ -19,67 +19,68 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" - crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" ) func TestGenGraph(t *testing.T) { - liveTf := crdv1alpha1.Traceflow{ + liveTf := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-live-traceflow", }, - Spec: crdv1alpha1.TraceflowSpec{ + Spec: crdv1beta1.TraceflowSpec{ LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPHeader: crdv1alpha1.IPHeader{ + Packet: crdv1beta1.Packet{ + IPHeader: &crdv1beta1.IPHeader{ Protocol: 1, }, - TransportHeader: crdv1alpha1.TransportHeader{ - ICMP: &crdv1alpha1.ICMPEchoRequestHeader{ + TransportHeader: crdv1beta1.TransportHeader{ + ICMP: &crdv1beta1.ICMPEchoRequestHeader{ ID: 123, Sequence: 1, }, }, }, - Source: crdv1alpha1.Source{ + Source: crdv1beta1.Source{ Namespace: "default", Pod: "test-pod", }, }, - Status: crdv1alpha1.TraceflowStatus{ - CapturedPacket: &crdv1alpha1.Packet{ + Status: crdv1beta1.TraceflowStatus{ + CapturedPacket: &crdv1beta1.Packet{ DstIP: "10.10.0.2", - IPHeader: crdv1alpha1.IPHeader{ + IPHeader: &crdv1beta1.IPHeader{ Flags: 2, Protocol: 1, TTL: 63, }, - TransportHeader: crdv1alpha1.TransportHeader{ - ICMP: &crdv1alpha1.ICMPEchoRequestHeader{ + TransportHeader: crdv1beta1.TransportHeader{ + ICMP: &crdv1beta1.ICMPEchoRequestHeader{ ID: 123, Sequence: 1, }, - TCP: &crdv1alpha1.TCPHeader{ + TCP: &crdv1beta1.TCPHeader{ SrcPort: 123, DstPort: 1, - Flags: 2, + Flags: pointer.Int32(2), }, }, Length: 84, SrcIP: "10.10.1.4", }, - Phase: crdv1alpha1.Succeeded, - Results: []crdv1alpha1.NodeResult{ + Phase: crdv1beta1.Succeeded, + Results: []crdv1beta1.NodeResult{ { Node: "k8s-node-worker-1", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, }, { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", TunnelDstIP: "192.168.77.100", }, @@ -87,15 +88,15 @@ func TestGenGraph(t *testing.T) { }, { Node: "k8s-node-control-plane", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionReceived, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionReceived, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Classification", }, { - Action: crdv1alpha1.ActionDelivered, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionDelivered, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", }, }, @@ -104,26 +105,26 @@ func TestGenGraph(t *testing.T) { }, } - liveTfWithSourceIP := crdv1alpha1.Traceflow{ + liveTfWithSourceIP := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-live-traceflow-source-ip", }, - Spec: crdv1alpha1.TraceflowSpec{ + Spec: crdv1beta1.TraceflowSpec{ LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPHeader: crdv1alpha1.IPHeader{ + Packet: crdv1beta1.Packet{ + IPHeader: &crdv1beta1.IPHeader{ Protocol: 1, }, - TransportHeader: crdv1alpha1.TransportHeader{}, + TransportHeader: crdv1beta1.TransportHeader{}, }, - Source: crdv1alpha1.Source{ + Source: crdv1beta1.Source{ IP: "192.168.225.5", }, }, - Status: crdv1alpha1.TraceflowStatus{ - CapturedPacket: &crdv1alpha1.Packet{ + Status: crdv1beta1.TraceflowStatus{ + CapturedPacket: &crdv1beta1.Packet{ DstIP: "192.168.226.5", - IPHeader: crdv1alpha1.IPHeader{ + IPHeader: &crdv1beta1.IPHeader{ Flags: 2, Protocol: 1, TTL: 63, @@ -131,18 +132,18 @@ func TestGenGraph(t *testing.T) { Length: 84, SrcIP: "192.168.225.5", }, - Phase: crdv1alpha1.Succeeded, - Results: []crdv1alpha1.NodeResult{ + Phase: crdv1beta1.Succeeded, + Results: []crdv1beta1.NodeResult{ { Node: "k8s-node-1", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionReceived, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionReceived, + Component: crdv1beta1.ComponentForwarding, }, { - Action: crdv1alpha1.ActionDelivered, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionDelivered, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", }, }, @@ -151,39 +152,39 @@ func TestGenGraph(t *testing.T) { }, } - tfInOneNode := crdv1alpha1.Traceflow{ + tfInOneNode := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-traceflow-one-node", }, - Spec: crdv1alpha1.TraceflowSpec{ - Packet: crdv1alpha1.Packet{ - IPHeader: crdv1alpha1.IPHeader{ + Spec: crdv1beta1.TraceflowSpec{ + Packet: crdv1beta1.Packet{ + IPHeader: &crdv1beta1.IPHeader{ Protocol: 1, }, - TransportHeader: crdv1alpha1.TransportHeader{}, + TransportHeader: crdv1beta1.TransportHeader{}, }, - Source: crdv1alpha1.Source{ + Source: crdv1beta1.Source{ Namespace: "default", Pod: "pod-1", }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: "default", Pod: "pod-2", }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Succeeded, - Results: []crdv1alpha1.NodeResult{ + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Succeeded, + Results: []crdv1beta1.NodeResult{ { Node: "k8s-node-1", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, }, { - Action: crdv1alpha1.ActionDelivered, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionDelivered, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", }, }, @@ -192,37 +193,37 @@ func TestGenGraph(t *testing.T) { }, } - liveTfWithSourceIPTwoNodes := crdv1alpha1.Traceflow{ + liveTfWithSourceIPTwoNodes := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-live-traceflow-source-ip-two-nodes", }, - Spec: crdv1alpha1.TraceflowSpec{ + Spec: crdv1beta1.TraceflowSpec{ LiveTraffic: true, - Packet: crdv1alpha1.Packet{ - IPHeader: crdv1alpha1.IPHeader{ + Packet: crdv1beta1.Packet{ + IPHeader: &crdv1beta1.IPHeader{ Protocol: 1, }, - TransportHeader: crdv1alpha1.TransportHeader{ - ICMP: &crdv1alpha1.ICMPEchoRequestHeader{ + TransportHeader: crdv1beta1.TransportHeader{ + ICMP: &crdv1beta1.ICMPEchoRequestHeader{ ID: 123, Sequence: 1, }, }, }, - Source: crdv1alpha1.Source{ + Source: crdv1beta1.Source{ IP: "192.168.225.5", }, }, - Status: crdv1alpha1.TraceflowStatus{ - CapturedPacket: &crdv1alpha1.Packet{ + Status: crdv1beta1.TraceflowStatus{ + CapturedPacket: &crdv1beta1.Packet{ DstIP: "10.10.0.2", - IPHeader: crdv1alpha1.IPHeader{ + IPHeader: &crdv1beta1.IPHeader{ Flags: 2, Protocol: 1, TTL: 63, }, - TransportHeader: crdv1alpha1.TransportHeader{ - UDP: &crdv1alpha1.UDPHeader{ + TransportHeader: crdv1beta1.TransportHeader{ + UDP: &crdv1beta1.UDPHeader{ SrcPort: 68, DstPort: 80, }, @@ -230,18 +231,18 @@ func TestGenGraph(t *testing.T) { Length: 84, SrcIP: "10.10.1.4", }, - Phase: crdv1alpha1.Succeeded, - Results: []crdv1alpha1.NodeResult{ + Phase: crdv1beta1.Succeeded, + Results: []crdv1beta1.NodeResult{ { Node: "k8s-node-worker-1", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, }, { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", TunnelDstIP: "192.168.77.100", }, @@ -249,15 +250,15 @@ func TestGenGraph(t *testing.T) { }, { Node: "k8s-node-control-plane", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionReceived, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionReceived, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Classification", }, { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", }, }, @@ -266,45 +267,45 @@ func TestGenGraph(t *testing.T) { }, } - nonliveTf := crdv1alpha1.Traceflow{ + nonliveTf := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-non-live-traceflow", }, - Spec: crdv1alpha1.TraceflowSpec{ + Spec: crdv1beta1.TraceflowSpec{ LiveTraffic: false, - Packet: crdv1alpha1.Packet{ - IPHeader: crdv1alpha1.IPHeader{ + Packet: crdv1beta1.Packet{ + IPHeader: &crdv1beta1.IPHeader{ Protocol: 1, }, - TransportHeader: crdv1alpha1.TransportHeader{ - ICMP: &crdv1alpha1.ICMPEchoRequestHeader{ + TransportHeader: crdv1beta1.TransportHeader{ + ICMP: &crdv1beta1.ICMPEchoRequestHeader{ ID: 123, Sequence: 1, }, }, }, - Source: crdv1alpha1.Source{ + Source: crdv1beta1.Source{ Namespace: "default", Pod: "pod-1", }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ Namespace: "default", Pod: "pod-2", }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Succeeded, - Results: []crdv1alpha1.NodeResult{ + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Succeeded, + Results: []crdv1beta1.NodeResult{ { Node: "k8s-node-worker-1", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, }, { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", TunnelDstIP: "192.168.77.100", }, @@ -312,15 +313,15 @@ func TestGenGraph(t *testing.T) { }, { Node: "k8s-node-control-plane", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionReceived, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionReceived, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Classification", }, { - Action: crdv1alpha1.ActionDropped, - Component: crdv1alpha1.ComponentNetworkPolicy, + Action: crdv1beta1.ActionDropped, + Component: crdv1beta1.ComponentNetworkPolicy, ComponentInfo: "IngressRule", }, }, @@ -329,44 +330,44 @@ func TestGenGraph(t *testing.T) { }, } - tfEgressFromLocalNode := crdv1alpha1.Traceflow{ + tfEgressFromLocalNode := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-traceflow-egress-local-node", }, - Spec: crdv1alpha1.TraceflowSpec{ - Packet: crdv1alpha1.Packet{ - IPHeader: crdv1alpha1.IPHeader{ + Spec: crdv1beta1.TraceflowSpec{ + Packet: crdv1beta1.Packet{ + IPHeader: &crdv1beta1.IPHeader{ Protocol: 1, }, - TransportHeader: crdv1alpha1.TransportHeader{}, + TransportHeader: crdv1beta1.TransportHeader{}, }, - Source: crdv1alpha1.Source{ + Source: crdv1beta1.Source{ Namespace: "default", Pod: "pod-1", }, - Destination: crdv1alpha1.Destination{ + Destination: crdv1beta1.Destination{ IP: "192.168.100.100", }, }, - Status: crdv1alpha1.TraceflowStatus{ - Phase: crdv1alpha1.Succeeded, - Results: []crdv1alpha1.NodeResult{ + Status: crdv1beta1.TraceflowStatus{ + Phase: crdv1beta1.Succeeded, + Results: []crdv1beta1.NodeResult{ { Node: "k8s-node-1", - Observations: []crdv1alpha1.Observation{ + Observations: []crdv1beta1.Observation{ { - Action: crdv1alpha1.ActionForwarded, - Component: crdv1alpha1.ComponentSpoofGuard, + Action: crdv1beta1.ActionForwarded, + Component: crdv1beta1.ComponentSpoofGuard, }, { - Component: crdv1alpha1.ComponentEgress, - Action: crdv1alpha1.ActionMarkedForSNAT, + Component: crdv1beta1.ComponentEgress, + Action: crdv1beta1.ActionMarkedForSNAT, Egress: "egressA", EgressIP: "192.168.225.5", }, { - Action: crdv1alpha1.ActionForwardedOutOfOverlay, - Component: crdv1alpha1.ComponentForwarding, + Action: crdv1beta1.ActionForwardedOutOfOverlay, + Component: crdv1beta1.ComponentForwarding, ComponentInfo: "Output", }, }, @@ -608,7 +609,7 @@ ForwardedOutOfOverlay", shape=box, style="rounded,filled,solid" ]; tests := []struct { name string - traceflow crdv1alpha1.Traceflow + traceflow crdv1beta1.Traceflow expectedOutput string }{ { @@ -653,32 +654,32 @@ ForwardedOutOfOverlay", shape=box, style="rounded,filled,solid" ]; } func TestGetTraceflowStatusMessage(t *testing.T) { - baseTf := crdv1alpha1.Traceflow{ + baseTf := crdv1beta1.Traceflow{ ObjectMeta: metav1.ObjectMeta{ Name: "test-tf", }, - Status: crdv1alpha1.TraceflowStatus{ + Status: crdv1beta1.TraceflowStatus{ Reason: "test", }, } tests := []struct { name string - phase crdv1alpha1.TraceflowPhase + phase crdv1beta1.TraceflowPhase expectOutput string }{ { name: "failed traceflow", - phase: crdv1alpha1.Failed, + phase: crdv1beta1.Failed, expectOutput: "\"Traceflow test-tf failed: test\"", }, { name: "running traceflow", - phase: crdv1alpha1.Running, + phase: crdv1beta1.Running, expectOutput: "\"Traceflow test-tf is running...\"", }, { name: "pending traceflow", - phase: crdv1alpha1.Pending, + phase: crdv1beta1.Pending, expectOutput: "\"Traceflow test-tf is pending...\"", }, {