From a83a4bc10e886e43457f3bec60924b663b2b75aa Mon Sep 17 00:00:00 2001 From: ezmcdja Date: Thu, 17 Oct 2024 14:07:48 +0100 Subject: [PATCH] Add package directory to ListPackageRevision filtering - make revision incrementation on rpkg approve work with --directory repos - add new Directory attribute to PackageRevisionKey - and use it when matching PackageRevisions to filter out from the List operation - package approval flow looks for previous copies of the package to determine new latest revision string (e.g. v1 -> v2) - this involves matching the package-for-approval's path attribute against existing packages' packageName attribute - however: - when a repo is registered using --directory to associate it with a subfolder in the upstream Git repo, packageName is deliberately trimmed of the directory attribute if it exists - but the path in the package-for-approval still has the directory part - so no existing packages can match to be counted as previous copies - therefore the revision can never increase beyond "v1" and the v1 tag is overwritten in Git with each new approval - this also results in previous package copies disappearing --- pkg/git/package.go | 1 + pkg/repository/repository.go | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/git/package.go b/pkg/git/package.go index b23c05f0..551701fe 100644 --- a/pkg/git/package.go +++ b/pkg/git/package.go @@ -102,6 +102,7 @@ func (p *gitPackageRevision) Key() repository.PackageRevisionKey { return repository.PackageRevisionKey{ Repository: p.repo.name, + Directory: p.repo.directory, Package: packageName, Revision: p.revision, WorkspaceName: p.workspaceName, diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index 2bd0b041..30e040a1 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -17,6 +17,7 @@ package repository import ( "context" "fmt" + "strings" "github.com/go-git/go-git/v5/plumbing/transport" "github.com/nephio-project/porch/api/porch/v1alpha1" @@ -31,13 +32,13 @@ type PackageResources struct { } type PackageRevisionKey struct { - Repository, Package, Revision string - WorkspaceName v1alpha1.WorkspaceName + Repository, Directory, Package, Revision string + WorkspaceName v1alpha1.WorkspaceName } func (n PackageRevisionKey) String() string { - return fmt.Sprintf("Repository: %q, Package: %q, Revision: %q, WorkspaceName: %q", - n.Repository, n.Package, n.Revision, string(n.WorkspaceName)) + return fmt.Sprintf("Repository: %q, Directory: %q, Package: %q, Revision: %q, WorkspaceName: %q", + n.Repository, n.Directory, n.Package, n.Revision, string(n.WorkspaceName)) } type PackageKey struct { @@ -149,13 +150,18 @@ type ListPackageRevisionFilter struct { // Matches returns true if the provided PackageRevision satisfies the conditions in the filter. func (f *ListPackageRevisionFilter) Matches(p PackageRevision) bool { - if f.Package != "" && f.Package != p.Key().Package { + packageKey := p.Key() + + fullPackagePath := strings.TrimPrefix( + fmt.Sprintf("%s/%s", packageKey.Directory, packageKey.Package), + "/") + if f.Package != "" && f.Package != fullPackagePath { return false } - if f.Revision != "" && f.Revision != p.Key().Revision { + if f.Revision != "" && f.Revision != packageKey.Revision { return false } - if f.WorkspaceName != "" && f.WorkspaceName != p.Key().WorkspaceName { + if f.WorkspaceName != "" && f.WorkspaceName != packageKey.WorkspaceName { return false } if f.KubeObjectName != "" && f.KubeObjectName != p.KubeObjectName() {