func (dc *DockerCenter) CreateInfoDetail(info *docker.Container, envConfigPrefix string, selfConfigFlag bool) *DockerInfoDetail {
	containerNameTag := make(map[string]string)
	k8sInfo := K8SInfo{}
	ip := dc.GetIPAddress(info)

	containerNameTag["_image_name_"] = dc.GetImageName(info.Image, info.Config.Image)
	if strings.HasPrefix(info.Name, "/k8s_") || strings.HasPrefix(info.Name, "k8s_") || strings.Count(info.Name, "_") >= 4 {
		// 1. container name is k8s
		// k8s_php-redis_frontend-2337258262-154p7_default_d8a2e2dd-3617-11e7-a4b0-ecf4bbe5d414_0
		// terway_terway-multi-ip-mgslw_kube-system_b07b491e-995a-11e9-94ea-00163e080931_8
		tags := strings.SplitN(info.Name, "_", 6)
		// containerNamePrefix：k8s
		// containerName：php-redis
		// podFullName：frontend-2337258262-154p7
		// computeHash：154p7
		// deploymentName：frontend
		// replicaSetName：frontend-2337258262
		// namespace：default
		// podUID：d8a2e2dd-3617-11e7-a4b0-ecf4bbe5d414

		baseIndex := 0
		if len(tags) == 6 {
			baseIndex = 1
		}
		containerNameTag["_container_name_"] = tags[baseIndex]
		containerNameTag["_pod_name_"] = tags[baseIndex+1]
		containerNameTag["_namespace_"] = tags[baseIndex+2]
		containerNameTag["_pod_uid_"] = tags[baseIndex+3]
		k8sInfo.ContainerName = tags[baseIndex]
		k8sInfo.Pod = tags[baseIndex+1]
		k8sInfo.Namespace = tags[baseIndex+2]
		k8sInfo.ExtractK8sLabels(info)
	} else if _, ok := info.Config.Labels[k8sPodNameLabel]; ok {
		// 2. container labels has k8sPodNameLabel
		containerNameTag["_container_name_"] = info.Name
		containerNameTag["_pod_name_"] = info.Config.Labels[k8sPodNameLabel]
		containerNameTag["_namespace_"] = info.Config.Labels[k8sPodNameSpaceLabel]
		containerNameTag["_pod_uid_"] = info.Config.Labels[k8sPodUUIDLabel]
		k8sInfo.ContainerName = info.Name
		k8sInfo.Pod = info.Config.Labels[k8sPodNameLabel]
		k8sInfo.Namespace = info.Config.Labels[k8sPodNameSpaceLabel]
		// the following method is couped with the CRI adapter, only the original docker container labels
		// would be added to the labels of the k8s info.
		k8sInfo.ExtractK8sLabels(info)
	} else {
		// 3. treat as normal container
		if strings.HasPrefix(info.Name, "/") {
			containerNameTag["_container_name_"] = info.Name[1:]
		} else {
			containerNameTag["_container_name_"] = info.Name
		}
	}
	if len(ip) > 0 {
		containerNameTag["_container_ip_"] = ip
	}

	did := &DockerInfoDetail{
		ContainerInfo:    info,
		ContainerNameTag: containerNameTag,
		K8SInfo:          &k8sInfo,
		ContainerIP:      ip,
		lastUpdateTime:   time.Now(),
	}
	did.FindAllEnvConfig(envConfigPrefix, selfConfigFlag)
	// @note for overlayfs only, some driver like nas, you can not see it in upper dir
	if info.GraphDriver != nil && info.GraphDriver.Data != nil {
		if rootPath, ok := did.ContainerInfo.GraphDriver.Data["UpperDir"]; ok {
			did.DefaultRootPath = rootPath
		}
	}
	// for cri-runtime
	if criRuntimeWrapper != nil && info.HostConfig != nil && len(did.DefaultRootPath) == 0 {
		did.DefaultRootPath = lookupContainerRootfsAbsDir(info)
	}
	logger.Debugf(context.Background(), "container(id: %s, name: %s) default root path is %s", info.ID, info.Name, did.DefaultRootPath)
	return did
}
// CreateInfoDetail create DockerInfoDetail with docker.Container
// Container property used in this function : HostsPath, Config.Hostname, Name, Config.Image, Config.Env, Mounts
//                                            ContainerInfo.GraphDriver.Data["UpperDir"] Config.Labels
CreateInfoDetail create DockerInfoDetail with docker.Container
Container property used in this function : HostsPath, Config.Hostname, Name, Config.Image, Config.Env, Mounts
ContainerInfo.GraphDriver.Data["UpperDir"] Config.Labels
// CreateInfoDetail create DockerInfoDetail with docker . Container // Container property used in this function : HostsPath Config . Hostname Name Config . Image Config . Env Mounts // ContainerInfo . GraphDriver . Data [ " UpperDir " ] Config . Labels
func (dc *DockerCenter) CreateInfoDetail(info *docker.Container, envConfigPrefix string, selfConfigFlag bool) *DockerInfoDetail {
	containerNameTag := make(map[string]string)
	k8sInfo := K8SInfo{}
	ip := dc.GetIPAddress(info)
	containerNameTag["_image_name_"] = dc.GetImageName(info.Image, info.Config.Image)
	if strings.HasPrefix(info.Name, "/k8s_") || strings.HasPrefix(info.Name, "k8s_") || strings.Count(info.Name, "_") >= 4 {
		tags := strings.SplitN(info.Name, "_", 6)
		baseIndex := 0
		if len(tags) == 6 {
			baseIndex = 1
		}
		containerNameTag["_container_name_"] = tags[baseIndex]
		containerNameTag["_pod_name_"] = tags[baseIndex+1]
		containerNameTag["_namespace_"] = tags[baseIndex+2]
		containerNameTag["_pod_uid_"] = tags[baseIndex+3]
		k8sInfo.ContainerName = tags[baseIndex]
		k8sInfo.Pod = tags[baseIndex+1]
		k8sInfo.Namespace = tags[baseIndex+2]
		k8sInfo.ExtractK8sLabels(info)
	} else if _, ok := info.Config.Labels[k8sPodNameLabel]; ok {
		containerNameTag["_container_name_"] = info.Name
		containerNameTag["_pod_name_"] = info.Config.Labels[k8sPodNameLabel]
		containerNameTag["_namespace_"] = info.Config.Labels[k8sPodNameSpaceLabel]
		containerNameTag["_pod_uid_"] = info.Config.Labels[k8sPodUUIDLabel]
		k8sInfo.ContainerName = info.Name
		k8sInfo.Pod = info.Config.Labels[k8sPodNameLabel]
		k8sInfo.Namespace = info.Config.Labels[k8sPodNameSpaceLabel]
		k8sInfo.ExtractK8sLabels(info)
	} else {
		if strings.HasPrefix(info.Name, "/") {
			containerNameTag["_container_name_"] = info.Name[1:]
		} else {
			containerNameTag["_container_name_"] = info.Name
		}
	}
	if len(ip) > 0 {
		containerNameTag["_container_ip_"] = ip
	}
	did := &DockerInfoDetail{
		ContainerInfo:    info,
		ContainerNameTag: containerNameTag,
		K8SInfo:          &k8sInfo,
		ContainerIP:      ip,
		lastUpdateTime:   time.Now(),
	}
	did.FindAllEnvConfig(envConfigPrefix, selfConfigFlag)
	if info.GraphDriver != nil && info.GraphDriver.Data != nil {
		if rootPath, ok := did.ContainerInfo.GraphDriver.Data["UpperDir"]; ok {
			did.DefaultRootPath = rootPath
		}
	}
	if criRuntimeWrapper != nil && info.HostConfig != nil && len(did.DefaultRootPath) == 0 {
		did.DefaultRootPath = lookupContainerRootfsAbsDir(info)
	}
	logger.Debugf(context.Background(), "container(id: %s, name: %s) default root path is %s", info.ID, info.Name, did.DefaultRootPath)
	return did
}
func ( dc * DockerCenter ) CreateInfoDetail ( info * docker . Container , envConfigPrefix string , selfConfigFlag bool ) * DockerInfoDetail { containerNameTag := make ( map [ string ] string ) k8sInfo := K8SInfo { } ip := dc . GetIPAddress ( info ) containerNameTag [ " " ] = dc . GetImageName ( info . Image , info . Config . Image ) if strings . HasPrefix ( info . Name , " " ) || strings . HasPrefix ( info . Name , " " ) || strings . Count ( info . Name , " " ) >= 4 { tags := strings . SplitN ( info . Name , " " , 6 ) baseIndex := 0 if len ( tags ) == 6 { baseIndex = 1 } containerNameTag [ " " ] = tags [ baseIndex ] containerNameTag [ " " ] = tags [ baseIndex + 1 ] containerNameTag [ " " ] = tags [ baseIndex + 2 ] containerNameTag [ " " ] = tags [ baseIndex + 3 ] k8sInfo . ContainerName = tags [ baseIndex ] k8sInfo . Pod = tags [ baseIndex + 1 ] k8sInfo . Namespace = tags [ baseIndex + 2 ] k8sInfo . ExtractK8sLabels ( info ) } else if _ , ok := info . Config . Labels [ k8sPodNameLabel ] ; ok { containerNameTag [ " " ] = info . Name containerNameTag [ " " ] = info . Config . Labels [ k8sPodNameLabel ] containerNameTag [ " " ] = info . Config . Labels [ k8sPodNameSpaceLabel ] containerNameTag [ " " ] = info . Config . Labels [ k8sPodUUIDLabel ] k8sInfo . ContainerName = info . Name k8sInfo . Pod = info . Config . Labels [ k8sPodNameLabel ] k8sInfo . Namespace = info . Config . Labels [ k8sPodNameSpaceLabel ] k8sInfo . ExtractK8sLabels ( info ) } else { if strings . HasPrefix ( info . Name , " " ) { containerNameTag [ " " ] = info . Name [ 1 : ] } else { containerNameTag [ " " ] = info . Name } } if len ( ip ) > 0 { containerNameTag [ " " ] = ip } did := & DockerInfoDetail { ContainerInfo : info , ContainerNameTag : containerNameTag , K8SInfo : & k8sInfo , ContainerIP : ip , lastUpdateTime : time . Now ( ) , } did . FindAllEnvConfig ( envConfigPrefix , selfConfigFlag ) if info . GraphDriver != nil && info . GraphDriver . Data != nil { if rootPath , ok := did . ContainerInfo . GraphDriver . Data [ " " ] ; ok { did . DefaultRootPath = rootPath } } if criRuntimeWrapper != nil && info . HostConfig != nil && len ( did . DefaultRootPath ) == 0 { did . DefaultRootPath = lookupContainerRootfsAbsDir ( info ) } logger . Debugf ( context . Background ( ) , " " , info . ID , info . Name , did . DefaultRootPath ) return did }
CreateInfoDetail create DockerInfoDetail with docker.Container
Container property used in this function : HostsPath, Config.Hostname, Name, Config.Image, Config.Env, Mounts
ContainerInfo.GraphDriver.Data["UpperDir"] Config.Labels
CreateInfoDetail create DockerInfoDetail with docker . Container Container property used in this function : HostsPath Config . Hostname Name Config . Image Config . Env Mounts ContainerInfo . GraphDriver . Data [ " UpperDir " ] Config . Labels
// 1. container name is k8s // k8s_php-redis_frontend-2337258262-154p7_default_d8a2e2dd-3617-11e7-a4b0-ecf4bbe5d414_0 // terway_terway-multi-ip-mgslw_kube-system_b07b491e-995a-11e9-94ea-00163e080931_8 // containerNamePrefix：k8s // containerName：php-redis // podFullName：frontend-2337258262-154p7 // computeHash：154p7 // deploymentName：frontend // replicaSetName：frontend-2337258262 // namespace：default // podUID：d8a2e2dd-3617-11e7-a4b0-ecf4bbe5d414 // 2. container labels has k8sPodNameLabel // the following method is couped with the CRI adapter, only the original docker container labels // would be added to the labels of the k8s info. // 3. treat as normal container // @note for overlayfs only, some driver like nas, you can not see it in upper dir // for cri-runtime