Skip to content

Commit

Permalink
Add package directory to ListPackageRevision filtering
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
JamesMcDermott committed Oct 17, 2024
1 parent a3d7d29 commit a83a4bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/git/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a83a4bc

Please sign in to comment.