From 554f21043580e007ad34b01a652d494ec5389cba Mon Sep 17 00:00:00 2001 From: Cheng-Zhang <2694824893@qq.com> Date: Mon, 27 May 2024 21:19:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20pilot=20sidecar=20mapping=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/kubeclient/client.go | 2 +- pkg/kubelet/kubelet.go | 4 ++-- pkg/microservice/pilot/pilot.go | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/kubeclient/client.go b/pkg/kubeclient/client.go index c8850f2..00d2a3c 100644 --- a/pkg/kubeclient/client.go +++ b/pkg/kubeclient/client.go @@ -302,7 +302,7 @@ func (c *client) UploadPodMetrics(metrics []*v1.PodRawMetrics) error { metricsStr, _ := json.Marshal(metrics) - fmt.Printf("upload metrics str: %s\n", string(metricsStr)) + // fmt.Printf("upload metrics str: %s\n", string(metricsStr)) req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(metricsStr)) if err != nil { diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 6931e04..a485c23 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -105,7 +105,7 @@ func (kl *Kubelet) syncLoopIteration(ctx context.Context, configCh <-chan types. case <-syncCh: // TODO 定时同步Pod信息到metrics collector allPods, err := kl.runtimeManager.GetAllPods() - log.Printf("allPods: %v\n", allPods) + // log.Printf("allPods: %v\n", allPods) if err != nil { log.Printf("Failed to get all pods: %v\n", err) return true @@ -113,7 +113,7 @@ func (kl *Kubelet) syncLoopIteration(ctx context.Context, configCh <-chan types. // 由allPods取到所有的status var podStatusList []*runtime.PodStatus for _, pod := range allPods { - log.Printf("pod: %v\n", pod) + // log.Printf("pod: %v\n", pod) podStatus, err := kl.runtimeManager.GetPodStatus(pod.ID, pod.Name, pod.Namespace) if err != nil { log.Printf("Failed to get pod %v status: %v\n", pod.Name, err) diff --git a/pkg/microservice/pilot/pilot.go b/pkg/microservice/pilot/pilot.go index 4cb8937..53fc4e7 100644 --- a/pkg/microservice/pilot/pilot.go +++ b/pkg/microservice/pilot/pilot.go @@ -158,7 +158,7 @@ func (p *pilot) syncLoopIteration() error { //println(fmt.Sprintf(":%d", port)) } } - newMap := make(map[int32]*v1.ServiceAndEndpoints) + newMap := make(map[string]*v1.ServiceAndEndpoints) for uid, portSs := range waitedServiceUidAndPorts { endpointsWithPodName := make(map[string]v1.Endpoint) service := endpointMap[uid].Service @@ -201,7 +201,7 @@ func (p *pilot) syncLoopIteration() error { Ports: ports, } } - newMap[port_i] = &v1.ServiceAndEndpoints{ + newMap[p.getFullPort(service.UID, port_i)] = &v1.ServiceAndEndpoints{ Service: service, EndpointsMapWithPodName: endpointsWithPodName, } @@ -211,7 +211,8 @@ func (p *pilot) syncLoopIteration() error { defaultWeight := int32(1) for port, serviceAndEndpoints := range newMap { - stringIP := serviceAndEndpoints.Service.Spec.ClusterIP + fmt.Sprintf(":%d", port) + _, port_i := p.splitFullPort(port) + stringIP := serviceAndEndpoints.Service.Spec.ClusterIP + fmt.Sprintf(":%d", port_i) var sidecarEndpoints []v1.SidecarEndpoints for _, endpoint := range serviceAndEndpoints.EndpointsMapWithPodName { var singleEndPoints []v1.SingleEndpoint