diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index 6fe953077be..4a13b87884c 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -130,6 +130,10 @@ func AddDevFlags(cmd *cobra.Command) { cmd.Flags().BoolVar(&opts.Cleanup, "cleanup", true, "Delete deployments after dev mode is interrupted") } +func AddRunDeployFlags(cmd *cobra.Command) { + cmd.Flags().BoolVar(&opts.Tail, "tail", false, "Stream logs from deployed objects") +} + func AddRunDevFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file") cmd.Flags().BoolVar(&opts.Notification, "toot", false, "Emit a terminal beep after the deploy is complete") diff --git a/cmd/skaffold/app/cmd/deploy.go b/cmd/skaffold/app/cmd/deploy.go index 61594488f58..049423891e6 100644 --- a/cmd/skaffold/app/cmd/deploy.go +++ b/cmd/skaffold/app/cmd/deploy.go @@ -23,6 +23,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -42,6 +43,7 @@ func NewCmdDeploy(out io.Writer) *cobra.Command { }, } AddRunDevFlags(cmd) + AddRunDeployFlags(cmd) cmd.Flags().StringSliceVar(&images, "images", nil, "A list of images to deploy") cmd.Flags().BoolVarP(&quietFlag, "quiet", "q", false, "Suppress the deploy output") return cmd @@ -50,7 +52,7 @@ func NewCmdDeploy(out io.Writer) *cobra.Command { func runDeploy(out io.Writer) error { ctx := context.Background() - r, _, err := newRunner(opts) + r, config, err := newRunner(opts) if err != nil { return errors.Wrap(err, "creating runner") } @@ -72,6 +74,25 @@ func runDeploy(out io.Writer) error { }) } - _, err = r.Deploy(ctx, deployOut, builds) - return err + if _, err := r.Deploy(ctx, deployOut, builds); err != nil { + return err + } + + if !opts.Tail { + return nil + } + // If tail is true, stream logs from deployed objects + imageList := kubernetes.NewImageList() + for _, b := range builds { + imageList.Add(b.Tag) + } + colorPicker := kubernetes.NewColorPicker(config.Build.Artifacts) + logger := kubernetes.NewLogAggregator(out, imageList, colorPicker) + + if err := logger.Start(ctx); err != nil { + return errors.Wrap(err, "starting logger") + } + + <-ctx.Done() + return nil } diff --git a/cmd/skaffold/app/cmd/run.go b/cmd/skaffold/app/cmd/run.go index 064c5f5df82..5ac02c717b0 100644 --- a/cmd/skaffold/app/cmd/run.go +++ b/cmd/skaffold/app/cmd/run.go @@ -35,6 +35,7 @@ func NewCmdRun(out io.Writer) *cobra.Command { }, } AddRunDevFlags(cmd) + AddRunDeployFlags(cmd) cmd.Flags().StringVarP(&opts.CustomTag, "tag", "t", "", "The optional custom tag to use for images which overrides the current Tagger configuration") return cmd diff --git a/pkg/skaffold/config/options.go b/pkg/skaffold/config/options.go index 937aef73db9..4b9cdb3fdc3 100644 --- a/pkg/skaffold/config/options.go +++ b/pkg/skaffold/config/options.go @@ -26,6 +26,7 @@ type SkaffoldOptions struct { ConfigurationFile string Cleanup bool Notification bool + Tail bool Profiles []string CustomTag string Namespace string diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index ba94c8509b6..cfe51b8b211 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -172,6 +172,21 @@ func (r *SkaffoldRunner) Run(ctx context.Context, out io.Writer, artifacts []*v1 return errors.Wrap(err, "deploy step") } + if !r.opts.Tail { + return nil + } + // If tail is true, stream logs from deployed objects + imageList := kubernetes.NewImageList() + for _, b := range bRes { + imageList.Add(b.Tag) + } + colorPicker := kubernetes.NewColorPicker(artifacts) + logger := kubernetes.NewLogAggregator(out, imageList, colorPicker) + if err := logger.Start(ctx); err != nil { + return errors.Wrap(err, "starting logger") + } + + <-ctx.Done() return nil } diff --git a/pkg/skaffold/runner/runner_test.go b/pkg/skaffold/runner/runner_test.go index 7ad44bf586c..1ae74de758e 100644 --- a/pkg/skaffold/runner/runner_test.go +++ b/pkg/skaffold/runner/runner_test.go @@ -266,6 +266,7 @@ func TestRun(t *testing.T) { Builder: test.builder, Deployer: test.deployer, Tagger: &tag.ChecksumTagger{}, + opts: &config.SkaffoldOptions{}, } err := runner.Run(context.Background(), ioutil.Discard, test.config.Build.Artifacts)