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 Oct 9, 2023
1 parent bcad019 commit bf1ed3d
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 64 deletions.
12 changes: 6 additions & 6 deletions pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ type NetReachTarget struct {
IPv6 *bool `json:"ipv6,omitempty"`

// +kubebuilder:default=true
Endpoint bool `json:"endpoint,omitempty"`
Endpoint *bool `json:"endpoint,omitempty"`

// +kubebuilder:default=false
MultusInterface bool `json:"multusInterface,omitempty"`
MultusInterface *bool `json:"multusInterface,omitempty"`

// +kubebuilder:default=true
ClusterIP bool `json:"clusterIP,omitempty"`
ClusterIP *bool `json:"clusterIP,omitempty"`

// +kubebuilder:default=true
NodePort bool `json:"nodePort,omitempty"`
NodePort *bool `json:"nodePort,omitempty"`

// +kubebuilder:default=false
LoadBalancer bool `json:"loadBalancer,omitempty"`
LoadBalancer *bool `json:"loadBalancer,omitempty"`

// +kubebuilder:default=false
Ingress bool `json:"ingress,omitempty"`
Ingress *bool `json:"ingress,omitempty"`

// +kubebuilder:default=false
// +kubebuilder:validation:Optional
Expand Down
30 changes: 30 additions & 0 deletions pkg/k8s/apis/kdoctor.io/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/loadRequest/loadHttp/http_requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Work struct {
// DisableCompression is an option to disable compression in response
DisableCompression bool

// DisableKeepAlives is an option to prevents re-use of TCP connections between different HTTP requests
// DisableKeepAlives is an option to prevents reuse of TCP connections between different HTTP requests
DisableKeepAlives bool

// DisableRedirects is an option to prevent the following of HTTP redirects
Expand Down
4 changes: 2 additions & 2 deletions pkg/pluginManager/controllerReconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type pluginControllerReconciler struct {
tracker *scheduler.Tracker
}

// contorller reconcile
// (1) chedule all task time
// controller reconcile
// (1) schedule all task time
// (2) update stauts result
// (3) collect report from agent
func (s *pluginControllerReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/pluginManager/netreach/agentExecuteTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
logger.Sugar().Infof("load test kdoctor Agent pod: qps=%v, PerRequestTimeout=%vs, Duration=%vs", request.QPS, request.PerRequestTimeoutInMS, request.DurationInSecond)
finalfailureReason = ""

if target.Endpoint {
podIPs, e := getTargetPodIP(ctx, runtimeResource.RuntimeName, runtimeResource.RuntimeType, target.MultusInterface)
if *target.Endpoint {
podIPs, e := getTargetPodIP(ctx, runtimeResource.RuntimeName, runtimeResource.RuntimeType, *target.MultusInterface)
if e != nil {
logger.Sugar().Debugf("test agent pod ip: %v", podIPs)
if e != nil {
Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
logger.Sugar().Errorf("failed to get agent ipv6 service url , error=%v", e)
}
}
if target.ClusterIP {
if *target.ClusterIP {
// ----------------------- test clusterIP ipv4
if target.IPv4 != nil && *(target.IPv4) {
if agentV4Url != nil && len(agentV4Url.ClusterIPUrl) > 0 {
Expand All @@ -163,7 +163,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
}

// ----------------------- test clusterIP ipv6
if target.ClusterIP && target.IPv6 != nil && *(target.IPv6) {
if *target.ClusterIP && target.IPv6 != nil && *(target.IPv6) {
if agentV6Url != nil && len(agentV6Url.ClusterIPUrl) > 0 {
testTargetList = append(testTargetList, &TestTarget{
Name: "AgentClusterV6IP_" + agentV6Url.ClusterIPUrl[0],
Expand All @@ -178,7 +178,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
}
}

if target.NodePort {
if *target.NodePort {
// get node ip
localNodeIpv4, localNodeIpv6, e := k8sObjManager.GetK8sObjManager().GetNodeIP(ctx, config.AgentConfig.LocalNodeName)
if e != nil {
Expand Down Expand Up @@ -217,7 +217,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
}
}

if target.LoadBalancer {
if *target.LoadBalancer {
if target.IPv4 != nil && *(target.IPv4) {
if agentV4Url != nil && len(agentV4Url.LoadBalancerUrl) > 0 {
testTargetList = append(testTargetList, &TestTarget{
Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
}
}

if target.Ingress {
if *target.Ingress {
if runtimeResource.ServiceNameV4 != nil {
agentIngress, e := k8sObjManager.GetK8sObjManager().GetIngress(ctx, *runtimeResource.ServiceNameV4, config.AgentConfig.PodNamespace)
if e != nil {
Expand Down
14 changes: 8 additions & 6 deletions pkg/pluginManager/netreach/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ func (s *PluginNetReach) WebhookMutating(logger *zap.Logger, ctx context.Context

enableIpv4 := types.ControllerConfig.Configmap.EnableIPv4
enableIpv6 := types.ControllerConfig.Configmap.EnableIPv6
enable := true
disable := false
m := &crd.NetReachTarget{
Endpoint: true,
MultusInterface: false,
ClusterIP: true,
NodePort: true,
LoadBalancer: testLoadBalancer,
Ingress: testIngress,
Endpoint: &enable,
MultusInterface: &disable,
ClusterIP: &enable,
NodePort: &enable,
LoadBalancer: &testLoadBalancer,
Ingress: &testIngress,
IPv6: &enableIpv6,
IPv4: &enableIpv4,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s *Scheduler) CreateTaskRuntimeIfNotExist(ctx context.Context, ownerTask m

if s.taskKind == types.KindNameNetReach {
nr := ownerTask.(*v1beta1.NetReach)
if nr.Spec.Target.Ingress {
if *nr.Spec.Target.Ingress {
err = s.createIngress(ctx, serviceNameV4, runtime)
if nil != err {
return v1beta1.TaskResource{}, fmt.Errorf("failed to create runtime IPv4 ingress for task '%s/%s', error: %w", s.taskKind, s.taskName, err)
Expand Down
26 changes: 13 additions & 13 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 Expand Up @@ -828,7 +828,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
32 changes: 29 additions & 3 deletions 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 IPv6 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 Expand Up @@ -632,7 +658,7 @@ func checkAgentSpec(f *frame.Framework, task client.Object, agentSpec v1beta1.Ag
}
if taskKind == kdoctor_types.KindNameNetReach {
taskNr := task.(*v1beta1.NetReach)
if taskNr.Spec.Target.Ingress {
if *taskNr.Spec.Target.Ingress {
ig := &networkingv1.Ingress{}
fake := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -678,7 +704,7 @@ func CheckRuntimeDeadLine(f *frame.Framework, taskName, taskKind string, timeout
done = true
runtimeResource = rs.Status.Resource
terminationGracePeriodMinutes = *rs.Spec.AgentSpec.TerminationGracePeriodMinutes
testIngress = rs.Spec.Target.Ingress
testIngress = *rs.Spec.Target.Ingress
break
}
time.Sleep(time.Second * interval)
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
Loading

0 comments on commit bf1ed3d

Please sign in to comment.