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 <darkowlzz@protonmail.com>
This commit is contained in:
parent
f4aed8baf8
commit
dcd0db406e
|
@ -61,6 +61,7 @@ import (
|
|||
"github.com/fluxcd/pkg/runtime/events"
|
||||
"github.com/fluxcd/pkg/runtime/patch"
|
||||
"github.com/fluxcd/pkg/runtime/predicates"
|
||||
"github.com/fluxcd/pkg/sourceignore"
|
||||
"github.com/fluxcd/pkg/untar"
|
||||
"github.com/fluxcd/pkg/version"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||
|
@ -992,7 +993,20 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
|
|||
return sreconcile.ResultEmpty, e
|
||||
}
|
||||
default:
|
||||
if err := r.Storage.Archive(&artifact, dir, nil); err != nil {
|
||||
// Load ignore rules for archiving.
|
||||
ignoreDomain := strings.Split(dir, string(filepath.Separator))
|
||||
ps, err := sourceignore.LoadIgnorePatterns(dir, ignoreDomain)
|
||||
if err != nil {
|
||||
return sreconcile.ResultEmpty, serror.NewGeneric(
|
||||
fmt.Errorf("failed to load source ignore patterns from repository: %w", err),
|
||||
"SourceIgnoreError",
|
||||
)
|
||||
}
|
||||
if obj.Spec.Ignore != nil {
|
||||
ps = append(ps, sourceignore.ReadPatterns(strings.NewReader(*obj.Spec.Ignore), ignoreDomain)...)
|
||||
}
|
||||
|
||||
if err := r.Storage.Archive(&artifact, dir, SourceIgnoreFilter(ps, ignoreDomain)); err != nil {
|
||||
e := serror.NewGeneric(
|
||||
fmt.Errorf("unable to archive artifact to storage: %s", err),
|
||||
sourcev1.ArchiveOperationFailedReason,
|
||||
|
|
|
@ -1392,6 +1392,27 @@ func TestOCIRepository_reconcileArtifact(t *testing.T) {
|
|||
assertPaths: []string{
|
||||
"latest.tar.gz",
|
||||
},
|
||||
afterFunc: func(g *WithT, obj *sourcev1.OCIRepository) {
|
||||
g.Expect(obj.Status.Artifact.Checksum).To(Equal("de37cb640bfe6c789f2b131416d259747d5757f7fe5e1d9d48f32d8c30af5934"))
|
||||
},
|
||||
assertConditions: []metav1.Condition{
|
||||
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for digest"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Artifact with source ignore",
|
||||
targetPath: "testdata/oci/repository",
|
||||
artifact: &sourcev1.Artifact{Revision: "revision"},
|
||||
beforeFunc: func(obj *sourcev1.OCIRepository) {
|
||||
obj.Spec.Ignore = pointer.String("foo.txt")
|
||||
},
|
||||
want: sreconcile.ResultSuccess,
|
||||
assertPaths: []string{
|
||||
"latest.tar.gz",
|
||||
},
|
||||
afterFunc: func(g *WithT, obj *sourcev1.OCIRepository) {
|
||||
g.Expect(obj.Status.Artifact.Checksum).To(Equal("05aada03e3e3e96f5f85a8f31548d833974ce862be14942fb3313eef2df861ec"))
|
||||
},
|
||||
assertConditions: []metav1.Condition{
|
||||
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for digest"),
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue