Skip to content

Commit cc7e317

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 186a3f5 commit cc7e317

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"
@@ -986,7 +987,20 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
986987
return sreconcile.ResultEmpty, e
987988
}
988989
default:
989-
if err := r.Storage.Archive(&artifact, dir, nil); err != nil {
990+
// Load ignore rules for archiving.
991+
ignoreDomain := strings.Split(dir, string(filepath.Separator))
992+
ps, err := sourceignore.LoadIgnorePatterns(dir, ignoreDomain)
993+
if err != nil {
994+
return sreconcile.ResultEmpty, serror.NewGeneric(
995+
fmt.Errorf("failed to load source ignore patterns from repository: %w", err),
996+
"SourceIgnoreError",
997+
)
998+
}
999+
if obj.Spec.Ignore != nil {
1000+
ps = append(ps, sourceignore.ReadPatterns(strings.NewReader(*obj.Spec.Ignore), ignoreDomain)...)
1001+
}
1002+
1003+
if err := r.Storage.Archive(&artifact, dir, SourceIgnoreFilter(ps, ignoreDomain)); err != nil {
9901004
e := serror.NewGeneric(
9911005
fmt.Errorf("unable to archive artifact to storage: %s", err),
9921006
sourcev1.ArchiveOperationFailedReason,

controllers/ocirepository_controller_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,27 @@ func TestOCIRepository_reconcileArtifact(t *testing.T) {
14231423
assertPaths: []string{
14241424
"latest.tar.gz",
14251425
},
1426+
afterFunc: func(g *WithT, obj *sourcev1.OCIRepository) {
1427+
g.Expect(obj.Status.Artifact.Checksum).To(Equal("de37cb640bfe6c789f2b131416d259747d5757f7fe5e1d9d48f32d8c30af5934"))
1428+
},
1429+
assertConditions: []metav1.Condition{
1430+
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for digest"),
1431+
},
1432+
},
1433+
{
1434+
name: "Artifact with source ignore",
1435+
targetPath: "testdata/oci/repository",
1436+
artifact: &sourcev1.Artifact{Revision: "revision"},
1437+
beforeFunc: func(obj *sourcev1.OCIRepository) {
1438+
obj.Spec.Ignore = pointer.String("foo.txt")
1439+
},
1440+
want: sreconcile.ResultSuccess,
1441+
assertPaths: []string{
1442+
"latest.tar.gz",
1443+
},
1444+
afterFunc: func(g *WithT, obj *sourcev1.OCIRepository) {
1445+
g.Expect(obj.Status.Artifact.Checksum).To(Equal("05aada03e3e3e96f5f85a8f31548d833974ce862be14942fb3313eef2df861ec"))
1446+
},
14261447
assertConditions: []metav1.Condition{
14271448
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for digest"),
14281449
},

0 commit comments

Comments
 (0)