Skip to content

Commit

Permalink
extend error propagation from initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
yorugac committed Dec 6, 2023
1 parent e5bd333 commit b73b126
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
err error
)
if err = c.List(ctx, podList, listOpts); err != nil {
returnErr = err
log.Error(err, "Could not list pods")
return
}

if len(podList.Items) < 1 {
log.Info("No initializing pod found yet")
return
Expand All @@ -65,12 +67,14 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
config, err := rest.InClusterConfig()
if err != nil {
log.Error(err, "unable to fetch in-cluster REST config")
returnErr = err
return
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Error(err, "unable to get access to clientset")
returnErr = err
return
}
req := clientset.CoreV1().Pods(k6.NamespacedName().Namespace).GetLogs(podList.Items[0].Name, &corev1.PodLogOptions{
Expand All @@ -82,12 +86,13 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
podLogs, err := req.Stream(ctx)
if err != nil {
log.Error(err, "unable to stream logs from the pod")
returnErr = err
return
}
defer podLogs.Close()

buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
_, returnErr = io.Copy(buf, podLogs)
if err != nil {
log.Error(err, "unable to copy logs from the pod")
return
Expand Down

0 comments on commit b73b126

Please sign in to comment.