From 97bf968fd6bc3e499f0e409abb57c05d716dd5cd Mon Sep 17 00:00:00 2001 From: Kushal Harish Naidu Date: Tue, 16 Jul 2024 12:05:37 +0000 Subject: [PATCH 1/4] Refresh cache after package approval --- pkg/cache/repository.go | 7 +++++++ pkg/engine/engine.go | 9 +++++++++ test/e2e/e2e_test.go | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/cache/repository.go b/pkg/cache/repository.go index 76e21ef8..6ed5e151 100644 --- a/pkg/cache/repository.go +++ b/pkg/cache/repository.go @@ -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) } diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 5b0dd6a4..4db1705a 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -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 } diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index e1621045..25c6156b 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -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{}) @@ -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) From e53ed00f0c73f2f9eac4d3642e52a96d9b43e7d2 Mon Sep 17 00:00:00 2001 From: Kushal Harish Naidu Date: Wed, 17 Jul 2024 16:29:57 +0000 Subject: [PATCH 2/4] Fix E2E cli rpkg-update test --- test/e2e/cli/testdata/rpkg-update/config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/e2e/cli/testdata/rpkg-update/config.yaml b/test/e2e/cli/testdata/rpkg-update/config.yaml index 67158872..1f00c645 100644 --- a/test/e2e/cli/testdata/rpkg-update/config.yaml +++ b/test/e2e/cli/testdata/rpkg-update/config.yaml @@ -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: @@ -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: @@ -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: From 5c3391d97854ecac8dff9f35ca547652d3ca5bf1 Mon Sep 17 00:00:00 2001 From: Kushal Harish Naidu Date: Mon, 22 Jul 2024 12:56:50 +0000 Subject: [PATCH 3/4] Update copyright date --- pkg/cache/repository.go | 2 +- pkg/engine/engine.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cache/repository.go b/pkg/cache/repository.go index 6ed5e151..e07c95eb 100644 --- a/pkg/cache/repository.go +++ b/pkg/cache/repository.go @@ -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. diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 4db1705a..91155f3b 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -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. From 685fc3c2543ab6d587e8c9f40ea311ad044001b5 Mon Sep 17 00:00:00 2001 From: Kushal Harish Naidu Date: Mon, 22 Jul 2024 13:09:50 +0000 Subject: [PATCH 4/4] Update copyright year --- pkg/cache/repository.go | 2 +- pkg/engine/engine.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cache/repository.go b/pkg/cache/repository.go index e07c95eb..05c466f0 100644 --- a/pkg/cache/repository.go +++ b/pkg/cache/repository.go @@ -1,4 +1,4 @@ -// Copyright 2022-2024 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. diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 91155f3b..b1898949 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -1,4 +1,4 @@ -// Copyright 2022-2024 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.