コード例 #1
0
ファイル: pod.go プロジェクト: asyoume/paas_srv
// kubenetes pod to protobuf struct
func PodToPbStruct(pod *api.Pod) *types.Pod {
	todata := &types.Pod{
		Id:   string(pod.GetUID()),
		Name: pod.GetName(),
	}
	pod_container := pod.Spec.Containers
	// 解析容器信息
	container := make([]*types.Container, len(pod_container))
	for k, v := range pod_container {
		container[k] = &types.Container{
			Name:  v.Name,
			Image: v.Image,
		}
		// 解析空间挂载信息
		VolumeMounts := make([]*types.VolumeMount, len(v.VolumeMounts))
		for k2, v2 := range v.VolumeMounts {
			VolumeMounts[k2] = &types.VolumeMount{
				Name:      v2.Name,
				ReadOnly:  v2.ReadOnly,
				MountPath: v2.MountPath,
			}
		}
		// 解析端口映射信息
		containerPort := make([]*types.ContainerPort, len(v.Ports))
		for k2, port := range v.Ports {
			containerPort[k2] = &types.ContainerPort{
				Name:          port.Name,
				Protocol:      string(port.Protocol),
				ContainerPort: int64(port.ContainerPort),
			}
		}
		container[k].Port = containerPort
	}
	todata.Containers = container
	return todata
}