Skip to content

Commit

Permalink
fix bugs to trim container id in pod spec
Browse files Browse the repository at this point in the history
  • Loading branch information
waynepeking348 committed Aug 1, 2023
1 parent 83bce0c commit 998b8c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/metaserver/agent/metric/malachite/client/client_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/malachite/types"
cgroupcm "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
"github.com/kubewharf/katalyst-core/pkg/util/general"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

func (c *MalachiteClient) GetAllPodContainersStats(ctx context.Context) (map[string]map[string]*types.MalachiteCgroupInfo, error) {
Expand Down Expand Up @@ -55,12 +56,13 @@ func (c *MalachiteClient) GetPodStats(ctx context.Context, podUID string) (map[s

containersStats := make(map[string]*types.MalachiteCgroupInfo)
for _, containerStatus := range pod.Status.ContainerStatuses {
stats, err := c.GetPodContainerStats(podUID, containerStatus.ContainerID)
containerID := native.TrimContainerIDPrefix(containerStatus.ContainerID)
stats, err := c.GetPodContainerStats(podUID, containerID)
if err != nil {
general.Errorf("GetPodStats err %v", err)
continue
}
containersStats[containerStatus.ContainerID] = stats
containersStats[containerID] = stats
}
return containersStats, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func TestGetPodContainerStats(t *testing.T) {
ContainerStatuses: []v1.ContainerStatus{
{
Name: "p1-c-name1",
ContainerID: "p1-c-uid1",
ContainerID: "docker://p1-c-uid1",
},
{
Name: "p1-c-name2",
ContainerID: "p1-c-uid2",
ContainerID: "containerd://p1-c-uid2",
},
},
},
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestGetPodContainerStats(t *testing.T) {
ContainerStatuses: []v1.ContainerStatus{
{
Name: "p3-c-name1",
ContainerID: "p3-c-uid1",
ContainerID: "containerd://p3-c-uid1",
},
},
},
Expand All @@ -142,7 +142,7 @@ func TestGetPodContainerStats(t *testing.T) {
ContainerStatuses: []v1.ContainerStatus{
{
Name: "p4-c-name1",
ContainerID: "p4-c-uid1",
ContainerID: "containerd://p4-c-uid1",
},
},
},
Expand Down

0 comments on commit 998b8c8

Please sign in to comment.