-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding container name to log config #9627
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -166,6 +166,7 @@ func (l *Logger) streamLogsFromKubernetesJob(ctx context.Context, id, namespace | |||||||||||
} | ||||||||||||
} | ||||||||||||
var podName string | ||||||||||||
var containerName string | ||||||||||||
w, err := clientset.CoreV1().Pods(namespace).Watch(ctx, | ||||||||||||
metav1.ListOptions{ | ||||||||||||
LabelSelector: labels.Set(map[string]string{"job-name": id, "skaffold.dev/run-id": l.labeller.GetRunID()}).String(), | ||||||||||||
|
@@ -180,6 +181,7 @@ func (l *Logger) streamLogsFromKubernetesJob(ctx context.Context, id, namespace | |||||||||||
pod, ok := event.Object.(*corev1.Pod) | ||||||||||||
if ok { | ||||||||||||
podName = pod.Name | ||||||||||||
containerName = pod.Spec.Containers[0].Name | ||||||||||||
done <- true | ||||||||||||
break | ||||||||||||
} | ||||||||||||
|
@@ -195,9 +197,7 @@ func (l *Logger) streamLogsFromKubernetesJob(ctx context.Context, id, namespace | |||||||||||
return false, fmt.Errorf("timeout waiting for event from pod of kubernetes job: %s", id) | ||||||||||||
} | ||||||||||||
|
||||||||||||
podLogOptions := &corev1.PodLogOptions{ | ||||||||||||
Follow: true, | ||||||||||||
} | ||||||||||||
podLogOptions := &corev1.PodLogOptions{Follow: true, Container: containerName} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good practice to check if
Suggested change
|
||||||||||||
|
||||||||||||
// Stream the logs | ||||||||||||
req := clientset.CoreV1().Pods(namespace).GetLogs(podName, podLogOptions) | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line assumes the pod has only one container, taking the name of the first container in the spec. Jobs can have multiple containers. Consider adding a mechanism to specify the target container. A few options include:
--container
flag: Allow users to specify the container name via a command-line flag.skaffold.yaml
configuration: Add a field in theskaffold.yaml
to configure the target container for logging.Choosing a suitable approach will provide flexibility and prevent unexpected behavior when jobs have multiple containers.