Skip to content

Commit 0e3bf24

Browse files
committed
Allow skaffold dev —filter image
Signed-off-by: David Gageot <[email protected]>
1 parent 80a04db commit 0e3bf24

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
@@ -128,6 +128,7 @@ func setFlagsFromEnvVariables(commands []*cobra.Command) {
128128

129129
func AddDevFlags(cmd *cobra.Command) {
130130
cmd.Flags().BoolVar(&opts.Cleanup, "cleanup", true, "Delete deployments after dev mode is interrupted")
131+
cmd.Flags().StringArrayVar(&opts.Watch, "watch", nil, "Choose which artifacts to watch. Matches against image names. If not specified, all artifacts are watched")
131132
}
132133

133134
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"
@@ -228,6 +229,10 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*v1
228229
for i := range artifacts {
229230
artifact := artifacts[i]
230231

232+
if !r.shouldWatch(artifact) {
233+
continue
234+
}
235+
231236
if err := watcher.Register(
232237
func() ([]string, error) { return dependenciesForArtifact(artifact) },
233238
func() { changed.Add(artifact) },
@@ -265,6 +270,20 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*v1
265270
return nil, watcher.Run(ctx, PollInterval, onChange)
266271
}
267272

273+
func (r *SkaffoldRunner) shouldWatch(artifact *v1alpha2.Artifact) bool {
274+
if len(r.opts.Watch) == 0 {
275+
return true
276+
}
277+
278+
for _, name := range r.opts.Watch {
279+
if strings.Contains(artifact.ImageName, name) {
280+
return true
281+
}
282+
}
283+
284+
return false
285+
}
286+
268287
// buildAndDeploy builds a subset of the artifacts and deploys everything.
269288
func (r *SkaffoldRunner) buildAndDeploy(ctx context.Context, out io.Writer, artifacts []*v1alpha2.Artifact, images *kubernetes.ImageList) error {
270289
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)