Skip to content

Commit

Permalink
Revise package revision caching strategy (#4094)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbelamaric committed Nov 30, 2023
1 parent aff697d commit 82b7c85
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 121 deletions.
3 changes: 3 additions & 0 deletions e2e/testdata/porch/rpkg-update/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ commands:
stdout: |
NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY
git-3f036055f7ba68706372cbe0c4b14d553794f7c4 basens-edit update-1 false Draft git
git-804ab1a9d043e44255ef3fb77820d5ad7b1576a9 basens-edit update-3 main false Published git
git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 basens-edit update-3 v1 true Published git
git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 basens-edit-clone update-2 false Draft git
- args:
Expand All @@ -82,6 +83,7 @@ commands:
stdout: |
PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES
git-3f036055f7ba68706372cbe0c4b14d553794f7c4 No update available
git-804ab1a9d043e44255ef3fb77820d5ad7b1576a9 No update available
git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 No update available
git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git v1
- args:
Expand Down Expand Up @@ -110,6 +112,7 @@ commands:
stdout: |
PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES
git-3f036055f7ba68706372cbe0c4b14d553794f7c4 No update available
git-804ab1a9d043e44255ef3fb77820d5ad7b1576a9 No update available
git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 No update available
git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git No update available
- args:
Expand Down
18 changes: 15 additions & 3 deletions porch/pkg/cache/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cache

import (
"context"
"fmt"

"github.com/GoogleContainerTools/kpt/porch/pkg/repository"
)
Expand All @@ -28,9 +29,20 @@ type cachedDraft struct {
var _ repository.PackageDraft = &cachedDraft{}

func (cd *cachedDraft) Close(ctx context.Context) (repository.PackageRevision, error) {
if closed, err := cd.PackageDraft.Close(ctx); err != nil {
closed, err := cd.PackageDraft.Close(ctx)
if err != nil {
return nil, err
} else {
return cd.cache.update(ctx, closed)
}

err = cd.cache.reconcileCache(ctx, "close-draft")
if err != nil {
return nil, err
}

cpr := cd.cache.getPackageRevision(closed.Key())
if cpr == nil {
return nil, fmt.Errorf("closed draft not found")
}

return cpr, nil
}
Loading

0 comments on commit 82b7c85

Please sign in to comment.