diff --git a/pkg/registry/apis/provisioning/jobs/sync/changes.go b/pkg/registry/apis/provisioning/jobs/sync/changes.go index 3de6b63480b..c25c7963f1b 100644 --- a/pkg/registry/apis/provisioning/jobs/sync/changes.go +++ b/pkg/registry/apis/provisioning/jobs/sync/changes.go @@ -121,6 +121,11 @@ func Changes(source []repository.FileTreeEntry, target *provisioning.ResourceLis continue } + // Ignore file change for `.keep` folders + if strings.HasSuffix(file.Path, ".keep") { + continue + } + changes = append(changes, ResourceFileChange{ Action: repository.FileActionCreated, // or previously ignored/failed Path: safeSegment, diff --git a/pkg/registry/apis/provisioning/jobs/sync/changes_test.go b/pkg/registry/apis/provisioning/jobs/sync/changes_test.go index aec6d0078ba..b5d86e0ab52 100644 --- a/pkg/registry/apis/provisioning/jobs/sync/changes_test.go +++ b/pkg/registry/apis/provisioning/jobs/sync/changes_test.go @@ -451,6 +451,38 @@ func TestChanges(t *testing.T) { Path: "folder2/", }, changes[2]) }) + + t.Run("report correct changes with .keep files", func(t *testing.T) { + // Replicating how `source` is actually being passed in `Changes` function + source := []repository.FileTreeEntry{ + {Path: "folder1/", Hash: "abc", Blob: false}, + {Path: "folder1/.keep", Hash: "abc", Blob: true}, + {Path: "folder1/dashboard.json", Hash: "def", Blob: true}, + {Path: "folder2/", Hash: "ghi", Blob: false}, + {Path: "folder2/.keep", Hash: "ghi", Blob: true}, + } + target := &provisioning.ResourceList{} + + changes, err := Changes(source, target) + require.NoError(t, err) + // 2 folders and 1 file, so 3 changes in total + require.Len(t, changes, 3) + + require.Equal(t, ResourceFileChange{ + Action: repository.FileActionCreated, + Path: "folder1/dashboard.json", + }, changes[0]) + + require.Equal(t, ResourceFileChange{ + Action: repository.FileActionCreated, + Path: "folder1/", + }, changes[1]) + + require.Equal(t, ResourceFileChange{ + Action: repository.FileActionCreated, + Path: "folder2/", + }, changes[2]) + }) } func TestCompare(t *testing.T) {