Skip to content

Commit

Permalink
Merge pull request nephio-project#87 from Nordix/refresh-cache
Browse files Browse the repository at this point in the history
#678 Blueprint isn't immediately available after creation
  • Loading branch information
nephio-prow[bot] authored Jul 22, 2024
2 parents 05ae047 + ab2644b commit c4b36b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/cache/repository.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The kpt and Nephio Authors
// Copyright 2022,2024 The kpt and Nephio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -87,6 +87,13 @@ func newRepository(id string, repoSpec *configapi.Repository, repo repository.Re
return r
}

func (r *cachedRepository) RefreshCache(ctx context.Context) error {

_, _, err := r.refreshAllCachedPackages(ctx)

return err
}

func (r *cachedRepository) Version(ctx context.Context) (string, error) {
return r.repo.Version(ctx)
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The kpt and Nephio Authors
// Copyright 2022,2024 The kpt and Nephio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -706,6 +706,15 @@ func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, repositoryObj *

sent := cad.watcherManager.NotifyPackageRevisionChange(watch.Modified, repoPkgRev, pkgRevMeta)
klog.Infof("engine: sent %d for updated PackageRevision %s/%s", sent, repoPkgRev.KubeObjectNamespace(), repoPkgRev.KubeObjectName())

// Refresh Cache after package is approved so that 'main' package rev is available instantly after creation
if repoPkgRev.Lifecycle() == api.PackageRevisionLifecyclePublished {
err := repo.RefreshCache(ctx)
if err != nil {
return nil, err
}
}

return ToPackageRevision(repoPkgRev, pkgRevMeta), nil
}

Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cli/testdata/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
17 changes: 15 additions & 2 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,9 @@ func (t *PorchSuite) TestDeleteAndRecreate(ctx context.Context) {

t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: created.Name}, &pkg)

// Propose deletion and then delete the package
mainPkg := t.waitUntilPackageRevisionExists(ctx, repository, packageName, "main")

t.Log("Propose deletion and then delete the package with revision v1")
pkg.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed
t.UpdateApprovalF(ctx, &pkg, metav1.UpdateOptions{})

Expand All @@ -1076,9 +1078,20 @@ func (t *PorchSuite) TestDeleteAndRecreate(ctx context.Context) {
Name: created.Name,
},
})

t.mustNotExist(ctx, &pkg)

t.Log("Propose deletion and then delete the package with revision main")
mainPkg.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed
t.UpdateApprovalF(ctx, mainPkg, metav1.UpdateOptions{})

t.DeleteE(ctx, &porchapi.PackageRevision{
ObjectMeta: metav1.ObjectMeta{
Namespace: t.namespace,
Name: mainPkg.Name,
},
})
t.mustNotExist(ctx, mainPkg)

// Recreate the package with the same name and workspace
created = t.createPackageDraftF(ctx, repository, packageName, workspace)

Expand Down

0 comments on commit c4b36b7

Please sign in to comment.