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

fix: Allow partial match for manual sync #9344

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions pkg/skaffold/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func autoSyncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon
}

func latestTag(image string, builds []graph.Artifact) string {
for _, build := range builds {
if build.ImageName == image {
return build.Tag
for _, _build := range builds {
if _build.ImageName == image {
return _build.Tag
}
}
return ""
Expand All @@ -239,8 +239,8 @@ func intersect(ctx context.Context, contextWd, containerWd string, syncRules []*
}

if len(dsts) == 0 {
log.Entry(ctx).Infof("Changed file %s does not match any sync pattern. Skipping sync", relPath)
return nil, nil
log.Entry(ctx).Infof("Changed file %s does not match any sync pattern. Skipping sync for it", relPath)
continue
}

ret[f] = dsts
Expand Down
72 changes: 71 additions & 1 deletion pkg/skaffold/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,58 @@ func TestNewSyncItem(t *testing.T) {
Delete: map[string][]string{},
},
},
{
description: "manual: match copy partial match first",
artifact: &latest.Artifact{
ImageName: "test",
Sync: &latest.Sync{
Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}},
},
Workspace: ".",
},
builds: []graph.Artifact{
{
ImageName: "test",
Tag: "test:123",
},
},
evt: filemon.Events{
Added: []string{"someOtherFile.txt", "index.html"},
},
expected: &Item{
Image: "test:123",
Copy: map[string][]string{
"index.html": {"index.html"},
},
Delete: map[string][]string{},
},
},
{
description: "manual: match copy partial match last",
artifact: &latest.Artifact{
ImageName: "test",
Sync: &latest.Sync{
Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}},
},
Workspace: ".",
},
builds: []graph.Artifact{
{
ImageName: "test",
Tag: "test:123",
},
},
evt: filemon.Events{
Added: []string{"index.html", "someOtherFile.txt"},
},
expected: &Item{
Image: "test:123",
Copy: map[string][]string{
"index.html": {"index.html"},
},
Delete: map[string][]string{},
},
},
{
description: "manual: no tag for image",
artifact: &latest.Artifact{
Expand Down Expand Up @@ -217,6 +269,13 @@ func TestNewSyncItem(t *testing.T) {
Tag: "placeholder",
},
},
expected: &Item{
Image: "placeholder",
Copy: map[string][]string{},
Delete: map[string][]string{
"index.html": {"index.html"},
},
},
},
{
description: "manual: not delete syncable",
Expand All @@ -237,6 +296,13 @@ func TestNewSyncItem(t *testing.T) {
Tag: "placeholder",
},
},
expected: &Item{
Image: "placeholder",
Copy: map[string][]string{
"index.html": {"/static/index.html"},
},
Delete: map[string][]string{},
},
},
{
description: "manual: err bad pattern",
Expand Down Expand Up @@ -715,7 +781,11 @@ func TestNewSyncItem(t *testing.T) {
}]
}`,
},
expected: nil,
expected: &Item{
Image: "test:123",
Copy: map[string][]string{},
Delete: map[string][]string{},
},
},

// Auto with Jib
Expand Down