Skip to content

Commit 8434429

Browse files
committed
OCIRepo: Implement source ignore
This implements source ignore in OCIRepositoryReconcilers' reconcileArtifact so that the ignore rules are considered when building the artifact. Adds tests based on the artifact checksum change when ignore rules are applied. Signed-off-by: Sunny <[email protected]>
1 parent c7112e9 commit 8434429

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

controllers/ocirepository_controller.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import (
6161
"github.com/fluxcd/pkg/runtime/events"
6262
"github.com/fluxcd/pkg/runtime/patch"
6363
"github.com/fluxcd/pkg/runtime/predicates"
64+
"github.com/fluxcd/pkg/sourceignore"
6465
"github.com/fluxcd/pkg/untar"
6566
"github.com/fluxcd/pkg/version"
6667
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
@@ -992,7 +993,20 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
992993
return sreconcile.ResultEmpty, e
993994
}
994995
default:
995-
if err := r.Storage.Archive(&artifact, dir, nil); err != nil {
996+
// Load ignore rules for archiving.
997+
ignoreDomain := strings.Split(dir, string(filepath.Separator))
998+
ps, err := sourceignore.LoadIgnorePatterns(dir, ignoreDomain)
999+
if err != nil {
1000+
return sreconcile.ResultEmpty, serror.NewGeneric(
1001+
fmt.Errorf("failed to load source ignore patterns from repository: %w", err),
1002+
"SourceIgnoreError",
1003+
)
1004+
}
1005+
if obj.Spec.Ignore != nil {
1006+
ps = append(ps, sourceignore.ReadPatterns(strings.NewReader(*obj.Spec.Ignore), ignoreDomain)...)
1007+
}
1008+
1009+
if err := r.Storage.Archive(&artifact, dir, SourceIgnoreFilter(ps, ignoreDomain)); err != nil {
9961010
e := serror.NewGeneric(
9971011
fmt.Errorf("unable to archive artifact to storage: %s", err),
9981012
sourcev1.ArchiveOperationFailedReason,

controllers/ocirepository_controller_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,27 @@ func TestOCIRepository_reconcileArtifact(t *testing.T) {
13921392
assertPaths: []string{
13931393
"latest.tar.gz",
13941394
},
1395+
afterFunc: func(g *WithT, obj *sourcev1.OCIRepository) {
1396+
g.Expect(obj.Status.Artifact.Checksum).To(Equal("de37cb640bfe6c789f2b131416d259747d5757f7fe5e1d9d48f32d8c30af5934"))
1397+
},
1398+
assertConditions: []metav1.Condition{
1399+
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for digest"),
1400+
},
1401+
},
1402+
{
1403+
name: "Artifact with source ignore",
1404+
targetPath: "testdata/oci/repository",
1405+
artifact: &sourcev1.Artifact{Revision: "revision"},
1406+
beforeFunc: func(obj *sourcev1.OCIRepository) {
1407+
obj.Spec.Ignore = pointer.String("foo.txt")
1408+
},
1409+
want: sreconcile.ResultSuccess,
1410+
assertPaths: []string{
1411+
"latest.tar.gz",
1412+
},
1413+
afterFunc: func(g *WithT, obj *sourcev1.OCIRepository) {
1414+
g.Expect(obj.Status.Artifact.Checksum).To(Equal("05aada03e3e3e96f5f85a8f31548d833974ce862be14942fb3313eef2df861ec"))
1415+
},
13951416
assertConditions: []metav1.Condition{
13961417
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for digest"),
13971418
},

0 commit comments

Comments
 (0)