Skip to content

Commit 1df51de

Browse files
authored
Merge pull request #612 from dgageot/simpler-logs
Simpler code that logs containers
2 parents b0d0b12 + ebdd127 commit 1df51de

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

pkg/skaffold/kaniko/kaniko.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func RunKanikoBuild(ctx context.Context, out io.Writer, artifact *v1alpha2.Artif
4747
}
4848

4949
imageList := kubernetes.NewImageList()
50-
imageList.AddImage(constants.DefaultKanikoImage)
50+
imageList.Add(constants.DefaultKanikoImage)
5151

5252
logger := kubernetes.NewLogAggregator(out, imageList, kubernetes.NewColorPicker([]*v1alpha2.Artifact{artifact}))
5353
if err := logger.Start(ctx); err != nil {
@@ -104,7 +104,7 @@ func RunKanikoBuild(ctx context.Context, out io.Writer, artifact *v1alpha2.Artif
104104
}
105105

106106
defer func() {
107-
imageList.RemoveImage(constants.DefaultKanikoImage)
107+
imageList.Remove(constants.DefaultKanikoImage)
108108
if err := client.CoreV1().Pods("default").Delete(p.Name, &metav1.DeleteOptions{
109109
GracePeriodSeconds: new(int64),
110110
}); err != nil {

pkg/skaffold/kubernetes/log.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (a *LogAggregator) Start(ctx context.Context) error {
9191
}
9292

9393
if a.podSelector.Select(pod) {
94-
go a.streamLogs(ctx, client, pod)
94+
a.streamLogs(ctx, client, pod)
9595
}
9696
}
9797
}
@@ -102,9 +102,6 @@ func (a *LogAggregator) Start(ctx context.Context) error {
102102

103103
func (a *LogAggregator) streamLogs(ctx context.Context, client corev1.PodsGetter, pod *v1.Pod) error {
104104
pods := client.Pods(pod.Namespace)
105-
if err := WaitForPodReady(pods, pod.Name); err != nil {
106-
return errors.Wrap(err, "waiting for pod ready")
107-
}
108105

109106
for _, container := range pod.Status.ContainerStatuses {
110107
containerID := container.ContainerID
@@ -248,14 +245,15 @@ func NewImageList() *ImageList {
248245
}
249246
}
250247

251-
// AddImage adds an image to the list.
252-
func (l *ImageList) AddImage(image string) {
248+
// Add adds an image to the list.
249+
func (l *ImageList) Add(image string) {
253250
l.Lock()
254251
l.names[image] = true
255252
l.Unlock()
256253
}
257254

258-
func (l *ImageList) RemoveImage(image string) {
255+
// Remove removes an image from the list.
256+
func (l *ImageList) Remove(image string) {
259257
l.Lock()
260258
delete(l.names, image)
261259
l.Unlock()

pkg/skaffold/runner/runner.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ func (r *SkaffoldRunner) watchBuildDeploy(ctx context.Context, out io.Writer, ar
193193
return errors.Wrap(err, "creating deploy watcher")
194194
}
195195

196-
podSelector := kubernetes.NewImageList()
196+
imageList := kubernetes.NewImageList()
197197
colorPicker := kubernetes.NewColorPicker(artifacts)
198-
logger := kubernetes.NewLogAggregator(out, podSelector, colorPicker)
198+
logger := kubernetes.NewLogAggregator(out, imageList, colorPicker)
199199

200200
onChange := func(changedPaths []string) error {
201201
logger.Mute()
@@ -215,7 +215,7 @@ func (r *SkaffoldRunner) watchBuildDeploy(ctx context.Context, out io.Writer, ar
215215

216216
// Update which images are logged.
217217
for _, build := range bRes {
218-
podSelector.AddImage(build.Tag)
218+
imageList.Add(build.Tag)
219219
}
220220

221221
// Make sure all artifacts are redeployed. Not only those that were just rebuilt.

0 commit comments

Comments
 (0)