Skip to content

Commit

Permalink
fix: pilot sidecar mapping输出不正确
Browse files Browse the repository at this point in the history
  • Loading branch information
sjtuzc954 committed May 27, 2024
1 parent 0bd1a0e commit 554f210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/kubeclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ 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
}
// 由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)
Expand Down
7 changes: 4 additions & 3 deletions pkg/microservice/pilot/pilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand All @@ -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
Expand Down

0 comments on commit 554f210

Please sign in to comment.