Skip to content

Commit

Permalink
Fixed the netreach target configuration not taking effect
Browse files Browse the repository at this point in the history
Signed-off-by: ii2day <ji.li@daocloud.io>
  • Loading branch information
ii2day committed Sep 28, 2023
1 parent 885761c commit 15f7e57
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
20 changes: 13 additions & 7 deletions pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/apphttphealth/apphttphealth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
28 changes: 27 additions & 1 deletion test/e2e/common/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/netdns/netdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/netreach/netreach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 15f7e57

Please sign in to comment.