From 15f7e57a836ef1dcb2d973ca810bc64d893ac559 Mon Sep 17 00:00:00 2001 From: ii2day Date: Wed, 13 Sep 2023 18:22:32 +0800 Subject: [PATCH] Fixed the netreach target configuration not taking effect Signed-off-by: ii2day --- .../apis/kdoctor.io/v1beta1/netreach_types.go | 20 ++++++++----- test/e2e/apphttphealth/apphttphealth_test.go | 24 ++++++++-------- test/e2e/common/tools.go | 28 ++++++++++++++++++- test/e2e/netdns/netdns_test.go | 4 +-- test/e2e/netreach/netreach_test.go | 2 +- 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go b/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go index 305b6d6e..b67797f6 100644 --- a/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go +++ b/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go @@ -37,26 +37,32 @@ type NetReachTarget struct { IPv6 *bool `json:"ipv6,omitempty"` // +kubebuilder:default=true - Endpoint bool `json:"endpoint,omitempty"` + // +kubebuilder:validation:Optional + Endpoint bool `json:"endpoint"` // +kubebuilder:default=false - MultusInterface bool `json:"multusInterface,omitempty"` + // +kubebuilder:validation:Optional + MultusInterface bool `json:"multusInterface"` // +kubebuilder:default=true - ClusterIP bool `json:"clusterIP,omitempty"` + // +kubebuilder:validation:Optional + ClusterIP bool `json:"clusterIP"` // +kubebuilder:default=true - NodePort bool `json:"nodePort,omitempty"` + // +kubebuilder:validation:Optional + NodePort bool `json:"nodePort"` // +kubebuilder:default=false - LoadBalancer bool `json:"loadBalancer,omitempty"` + // +kubebuilder:validation:Optional + LoadBalancer bool `json:"loadBalancer"` // +kubebuilder:default=false - Ingress bool `json:"ingress,omitempty"` + // +kubebuilder:validation:Optional + Ingress bool `json:"ingress"` // +kubebuilder:default=false // +kubebuilder:validation:Optional - EnableLatencyMetric bool `json:"enableLatencyMetric,omitempty"` + EnableLatencyMetric bool `json:"enableLatencyMetric"` } // scope(Namespaced or Cluster) diff --git a/test/e2e/apphttphealth/apphttphealth_test.go b/test/e2e/apphttphealth/apphttphealth_test.go index 76de54f0..4520a992 100644 --- a/test/e2e/apphttphealth/apphttphealth_test.go +++ b/test/e2e/apphttphealth/apphttphealth_test.go @@ -71,7 +71,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -135,7 +135,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeFalse(), "compare report and task result") @@ -197,7 +197,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeFalse(), "compare report and task result") @@ -260,7 +260,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -325,7 +325,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, []string{}, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, []string{}, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeFalse(), "compare report and task result") @@ -387,7 +387,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -453,7 +453,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -515,7 +515,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -577,7 +577,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -639,7 +639,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -701,7 +701,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") @@ -766,7 +766,7 @@ var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") - success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum) + success, e := common.CompareResult(frame, appHttpHealthName, pluginManager.KindNameAppHttpHealthy, testPodIPs, reportNum, appHttpHealth) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") diff --git a/test/e2e/common/tools.go b/test/e2e/common/tools.go index c21cc575..e3e5131b 100644 --- a/test/e2e/common/tools.go +++ b/test/e2e/common/tools.go @@ -185,7 +185,7 @@ func GetPluginReportResult(f *frame.Framework, name string, n int) (*kdoctor_rep return report, nil } -func CompareResult(f *frame.Framework, name, taskKind string, podIPs []string, n int) (bool, error) { +func CompareResult(f *frame.Framework, name, taskKind string, podIPs []string, n int, object client.Object) (bool, error) { // get Aggregate API report var r *kdoctor_report.KdoctorReport @@ -204,6 +204,7 @@ func CompareResult(f *frame.Framework, name, taskKind string, podIPs []string, n } switch taskKind { case pluginManager.KindNameNetReach: + obj := object.(*v1beta1.NetReach) fake := &v1beta1.NetReach{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -215,6 +216,31 @@ func CompareResult(f *frame.Framework, name, taskKind string, podIPs []string, n return GetResultFromReport(r), fmt.Errorf("failed get resource AppHttpHealthy %s", name) } + if obj.Spec.Target.Ingress != rs.Spec.Target.Ingress { + return GetResultFromReport(r), fmt.Errorf("spec target ingress not equal input %v,output %v", obj.Spec.Target.Ingress, rs.Spec.Target.Ingress) + } + if obj.Spec.Target.EnableLatencyMetric != rs.Spec.Target.EnableLatencyMetric { + return GetResultFromReport(r), fmt.Errorf("spec target EnableLatencyMetric not equal input %v,output %v", obj.Spec.Target.EnableLatencyMetric, rs.Spec.Target.EnableLatencyMetric) + } + if obj.Spec.Target.Endpoint != rs.Spec.Target.Endpoint { + return GetResultFromReport(r), fmt.Errorf("spec target Endpoint not equal input %v,output %v", obj.Spec.Target.Endpoint, rs.Spec.Target.Endpoint) + } + if obj.Spec.Target.ClusterIP != rs.Spec.Target.ClusterIP { + return GetResultFromReport(r), fmt.Errorf("spec target ClusterIP not equal input %v,output %v", obj.Spec.Target.ClusterIP, rs.Spec.Target.ClusterIP) + } + if obj.Spec.Target.LoadBalancer != rs.Spec.Target.LoadBalancer { + return GetResultFromReport(r), fmt.Errorf("spec target LoadBalancer not equal input %v,output %v", obj.Spec.Target.LoadBalancer, rs.Spec.Target.LoadBalancer) + } + if obj.Spec.Target.MultusInterface != rs.Spec.Target.MultusInterface { + return GetResultFromReport(r), fmt.Errorf("spec target MultusInterface not equal input %v,output %v", obj.Spec.Target.MultusInterface, rs.Spec.Target.MultusInterface) + } + if *obj.Spec.Target.IPv4 != *rs.Spec.Target.IPv4 { + return GetResultFromReport(r), fmt.Errorf("spec target IPv4 not equal input %v,output %v", *obj.Spec.Target.IPv4, *rs.Spec.Target.IPv4) + } + if *obj.Spec.Target.IPv6 != *rs.Spec.Target.IPv6 { + return GetResultFromReport(r), fmt.Errorf("spec target LoadBalancer not equal input %v,output %v", *obj.Spec.Target.IPv6, *rs.Spec.Target.IPv6) + } + for _, v := range *r.Spec.Report { for _, m := range v.NetReachTask.Detail { // qps diff --git a/test/e2e/netdns/netdns_test.go b/test/e2e/netdns/netdns_test.go index 974ba00b..d45b7a4b 100644 --- a/test/e2e/netdns/netdns_test.go +++ b/test/e2e/netdns/netdns_test.go @@ -77,7 +77,7 @@ var _ = Describe("testing netDns ", Label("netDns"), func() { e = common.WaitKdoctorTaskDone(frame, netDns, pluginManager.KindNameNetdns, 120) Expect(e).NotTo(HaveOccurred(), "wait netDns task finish") - success, e := common.CompareResult(frame, netDnsName, pluginManager.KindNameNetdns, []string{}, reportNum) + success, e := common.CompareResult(frame, netDnsName, pluginManager.KindNameNetdns, []string{}, reportNum, netDns) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).NotTo(BeFalse(), "compare report and task result") @@ -145,7 +145,7 @@ var _ = Describe("testing netDns ", Label("netDns"), func() { e = common.WaitKdoctorTaskDone(frame, netDns, pluginManager.KindNameNetdns, 120) Expect(e).NotTo(HaveOccurred(), "wait netDns task finish") - success, e := common.CompareResult(frame, netDnsName, pluginManager.KindNameNetdns, testPodIPs, reportNum) + success, e := common.CompareResult(frame, netDnsName, pluginManager.KindNameNetdns, testPodIPs, reportNum, netDns) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result") diff --git a/test/e2e/netreach/netreach_test.go b/test/e2e/netreach/netreach_test.go index 6b061816..33ef7e0e 100644 --- a/test/e2e/netreach/netreach_test.go +++ b/test/e2e/netreach/netreach_test.go @@ -74,7 +74,7 @@ var _ = Describe("testing netReach ", Label("netReach"), func() { e = common.WaitKdoctorTaskDone(frame, netReach, pluginManager.KindNameNetReach, 120) Expect(e).NotTo(HaveOccurred(), "wait netReach task finish") - success, e := common.CompareResult(frame, netReachName, pluginManager.KindNameNetReach, []string{}, reportNum) + success, e := common.CompareResult(frame, netReachName, pluginManager.KindNameNetReach, []string{}, reportNum, netReach) Expect(e).NotTo(HaveOccurred(), "compare report and task") Expect(success).To(BeTrue(), "compare report and task result")