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