Skip to content

Commit 2d6d49e

Browse files
Fix packagerevisions for repos with subdirs (#4097)
* Fix packagerevisions for repos with subdirs Signed-off-by: John Belamaric <[email protected]> * Update key used during deletion and close Signed-off-by: John Belamaric <[email protected]> * Fix erroneous and extraneous log message Signed-off-by: John Belamaric <[email protected]> --------- Signed-off-by: John Belamaric <[email protected]>
1 parent 82b7c85 commit 2d6d49e

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

porch/pkg/cache/cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re
119119
if !isPackageContent(repositorySpec.Spec.Content) {
120120
return nil, fmt.Errorf("git repository supports Package content only; got %q", string(repositorySpec.Spec.Content))
121121
}
122-
key := "git://" + gitSpec.Repo
122+
key := "git://" + gitSpec.Repo + gitSpec.Directory
123123

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

180180
default:
181181
return fmt.Errorf("unknown repository type: %q", repositorySpec.Spec.Type)

porch/pkg/cache/repository.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ func (r *cachedRepository) Close() error {
309309
// There isn't much use in returning an error here, so we just log it
310310
// and create a PackageRevisionMeta with just name and namespace. This
311311
// makes sure that the Delete event is sent.
312-
klog.Warningf("Error looking up PackageRev CR for %s: %v")
312+
if !apierrors.IsNotFound(err) {
313+
klog.Warningf("Error deleting PackageRev CR %s/%s: %s", nn.Namespace, nn.Name, err)
314+
}
313315
pkgRevMeta = meta.PackageRevisionMeta{
314316
Name: nn.Name,
315317
Namespace: nn.Namespace,

porch/pkg/git/git.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit
316316
if err != nil {
317317
return nil, fmt.Errorf("failed to load package draft %q: %w", name.String(), err)
318318
}
319-
draftLoaded += 1
319+
if draft != nil {
320+
draftLoaded += 1
321+
}
320322
}
321323
if draft != nil {
322324
drafts = append(drafts, draft)
@@ -342,7 +344,9 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit
342344
// this tag is not associated with any package (e.g. could be a release tag)
343345
continue
344346
}
345-
tagLoaded += 1
347+
if tagged != nil {
348+
tagLoaded += 1
349+
}
346350
}
347351
if tagged != nil && filter.Matches(tagged) {
348352
result = append(result, tagged)

porch/pkg/registry/porch/background.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (b *background) isSharedRepository(ctx context.Context, repo *configapi.Rep
174174
return true, nil
175175
}
176176
case configapi.RepositoryTypeGit:
177-
if r.Spec.Git.Repo == repo.Spec.Git.Repo {
177+
if r.Spec.Git.Repo == repo.Spec.Git.Repo && r.Spec.Git.Directory == repo.Spec.Git.Directory {
178178
return true, nil
179179
}
180180
default:

0 commit comments

Comments
 (0)