✨ feat:TSG-18258
This commit is contained in:
@@ -123,25 +123,33 @@ func getContainerId(pid string) (string, error) {
|
|||||||
return containerID, nil
|
return containerID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get image name by container id
|
// get container info by container id
|
||||||
func getImageName(container_id string, sock_path string) (string, error) {
|
func getContainerInfo(container_id string, sock_path string) (string, string, error) {
|
||||||
// connect to containerd daemon
|
// connect to containerd daemon
|
||||||
client, err := containerd.New(sock_path)
|
client, err := containerd.New(sock_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
// according to container id to get container info
|
// according to container id to get container info
|
||||||
ctx := namespaces.WithNamespace(context.Background(), "k8s.io")
|
ctx := namespaces.WithNamespace(context.Background(), "k8s.io")
|
||||||
container, err := client.LoadContainer(ctx, container_id)
|
container, err := client.LoadContainer(ctx, container_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
imageRef, err := container.Image(ctx)
|
imageRef, err := container.Image(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
return imageRef.Name(), nil
|
label, err := container.Labels(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
pod_name, ok := label["io.kubernetes.pod.name"]
|
||||||
|
if !ok {
|
||||||
|
return imageRef.Name(), "", nil
|
||||||
|
}
|
||||||
|
return imageRef.Name(), pod_name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// write coredump info to file
|
// write coredump info to file
|
||||||
@@ -336,7 +344,7 @@ func main() {
|
|||||||
//find image name
|
//find image name
|
||||||
if err == nil && len(container_id) != 0 {
|
if err == nil && len(container_id) != 0 {
|
||||||
coredump_config.Container_id = container_id
|
coredump_config.Container_id = container_id
|
||||||
coredump_config.Image_name, err = getImageName(container_id, pipe_config.Containered_sock_path)
|
coredump_config.Image_name, coredump_config.Pod_name, err = getContainerInfo(container_id, pipe_config.Containered_sock_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriInfo, err.Error())
|
journal.Print(journal.PriInfo, err.Error())
|
||||||
}
|
}
|
||||||
@@ -347,6 +355,9 @@ func main() {
|
|||||||
if coredump_config.Image_name == "" {
|
if coredump_config.Image_name == "" {
|
||||||
coredump_config.Image_name = "NULL"
|
coredump_config.Image_name = "NULL"
|
||||||
}
|
}
|
||||||
|
if coredump_config.Pod_name == "" {
|
||||||
|
coredump_config.Pod_name = "NULL"
|
||||||
|
}
|
||||||
//write coredump file
|
//write coredump file
|
||||||
if !pipe_config.Compress {
|
if !pipe_config.Compress {
|
||||||
if pipe_config.Storage_type == 1 {
|
if pipe_config.Storage_type == 1 {
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ func info(pid string) {
|
|||||||
{Text: "GID"},
|
{Text: "GID"},
|
||||||
{Text: "SIG"},
|
{Text: "SIG"},
|
||||||
{Text: "EXE"},
|
{Text: "EXE"},
|
||||||
{Text: "CONTAINER"},
|
{Text: "POD"},
|
||||||
{Text: "IMAGE"},
|
{Text: "IMAGE"},
|
||||||
{Text: "HOSTNAME"},
|
{Text: "HOSTNAME"},
|
||||||
{Text: "STORAGE"},
|
{Text: "STORAGE"},
|
||||||
@@ -152,7 +152,7 @@ func info(pid string) {
|
|||||||
{Text: c.GID},
|
{Text: c.GID},
|
||||||
{Text: strconv.Itoa(c.Signal)},
|
{Text: strconv.Itoa(c.Signal)},
|
||||||
{Text: c.Process_exe_path},
|
{Text: c.Process_exe_path},
|
||||||
{Text: c.Container_id},
|
{Text: c.Pod_name},
|
||||||
{Text: c.Image_name},
|
{Text: c.Image_name},
|
||||||
{Text: c.Hostname},
|
{Text: c.Hostname},
|
||||||
{Text: c.Storage},
|
{Text: c.Storage},
|
||||||
@@ -342,7 +342,7 @@ func debugInpod(conf *rest.Config, clientset *kubernetes.Clientset, config types
|
|||||||
ready = true
|
ready = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
}
|
}
|
||||||
if !ready {
|
if !ready {
|
||||||
return podName, errors.New("create pod timeout")
|
return podName, errors.New("create pod timeout")
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type Coredump_config struct {
|
|||||||
Timestamp int64
|
Timestamp int64
|
||||||
Corepipe_config_path string `json:"-"`
|
Corepipe_config_path string `json:"-"`
|
||||||
Container_id string
|
Container_id string
|
||||||
|
Pod_name string
|
||||||
Image_name string
|
Image_name string
|
||||||
UID string
|
UID string
|
||||||
GID string
|
GID string
|
||||||
|
|||||||
Reference in New Issue
Block a user