Skip to content

Commit dd01d2a

Browse files
committed
Allow skaffold dev —-watch-image name
Signed-off-by: David Gageot <[email protected]>
1 parent 3cfdf89 commit dd01d2a

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

cmd/skaffold/app/cmd/cmd.go

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func setFlagsFromEnvVariables(commands []*cobra.Command) {
129129

130130
func AddDevFlags(cmd *cobra.Command) {
131131
cmd.Flags().BoolVar(&opts.Cleanup, "cleanup", true, "Delete deployments after dev mode is interrupted")
132+
cmd.Flags().StringArrayVarP(&opts.Watch, "watch-image", "w", nil, "Choose which artifacts to watch. Artifacts with image names that contain the expression will be watched only. Default is to watch sources for all artifacts.")
132133
}
133134

134135
func AddRunDeployFlags(cmd *cobra.Command) {

pkg/skaffold/config/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type SkaffoldOptions struct {
3030
Profiles []string
3131
CustomTag string
3232
Namespace string
33+
Watch []string
3334
}
3435

3536
// Labels returns a map of labels to be applied to all deployed

pkg/skaffold/runner/runner.go

+19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"strings"
2526
"time"
2627

2728
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/bazel"
@@ -234,6 +235,10 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*v1
234235
for i := range artifacts {
235236
artifact := artifacts[i]
236237

238+
if !r.shouldWatch(artifact) {
239+
continue
240+
}
241+
237242
if err := watcher.Register(
238243
func() ([]string, error) { return dependenciesForArtifact(artifact) },
239244
func() { changed.Add(artifact) },
@@ -271,6 +276,20 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*v1
271276
return nil, watcher.Run(ctx, PollInterval, onChange)
272277
}
273278

279+
func (r *SkaffoldRunner) shouldWatch(artifact *v1alpha2.Artifact) bool {
280+
if len(r.opts.Watch) == 0 {
281+
return true
282+
}
283+
284+
for _, watchExpression := range r.opts.Watch {
285+
if strings.Contains(artifact.ImageName, watchExpression) {
286+
return true
287+
}
288+
}
289+
290+
return false
291+
}
292+
274293
// buildAndDeploy builds a subset of the artifacts and deploys everything.
275294
func (r *SkaffoldRunner) buildAndDeploy(ctx context.Context, out io.Writer, artifacts []*v1alpha2.Artifact, images *kubernetes.ImageList) error {
276295
firstRun := r.builds == nil

pkg/skaffold/runner/runner_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func TestBuildAndDeployAllArtifacts(t *testing.T) {
358358
runner := &SkaffoldRunner{
359359
Builder: builder,
360360
Deployer: deployer,
361+
opts: &config.SkaffoldOptions{},
361362
}
362363

363364
ctx := context.Background()

0 commit comments

Comments
 (0)