// printTestFailureDebugInfo will output the status of Build, BuildRun, TaskRun and Pod, also print logs of Pod
printTestFailureDebugInfo will output the status of Build, BuildRun, TaskRun and Pod, also print logs of Pod
// printTestFailureDebugInfo will output the status of Build BuildRun TaskRun and Pod also print logs of Pod
func printTestFailureDebugInfo(namespace string, buildRunName string) {
	Logf("Print failed BuildRun's log")
	f := framework.Global
	buildRun, build, err := retrieveBuildAndBuildRun(namespace, buildRunName)
	if build != nil {
		Logf("The status of Build %s: registered=%s, reason=%s", build.Name, build.Status.Registered, build.Status.Reason)
		if buildJSON, err := json.Marshal(build); err == nil {
			Logf("The full Build: %s", string(buildJSON))
		}
	}
	if buildRun != nil {
		brCondition := buildRun.Status.GetCondition(operator.Succeeded)
		if brCondition != nil {
			Logf("The status of BuildRun %s: status=%s, reason=%s", buildRun.Name, brCondition.Status, brCondition.Reason)
		}
		if buildRunJSON, err := json.Marshal(buildRun); err == nil {
			Logf("The full BuildRun: %s", string(buildRunJSON))
		}
		podName := ""
		if os.Getenv(EnvVarVerifyTektonObjects) == "true" {
			if taskRun, _ := getTaskRun(f, buildRun); taskRun != nil {
				condition := taskRun.Status.GetCondition(apis.ConditionSucceeded)
				if condition != nil {
					Logf("The status of TaskRun %s: reason=%s, message=%s", taskRun.Name, condition.Reason, condition.Message)
				}
				if taskRunJSON, err := json.Marshal(taskRun); err == nil {
					Logf("The full TaskRun: %s", string(taskRunJSON))
				}
				podName = taskRun.Status.PodName
			}
		}
		var pod *v1.Pod
		if podName != "" {
			pod = &v1.Pod{}
			if err = clientGet(types.NamespacedName{Name: podName, Namespace: namespace}, pod); err != nil {
				Logf("Error retrieving pod %s: %v", podName, err)
				pod = nil
			}
		} else {
			listOptions := client.ListOptions{
				Namespace: namespace,
				LabelSelector: labels.SelectorFromSet(map[string]string{
					operator.LabelBuildRun: buildRunName,
				}),
			}
			podList := &v1.PodList{}
			if err = f.Client.List(context.TODO(), podList, &listOptions); err == nil && len(podList.Items) > 0 {
				pod = &podList.Items[0]
			}
		}
		if pod != nil {
			Logf("The status of Pod %s: phase=%s, reason=%s, message=%s", pod.Name, pod.Status.Phase, pod.Status.Reason, pod.Status.Message)
			if podJSON, err := json.Marshal(pod); err == nil {
				Logf("The full Pod: %s", string(podJSON))
			}
			for _, container := range pod.Spec.Containers {
				req := f.KubeClient.CoreV1().Pods(namespace).GetLogs(pod.Name, &v1.PodLogOptions{
					TypeMeta:  metav1.TypeMeta{},
					Container: container.Name,
					Follow:    false,
				})
				podLogs, err := req.Stream(context.TODO())
				if err != nil {
					Logf("Failed to retrieve the logs of container %s: %v", container.Name, err)
					continue
				}
				buf := new(bytes.Buffer)
				_, err = io.Copy(buf, podLogs)
				if err != nil {
					Logf("Failed to copy logs of container %s to buffer: %v", container.Name, err)
					continue
				}
				Logf("Logs of container %s: %s", container.Name, buf.String())
			}
		}
	}
}
func printTestFailureDebugInfo ( namespace string , buildRunName string ) { Logf ( " " ) f := framework . Global buildRun , build , err := retrieveBuildAndBuildRun ( namespace , buildRunName ) if build != nil { Logf ( " " , build . Name , build . Status . Registered , build . Status . Reason ) if buildJSON , err := json . Marshal ( build ) ; err == nil { Logf ( " " , string ( buildJSON ) ) } } if buildRun != nil { brCondition := buildRun . Status . GetCondition ( operator . Succeeded ) if brCondition != nil { Logf ( " " , buildRun . Name , brCondition . Status , brCondition . Reason ) } if buildRunJSON , err := json . Marshal ( buildRun ) ; err == nil { Logf ( " " , string ( buildRunJSON ) ) } podName := " " if os . Getenv ( EnvVarVerifyTektonObjects ) == " " { if taskRun , _ := getTaskRun ( f , buildRun ) ; taskRun != nil { condition := taskRun . Status . GetCondition ( apis . ConditionSucceeded ) if condition != nil { Logf ( " " , taskRun . Name , condition . Reason , condition . Message ) } if taskRunJSON , err := json . Marshal ( taskRun ) ; err == nil { Logf ( " " , string ( taskRunJSON ) ) } podName = taskRun . Status . PodName } } var pod * v1 . Pod if podName != " " { pod = & v1 . Pod { } if err = clientGet ( types . NamespacedName { Name : podName , Namespace : namespace } , pod ) ; err != nil { Logf ( " " , podName , err ) pod = nil } } else { listOptions := client . ListOptions { Namespace : namespace , LabelSelector : labels . SelectorFromSet ( map [ string ] string { operator . LabelBuildRun : buildRunName , } ) , } podList := & v1 . PodList { } if err = f . Client . List ( context . TODO ( ) , podList , & listOptions ) ; err == nil && len ( podList . Items ) > 0 { pod = & podList . Items [ 0 ] } } if pod != nil { Logf ( " " , pod . Name , pod . Status . Phase , pod . Status . Reason , pod . Status . Message ) if podJSON , err := json . Marshal ( pod ) ; err == nil { Logf ( " " , string ( podJSON ) ) } for _ , container := range pod . Spec . Containers { req := f . KubeClient . CoreV1 ( ) . Pods ( namespace ) . GetLogs ( pod . Name , & v1 . PodLogOptions { TypeMeta : metav1 . TypeMeta { } , Container : container . Name , Follow : false , } ) podLogs , err := req . Stream ( context . TODO ( ) ) if err != nil { Logf ( " " , container . Name , err ) continue } buf := new ( bytes . Buffer ) _ , err = io . Copy ( buf , podLogs ) if err != nil { Logf ( " " , container . Name , err ) continue } Logf ( " " , container . Name , buf . String ( ) ) } } } }
printTestFailureDebugInfo will output the status of Build, BuildRun, TaskRun and Pod, also print logs of Pod
printTestFailureDebugInfo will output the status of Build BuildRun TaskRun and Pod also print logs of Pod
// Only log details of TaskRun if Tekton objects can be accessed // retrieve or query pod depending on whether we have the pod name from the TaskRun // Loop through the containers to print their logs