Skip to content

Commit

Permalink
Fix packagerevisions for repos with subdirs (#4097)
Browse files Browse the repository at this point in the history
* Fix packagerevisions for repos with subdirs

Signed-off-by: John Belamaric <jbelamaric@google.com>

* Update key used during deletion and close

Signed-off-by: John Belamaric <jbelamaric@google.com>

* Fix erroneous and extraneous log message

Signed-off-by: John Belamaric <jbelamaric@google.com>

---------

Signed-off-by: John Belamaric <jbelamaric@google.com>
  • Loading branch information
johnbelamaric authored Nov 30, 2023
1 parent 82b7c85 commit 2d6d49e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions porch/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re
if !isPackageContent(repositorySpec.Spec.Content) {
return nil, fmt.Errorf("git repository supports Package content only; got %q", string(repositorySpec.Spec.Content))
}
key := "git://" + gitSpec.Repo
key := "git://" + gitSpec.Repo + gitSpec.Directory

c.mutex.Lock()
defer c.mutex.Unlock()
Expand Down Expand Up @@ -175,7 +175,7 @@ func (c *Cache) CloseRepository(repositorySpec *configapi.Repository) error {
if git == nil {
return fmt.Errorf("git not configured for %s:%s", repositorySpec.ObjectMeta.Namespace, repositorySpec.ObjectMeta.Name)
}
key = "git://" + git.Repo
key = "git://" + git.Repo + git.Directory

default:
return fmt.Errorf("unknown repository type: %q", repositorySpec.Spec.Type)
Expand Down
4 changes: 3 additions & 1 deletion porch/pkg/cache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ func (r *cachedRepository) Close() error {
// There isn't much use in returning an error here, so we just log it
// and create a PackageRevisionMeta with just name and namespace. This
// makes sure that the Delete event is sent.
klog.Warningf("Error looking up PackageRev CR for %s: %v")
if !apierrors.IsNotFound(err) {
klog.Warningf("Error deleting PackageRev CR %s/%s: %s", nn.Namespace, nn.Name, err)
}
pkgRevMeta = meta.PackageRevisionMeta{
Name: nn.Name,
Namespace: nn.Namespace,
Expand Down
8 changes: 6 additions & 2 deletions porch/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit
if err != nil {
return nil, fmt.Errorf("failed to load package draft %q: %w", name.String(), err)
}
draftLoaded += 1
if draft != nil {
draftLoaded += 1
}
}
if draft != nil {
drafts = append(drafts, draft)
Expand All @@ -342,7 +344,9 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit
// this tag is not associated with any package (e.g. could be a release tag)
continue
}
tagLoaded += 1
if tagged != nil {
tagLoaded += 1
}
}
if tagged != nil && filter.Matches(tagged) {
result = append(result, tagged)
Expand Down
2 changes: 1 addition & 1 deletion porch/pkg/registry/porch/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (b *background) isSharedRepository(ctx context.Context, repo *configapi.Rep
return true, nil
}
case configapi.RepositoryTypeGit:
if r.Spec.Git.Repo == repo.Spec.Git.Repo {
if r.Spec.Git.Repo == repo.Spec.Git.Repo && r.Spec.Git.Directory == repo.Spec.Git.Directory {
return true, nil
}
default:
Expand Down

0 comments on commit 2d6d49e

Please sign in to comment.