Skip to content
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

Simpler code that logs containers #612

Merged
merged 2 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/skaffold/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RunKanikoBuild(ctx context.Context, out io.Writer, artifact *v1alpha2.Artif
}

imageList := kubernetes.NewImageList()
imageList.AddImage(constants.DefaultKanikoImage)
imageList.Add(constants.DefaultKanikoImage)

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

defer func() {
imageList.RemoveImage(constants.DefaultKanikoImage)
imageList.Remove(constants.DefaultKanikoImage)
if err := client.CoreV1().Pods("default").Delete(p.Name, &metav1.DeleteOptions{
GracePeriodSeconds: new(int64),
}); err != nil {
Expand Down
12 changes: 5 additions & 7 deletions pkg/skaffold/kubernetes/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (a *LogAggregator) Start(ctx context.Context) error {
}

if a.podSelector.Select(pod) {
go a.streamLogs(ctx, client, pod)
a.streamLogs(ctx, client, pod)
}
}
}
Expand All @@ -102,9 +102,6 @@ func (a *LogAggregator) Start(ctx context.Context) error {

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

for _, container := range pod.Status.ContainerStatuses {
containerID := container.ContainerID
Expand Down Expand Up @@ -248,14 +245,15 @@ func NewImageList() *ImageList {
}
}

// AddImage adds an image to the list.
func (l *ImageList) AddImage(image string) {
// Add adds an image to the list.
func (l *ImageList) Add(image string) {
l.Lock()
l.names[image] = true
l.Unlock()
}

func (l *ImageList) RemoveImage(image string) {
// Remove removes an image from the list.
func (l *ImageList) Remove(image string) {
l.Lock()
delete(l.names, image)
l.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ func (r *SkaffoldRunner) watchBuildDeploy(ctx context.Context, out io.Writer, ar
return errors.Wrap(err, "creating deploy watcher")
}

podSelector := kubernetes.NewImageList()
imageList := kubernetes.NewImageList()
colorPicker := kubernetes.NewColorPicker(artifacts)
logger := kubernetes.NewLogAggregator(out, podSelector, colorPicker)
logger := kubernetes.NewLogAggregator(out, imageList, colorPicker)

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

// Update which images are logged.
for _, build := range bRes {
podSelector.AddImage(build.Tag)
imageList.Add(build.Tag)
}

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