From c3e8db0419719e8f2dd85948afcdc1fc4c24f00a Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 28 Apr 2026 15:07:43 +0100 Subject: [PATCH 01/20] Feat: add package resource file sizes to PackageRevision interface - on ClosePackageRevisionDraft: - add up individual sizes of PackageRevisionResources - store total as a separate metadata field in package_revisions table - on get/list PackageRevision, include total resources size in status field of returned API object https://github.com/nephio-project/porch/issues/811 Signed-off-by: James McDermott --- api/porch/v1alpha1/types.go | 3 ++ api/porch/v1alpha2/packagerevision_types.go | 3 ++ .../porch.kpt.dev_packagerevisions.yaml | 7 ++-- api/sql/porch-db.sql | 3 +- ...iant_controller-with-workspacename_test.go | 11 +++++- .../packagevariant_controller_test.go | 11 +++++- .../porch/3-porch-postgres-bundle.yaml | 1 + pkg/cache/dbcache/dbpackagerevision.go | 13 ++++--- pkg/cache/dbcache/dbpackagerevisionsql.go | 34 +++++++++++-------- pkg/cache/dbcache/dbrepository.go | 8 ++++- pkg/registry/porch/table.go | 5 ++- test/e2e/api/repository_test.go | 11 ++++-- test/e2e/api/rpkg_init_test.go | 11 ++++-- test/e2e/api/rpkg_lifecycle_test.go | 8 ++--- 14 files changed, 93 insertions(+), 36 deletions(-) diff --git a/api/porch/v1alpha1/types.go b/api/porch/v1alpha1/types.go index 0fa0ef8ea..be4a35b0f 100644 --- a/api/porch/v1alpha1/types.go +++ b/api/porch/v1alpha1/types.go @@ -162,6 +162,9 @@ type PackageRevisionStatus struct { Deployment bool `json:"deployment,omitempty"` Conditions []Condition `json:"conditions,omitempty"` + + // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. + PrrSizeOnDisk int `json:"prrSizeOnDisk"` } type TaskType string diff --git a/api/porch/v1alpha2/packagerevision_types.go b/api/porch/v1alpha2/packagerevision_types.go index 4a10267df..93f4af01f 100644 --- a/api/porch/v1alpha2/packagerevision_types.go +++ b/api/porch/v1alpha2/packagerevision_types.go @@ -200,6 +200,9 @@ type PackageRevisionStatus struct { // +listType=map // +listMapKey=type Conditions []metav1.Condition `json:"conditions,omitempty"` + + // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. + PrrSizeOnDisk int `json:"prrSizeOnDisk"` } // PackageSource specifies how a package was created. diff --git a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml index 23820a4be..e29fdf6f3 100644 --- a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml +++ b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml @@ -373,14 +373,17 @@ spec: - type type: object type: array + prrSizeOnDisk: + description: PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. + type: integer publishedAt: - description: PublishedAt is the time when the packagerevision were + description: PublishedAt is the time when the package revision was approved. format: date-time type: string publishedBy: description: PublishedBy is the identity of the user who approved - the packagerevision. + the package revision. type: string renderingPrrResourceVersion: description: |- diff --git a/api/sql/porch-db.sql b/api/sql/porch-db.sql index a5ec725e1..017bacd17 100644 --- a/api/sql/porch-db.sql +++ b/api/sql/porch-db.sql @@ -1,5 +1,5 @@ /* -Copyright 2024-2025 The kpt Authors +Copyright 2024-2026 The kpt Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS package_revisions ( latest BOOLEAN NOT NULL DEFAULT FALSE, tasks TEXT NOT NULL, kptfile_status TEXT NOT NULL DEFAULT '{}', + resources_size INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (k8s_name_space, k8s_name), CONSTRAINT fk_package FOREIGN KEY (k8s_name_space, package_k8s_name) diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go index 44dabacbd..961aa4dce 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 The kpt Authors +// Copyright 2022, 2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -405,6 +405,7 @@ spec: repository: deployments workspaceName: packagevariant-1 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -472,6 +473,7 @@ spec: repository: deployments workspaceName: packagevariant-2 status: + prrSizeOnDisk: 0 publishTimestamp: null `, `apiVersion: porch.kpt.dev kind: PackageRevision @@ -488,6 +490,7 @@ spec: repository: deployments workspaceName: packagevariant-3 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -563,6 +566,7 @@ spec: revision: 2 workspaceName: packagevariant-2 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -632,6 +636,7 @@ spec: revision: 1 workspaceName: packagevariant-1 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -744,6 +749,7 @@ spec: repository: deployments workspaceName: packagevariant-3 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -775,6 +781,7 @@ spec: repository: deployments workspaceName: packagevariant-3 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -879,6 +886,7 @@ spec: repository: deployments workspaceName: packagevariant-2 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -928,6 +936,7 @@ spec: repository: deployments workspaceName: packagevariant-1 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go index ca94432ae..81e273bd5 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go @@ -1,4 +1,4 @@ -// Copyright 2022, 2025 The kpt Authors +// Copyright 2022, 2025-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -408,6 +408,7 @@ spec: repository: deployments workspaceName: packagevariant-1 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -475,6 +476,7 @@ spec: repository: deployments workspaceName: packagevariant-2 status: + prrSizeOnDisk: 0 publishTimestamp: null `, `apiVersion: porch.kpt.dev kind: PackageRevision @@ -491,6 +493,7 @@ spec: repository: deployments workspaceName: packagevariant-3 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -566,6 +569,7 @@ spec: revision: 2 workspaceName: packagevariant-2 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -635,6 +639,7 @@ spec: revision: 1 workspaceName: packagevariant-1 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -747,6 +752,7 @@ spec: repository: deployments workspaceName: packagevariant-3 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -778,6 +784,7 @@ spec: repository: deployments workspaceName: packagevariant-3 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -882,6 +889,7 @@ spec: repository: deployments workspaceName: packagevariant-2 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -931,6 +939,7 @@ spec: repository: deployments workspaceName: packagevariant-1 status: + prrSizeOnDisk: 0 publishTimestamp: null `, }, diff --git a/deployments/porch/3-porch-postgres-bundle.yaml b/deployments/porch/3-porch-postgres-bundle.yaml index fd6d46f5a..6ece91251 100644 --- a/deployments/porch/3-porch-postgres-bundle.yaml +++ b/deployments/porch/3-porch-postgres-bundle.yaml @@ -354,6 +354,7 @@ data: latest BOOLEAN NOT NULL DEFAULT FALSE, tasks TEXT NOT NULL, kptfile_status TEXT NOT NULL DEFAULT '{}', + resources_size INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (k8s_name_space, k8s_name), CONSTRAINT fk_package FOREIGN KEY (k8s_name_space, package_k8s_name) diff --git a/pkg/cache/dbcache/dbpackagerevision.go b/pkg/cache/dbcache/dbpackagerevision.go index 779f03295..696b8ae47 100644 --- a/pkg/cache/dbcache/dbpackagerevision.go +++ b/pkg/cache/dbcache/dbpackagerevision.go @@ -1,4 +1,4 @@ -// Copyright 2024-2025 The kpt Authors +// Copyright 2024-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -89,6 +89,7 @@ type dbPackageRevision struct { resources map[string]string resourcesDirty bool kptfileStatus kptfileStatus + resourcesSize int // gitDraftPR maintains the draft in the external git repository during editing (when pushDraftsToGit is true) gitPRDraft repository.PackageRevisionDraft @@ -236,10 +237,11 @@ func (pr *dbPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi. _, selfLock, _ := pr.GetLock(ctx) status := porchapi.PackageRevisionStatus{ - UpstreamLock: repository.KptUpstreamLock2APIUpstreamLock(upstreamLock), - SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), - Deployment: pr.deployment, - Conditions: pr.kptfileStatus.Conditions, + UpstreamLock: repository.KptUpstreamLock2APIUpstreamLock(upstreamLock), + SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), + Deployment: pr.deployment, + Conditions: pr.kptfileStatus.Conditions, + PrrSizeOnDisk: pr.resourcesSize, } if porchapi.LifecycleIsPublished(pr.Lifecycle(ctx)) { @@ -358,6 +360,7 @@ func (pr *dbPackageRevision) ToMainPackageRevision(ctx context.Context) reposito tasks: pr.tasks, resources: pr.resources, kptfileStatus: pr.kptfileStatus, + resourcesSize: pr.resourcesSize, } mainPR.meta.CreationTimestamp = metav1.Time{Time: time.Now()} diff --git a/pkg/cache/dbcache/dbpackagerevisionsql.go b/pkg/cache/dbcache/dbpackagerevisionsql.go index 7622bd6f7..23c9c3d76 100644 --- a/pkg/cache/dbcache/dbpackagerevisionsql.go +++ b/pkg/cache/dbcache/dbpackagerevisionsql.go @@ -1,4 +1,4 @@ -// Copyright 2024-2025 The kpt Authors +// Copyright 2024-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -52,7 +52,8 @@ func pkgRevReadFromDB(ctx context.Context, prk repository.PackageRevisionKey, re package_revisions.ext_pr_id, package_revisions.latest, package_revisions.tasks, - package_revisions.kptfile_status + package_revisions.kptfile_status, + package_revisions.resources_size FROM package_revisions INNER JOIN packages ON package_revisions.k8s_name_space=packages.k8s_name_space AND package_revisions.package_k8s_name=packages.k8s_name INNER JOIN repositories @@ -124,7 +125,8 @@ func pkgRevListPRsFromDB(ctx context.Context, filter repository.ListPackageRevis package_revisions.ext_pr_id, package_revisions.latest, package_revisions.tasks, - package_revisions.kptfile_status + package_revisions.kptfile_status, + package_revisions.resources_size FROM package_revisions INNER JOIN packages ON package_revisions.k8s_name_space=packages.k8s_name_space AND package_revisions.package_k8s_name=packages.k8s_name @@ -173,7 +175,8 @@ func pkgRevReadPRsFromDB(ctx context.Context, pk repository.PackageKey) ([]*dbPa package_revisions.ext_pr_id, package_revisions.latest, package_revisions.tasks, - package_revisions.kptfile_status + package_revisions.kptfile_status, + package_revisions.resources_size FROM package_revisions INNER JOIN packages ON package_revisions.k8s_name_space=packages.k8s_name_space AND package_revisions.package_k8s_name=packages.k8s_name INNER JOIN repositories @@ -223,7 +226,8 @@ func pkgRevReadLatestPRFromDB(ctx context.Context, pk repository.PackageKey) (*d package_revisions.ext_pr_id, package_revisions.latest, package_revisions.tasks, - package_revisions.kptfile_status + package_revisions.kptfile_status, + package_revisions.resources_size FROM package_revisions INNER JOIN packages ON package_revisions.k8s_name_space=packages.k8s_name_space AND package_revisions.package_k8s_name=packages.k8s_name INNER JOIN repositories @@ -310,7 +314,8 @@ func pkgRevScanRowsFromDB(ctx context.Context, rows *sql.Rows) ([]*dbPackageRevi &extPRID, &pkgRev.latest, &tasks, - &kptfileStatusJSON) + &kptfileStatusJSON, + &pkgRev.resourcesSize) if err != nil { klog.Warningf("pkgRevScanRowsFromDB: scanning rows failed: %q", err) @@ -346,8 +351,8 @@ func pkgRevWriteToDB(ctx context.Context, pr *dbPackageRevision) error { klog.V(5).Infof("pkgRevWriteToDB: writing package revision %+v", pr.Key()) sqlStatement := ` - INSERT INTO package_revisions (k8s_name_space, k8s_name, package_k8s_name, revision, meta, spec, updated, updatedby, lifecycle, ext_pr_id, tasks, kptfile_status) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) + INSERT INTO package_revisions (k8s_name_space, k8s_name, package_k8s_name, revision, meta, spec, updated, updatedby, lifecycle, ext_pr_id, tasks, kptfile_status, resources_size) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) ` klog.V(6).Infof("pkgRevWriteToDB: running query %q on package revision %+v", sqlStatement, pr) @@ -355,7 +360,7 @@ func pkgRevWriteToDB(ctx context.Context, pr *dbPackageRevision) error { if _, err := GetDB().db.Exec(ctx, sqlStatement, prk.K8SNS(), prk.K8SName(), - prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus)); err == nil { + prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus), pr.resourcesSize); err == nil { klog.V(5).Infof("pkgRevWriteToDB: query succeeded, row created") } else { klog.Warningf("pkgRevWriteToDB: query failed for %+v %q", pr.Key(), err) @@ -378,15 +383,15 @@ func pkgRevUpdateDB(ctx context.Context, pr *dbPackageRevision, updateResources klog.V(5).Infof("pkgRevUpdateDB: updating package revision %+v", pr.Key()) sqlStatement := ` - UPDATE package_revisions SET package_k8s_name=$3, revision=$4, meta=$5, spec=$6, updated=$7, updatedby=$8, lifecycle=$9, ext_pr_id=$10, tasks=$11, kptfile_status=$12 + UPDATE package_revisions SET package_k8s_name=$3, revision=$4, meta=$5, spec=$6, updated=$7, updatedby=$8, lifecycle=$9, ext_pr_id=$10, tasks=$11, kptfile_status=$12, resources_size=$13 WHERE k8s_name_space=$1 AND k8s_name=$2 ` if pr.pkgRevKey.Revision == -1 { sqlStatement = ` INSERT INTO package_revisions ( - k8s_name_space, k8s_name, package_k8s_name, revision, meta, spec, updated, updatedby, lifecycle, ext_pr_id, tasks, kptfile_status + k8s_name_space, k8s_name, package_k8s_name, revision, meta, spec, updated, updatedby, lifecycle, ext_pr_id, tasks, kptfile_status, resources_size ) VALUES ( - $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13 ) ON CONFLICT (k8s_name_space, k8s_name) DO UPDATE SET @@ -399,7 +404,8 @@ func pkgRevUpdateDB(ctx context.Context, pr *dbPackageRevision, updateResources lifecycle = EXCLUDED.lifecycle, ext_pr_id = EXCLUDED.ext_pr_id, tasks = EXCLUDED.tasks, - kptfile_status = EXCLUDED.kptfile_status; + kptfile_status = EXCLUDED.kptfile_status, + resources_size = EXCLUDED.resources_size; ` } @@ -408,7 +414,7 @@ func pkgRevUpdateDB(ctx context.Context, pr *dbPackageRevision, updateResources result, err := GetDB().db.Exec(ctx, sqlStatement, prk.K8SNS(), prk.K8SName(), - prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus)) + prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus), pr.resourcesSize) if err == nil { if rowsAffected, _ := result.RowsAffected(); rowsAffected == 1 { diff --git a/pkg/cache/dbcache/dbrepository.go b/pkg/cache/dbcache/dbrepository.go index 3f44cd11c..1ce8fcdcc 100644 --- a/pkg/cache/dbcache/dbrepository.go +++ b/pkg/cache/dbcache/dbrepository.go @@ -1,4 +1,4 @@ -// Copyright 2024-2025 The kpt Authors +// Copyright 2024-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -476,6 +476,12 @@ func (r *dbRepository) ClosePackageRevisionDraft(ctx context.Context, prd reposi r.setCachedGitPR(dbPrd.Key().PkgKey, dbPrd.Key().WorkspaceName, gitPR) } + if dbPrd.resourcesSize == 0 { + for _, fileString := range dbPrd.resources { + dbPrd.resourcesSize += len(fileString) + } + } + pr, err := r.savePackageRevisionDraft(ctx, prd, version) if err != nil { return nil, err diff --git a/pkg/registry/porch/table.go b/pkg/registry/porch/table.go index 6e0f42fbb..a9a393ef1 100644 --- a/pkg/registry/porch/table.go +++ b/pkg/registry/porch/table.go @@ -1,4 +1,4 @@ -// Copyright 2022, 2025 The kpt Authors +// Copyright 2022, 2025-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package porch import ( "context" + "strconv" porchapi "github.com/kptdev/porch/api/porch/v1alpha1" "k8s.io/apimachinery/pkg/api/meta" @@ -118,6 +119,7 @@ var ( isLatest(pr), pr.Spec.Lifecycle, pr.Spec.RepositoryName, + strconv.Itoa(pr.Status.PrrSizeOnDisk) + " B", } }, columns: []metav1.TableColumnDefinition{ @@ -128,6 +130,7 @@ var ( {Name: "Latest", Type: "boolean"}, {Name: "Lifecycle", Type: "string"}, {Name: "Repository", Type: "string"}, + {Name: "Size on Disk", Type: "string"}, }, } diff --git a/test/e2e/api/repository_test.go b/test/e2e/api/repository_test.go index 1c61cd600..03df4d00d 100644 --- a/test/e2e/api/repository_test.go +++ b/test/e2e/api/repository_test.go @@ -20,9 +20,10 @@ import ( "sync" "time" - porchapi "github.com/kptdev/porch/api/porch/v1alpha1" - configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1" - suiteutils "github.com/kptdev/porch/test/e2e/suiteutils" + porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" + configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" + suiteutils "github.com/nephio-project/porch/test/e2e/suiteutils" + "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -112,6 +113,10 @@ func (t *PorchSuite) TestGitRepositoryWithReleaseTagsAndDirectory() { t.Errorf("package name %q should not include repo directory %q as prefix", pr.Spec.PackageName, directory) } } + + for _, pr := range list.Items { + require.Equal(t.T(), 895, pr.Status.PrrSizeOnDisk, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeOnDisk) + } } func (t *PorchSuite) TestRegisterRepository() { diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index 78e1860a1..ef52b9306 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -1,4 +1,4 @@ -// Copyright 2025 The kpt Authors +// Copyright 2025-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,11 +17,14 @@ package api import ( "github.com/google/go-cmp/cmp" kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - porchapi "github.com/kptdev/porch/api/porch/v1alpha1" - suiteutils "github.com/kptdev/porch/test/e2e/suiteutils" + porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" + suiteutils "github.com/nephio-project/porch/test/e2e/suiteutils" + "github.com/stretchr/testify/assert" "sigs.k8s.io/controller-runtime/pkg/client" ) +var defaultEmptyResourcesSize = 893 + func (t *PorchSuite) TestInitEmptyPackage() { // Create a new package via init, no task specified const ( @@ -40,6 +43,8 @@ func (t *PorchSuite) TestInitEmptyPackage() { t.validateKptFileMetadata(pr, packageName, &kptfilev1.PackageInfo{ Description: description, }) + + assert.Equal(t, defaultEmptyResourcesSize, pr.Status.PrrSizeOnDisk) } func (t *PorchSuite) TestInitTaskPackage() { diff --git a/test/e2e/api/rpkg_lifecycle_test.go b/test/e2e/api/rpkg_lifecycle_test.go index c08bc0e02..b5349ed87 100644 --- a/test/e2e/api/rpkg_lifecycle_test.go +++ b/test/e2e/api/rpkg_lifecycle_test.go @@ -1,4 +1,4 @@ -// Copyright 2025 The kpt Authors +// Copyright 2025-2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import ( configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1" suiteutils "github.com/kptdev/porch/test/e2e/suiteutils" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -45,9 +46,8 @@ func (t *PorchSuite) TestBasicLifecycle() { Workspace: defaultWorkspace, TargetState: porchapi.PackageRevisionLifecyclePublished, Validate: func(t *PorchSuite, pr *porchapi.PackageRevision) { - if pr.Spec.Revision != 1 { - t.Fatalf("Expected revision 1, got %d", pr.Spec.Revision) - } + require.Equal(t.T(), 1, pr.Spec.Revision, "Expected revision 1, got %d", pr.Spec.Revision) + require.Equal(t.T(), 885, pr.Status.PrrSizeOnDisk, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeOnDisk) }, }, { From 386f1e54c2ca026c32df566eb546452b1d40debc Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 28 Apr 2026 17:05:06 +0100 Subject: [PATCH 02/20] Update documentation to include new size-on-disk field - document new API field `prrSizeOnDisk` - include new "SIZE ON DISK" table column in `rpkg get` output examples Signed-off-by: James McDermott --- .../en/docs/2_concepts/package-revisions.md | 36 +++++++++---------- .../inspecting-packages.md | 33 ++++++++--------- .../package-cache/db-cache.md | 6 ++-- docs/content/en/docs/7_cli_api/api-ref.md | 1 + 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/docs/content/en/docs/2_concepts/package-revisions.md b/docs/content/en/docs/2_concepts/package-revisions.md index ba04af5c3..0e668b285 100644 --- a/docs/content/en/docs/2_concepts/package-revisions.md +++ b/docs/content/en/docs/2_concepts/package-revisions.md @@ -122,8 +122,8 @@ spec: apiVersion: config.porch.kpt.dev/v1alpha1 kind: Repository metadata: -name: catalog-v4-0-0 -namespace: default + name: catalog-v4-0-0 + namespace: default spec: content: Package deployment: false @@ -138,14 +138,14 @@ spec: apiVersion: config.porch.kpt.dev/v1alpha1 kind: Repository metadata: -name: catalog-v3-0-0 -namespace: default + name: catalog-v3-0-0 + namespace: default spec: content: Package deployment: false type: git git: - branch: v3.0.0 + branch: v3 directory: / repo: https://github.com/nephio-project/catalog.git ``` @@ -155,19 +155,19 @@ Porch discovers the following package revisions for the "oai-ran-operator" packa ```bash $ porchctl -n default rpkg get -NAMESPACE NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY -default catalog-main.workloads.oai.oai-ran-operator.main workloads/oai/oai-ran-operator main -1 false Published catalog-main -default catalog-main.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-main -default catalog-main.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-main -default catalog-main.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 true Published catalog-main -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v3-0-0 -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v3-0-0 -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v3-0-0 -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3 workloads/oai/oai-ran-operator v3 3 true Published catalog-v3-0-0 -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v4-0-0 -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v4-0-0 -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v4-0-0 -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v4 workloads/oai/oai-ran-operator v4 4 true Published catalog-v4-0-0 +NAMESPACE NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK +default catalog-main.workloads.oai.oai-ran-operator.main workloads/oai/oai-ran-operator main -1 false Published catalog-main 2999 B +default catalog-main.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-main 3003 B +default catalog-main.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-main 3003 B +default catalog-main.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 true Published catalog-main 3006 B +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v3-0-0 3003 B +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v3-0-0 3003 B +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v3-0-0 3006 B +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3 workloads/oai/oai-ran-operator v3 3 true Published catalog-v3-0-0 3003 B +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v4-0-0 3003 B +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v4-0-0 3003 B +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v4-0-0 3006 B +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v4 workloads/oai/oai-ran-operator v4 4 true Published catalog-v4-0-0 3003 B ``` {{% /details %}} diff --git a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md index 09df483c1..4b43e9cbb 100644 --- a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md +++ b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md @@ -35,11 +35,11 @@ porchctl rpkg list --namespace default Example output: ```bash -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY -porch-test.my-app.v1 my-app v1 1 true Published porch-test -porch-test.my-app.v2 my-app v2 0 false Draft porch-test -blueprints.nginx.main nginx main 5 true Published blueprints -blueprints.postgres.v1 postgres v1 0 false Proposed blueprints +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK +porch-test.my-app.v1 my-app v1 1 true Published porch-test 12432 B +porch-test.my-app.v2 my-app v2 0 false Draft porch-test 12432 B +blueprints.nginx.main nginx main 5 true Published blueprints 129955 B +blueprints.postgres.v1 postgres v1 0 false Proposed blueprints 153908 B ``` Understanding the output: @@ -53,6 +53,7 @@ Understanding the output: | **LATEST** | Indicates the latest published PackageRevision for the package (only one; highest revision number). | `true` / `false` | | **LIFECYCLE** | Current state of the PackageRevision.
**Draft** — in progress, editable, visible to authors
**Proposed** — read-only, pending approval (approve or reject)
**Published** — immutable, production-ready, has revision numbers
**DeletionProposed** — marked for removal, pending deletion approval. | `Draft`, `Proposed`, `Published`, `DeletionProposed` | | **REPOSITORY** | Name of the source repository. | `porch-test` | +| **SIZE ON DISK** | Total disk space, in bytes, occupied by the PackageRevision's resource files | `1492B` | --- ### Get Detailed PackageRevision Information @@ -232,10 +233,10 @@ Example output: ```bash $ porchctl rpkg get --namespace default --name network-function -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY -porch-test.network-function.v1 network-function v1 1 false Published porch-test -porch-test.network-function.v2 network-function v2 2 true Published porch-test -porch-test.network-function.main network-function main 0 false Draft porch-test +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK +porch-test.network-function.v1 network-function v1 1 false Published porch-test 162831 B +porch-test.network-function.v2 network-function v2 2 true Published porch-test 162831 B +porch-test.network-function.main network-function main 0 false Draft porch-test 162831 B ``` --- @@ -254,9 +255,9 @@ Example output: ```bash $ kubectl get packagerevisions -n default --show-labels --selector 'kpt.dev/latest-revision=true' -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY LABELS -porch-test.my-app.v2 my-app v2 2 true Published porch-test kpt.dev/latest-revision=true -blueprints.nginx.main nginx main 5 true Published blueprints kpt.dev/latest-revision=true +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK LABELS +porch-test.my-app.v2 my-app v2 2 true Published porch-test 12432 B kpt.dev/latest-revision=true +blueprints.nginx.main nginx main 5 true Published blueprints 129955 B kpt.dev/latest-revision=true ``` {{% alert title="Note" color="primary" %}} @@ -308,10 +309,10 @@ Example output: ```bash $ kubectl get packagerevisions -n default --field-selector 'spec.repository==porch-test' -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY -porch-test.my-app.v1 my-app v1 1 false Published porch-test -porch-test.my-app.v2 my-app v2 2 true Published porch-test -porch-test.my-service.main my-service main 3 true Published porch-test +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK +porch-test.my-app.v1 my-app v1 1 false Published porch-test 12432 B +porch-test.my-app.v2 my-app v2 2 true Published porch-test 12432 B +porch-test.my-service.main my-service main 3 true Published porch-test 11885 B ``` {{% alert title="Note" color="primary" %}} diff --git a/docs/content/en/docs/5_architecture_and_components/package-cache/db-cache.md b/docs/content/en/docs/5_architecture_and_components/package-cache/db-cache.md index 43ee05422..a1978bdc2 100644 --- a/docs/content/en/docs/5_architecture_and_components/package-cache/db-cache.md +++ b/docs/content/en/docs/5_architecture_and_components/package-cache/db-cache.md @@ -44,7 +44,7 @@ PostgreSQL Database **Database Storage:** - Repository connections and metadata - Package metadata (names, paths) -- Package revision metadata (lifecycle, tasks, upstream locks) +- Package revision metadata (lifecycle, tasks, upstream locks, package resources size) - Package resources (full KRM resource content) - Timestamps and user tracking for all entities @@ -242,7 +242,9 @@ The DB Cache has a **database-first approach** to draft packages by default, but - Draft packages stored entirely in PostgreSQL - All draft modifications update database, not Git - UpdatePackageRevision operations modify database records -- ClosePackageRevisionDraft saves to database without Git interaction +- ClosePackageRevisionDraft: + - sums up package file size based on state of resources at this point + - saves to database without Git interaction **Default Git interaction pattern:** - **Draft creation**: No Git interaction (database only) diff --git a/docs/content/en/docs/7_cli_api/api-ref.md b/docs/content/en/docs/7_cli_api/api-ref.md index c28d17ed0..fa34fc7a6 100644 --- a/docs/content/en/docs/7_cli_api/api-ref.md +++ b/docs/content/en/docs/7_cli_api/api-ref.md @@ -367,6 +367,7 @@ _Appears in:_ | `publishTimestamp` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#time-v1-meta)_ | PublishedAt is the time when the packagerevision were approved. | | | | `deployment` _boolean_ | Deployment is true if this is a deployment package (in a deployment repository). | | | | `conditions` _[Condition](#condition) array_ | | | | +| `prrSizeOnDisk` _integer_ | PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. | | | #### PackageSpec From f9375a6b09b3a69c4f3ab3dea04c70a49b05a056 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 28 Apr 2026 17:27:37 +0100 Subject: [PATCH 03/20] missed some generated bits Signed-off-by: James McDermott --- api/generated/openapi/zz_generated.openapi.go | 9 +++++ api/porch/v1alpha1/zz_generated.conversion.go | 34 ++++++++++++++----- .../porch.kpt.dev_packagerevisions.yaml | 9 +++-- pkg/cache/dbcache/dbreposync.go | 4 +++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index 70f67388e..512505a0d 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -1087,7 +1087,16 @@ func schema_porch_api_porch_v1alpha1_PackageRevisionStatus(ref common.ReferenceC }, }, }, + "prrSizeOnDisk": { + SchemaProps: spec.SchemaProps{ + Description: "PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources.", + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, }, + Required: []string{"prrSizeOnDisk"}, }, }, Dependencies: []string{ diff --git a/api/porch/v1alpha1/zz_generated.conversion.go b/api/porch/v1alpha1/zz_generated.conversion.go index ae5168f1e..f0fb6aafa 100644 --- a/api/porch/v1alpha1/zz_generated.conversion.go +++ b/api/porch/v1alpha1/zz_generated.conversion.go @@ -235,7 +235,7 @@ func RegisterConversions(s *runtime.Scheme) error { return err } if err := s.AddGeneratedConversionFunc((*PackageRevisionStatus)(nil), (*porch.PackageRevisionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(a.(*PackageRevisionStatus), b.(*porch.PackageRevisionStatus), scope) + return autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(a.(*PackageRevisionStatus), b.(*porch.PackageRevisionStatus), scope) }); err != nil { return err } @@ -714,7 +714,7 @@ func autoConvert_v1alpha1_PackageRevision_To_porch_PackageRevision(in *PackageRe if err := Convert_v1alpha1_PackageRevisionSpec_To_porch_PackageRevisionSpec(&in.Spec, &out.Spec, s); err != nil { return err } - if err := Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(&in.Status, &out.Status, s); err != nil { + if err := autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(&in.Status, &out.Status, s); err != nil { return err } return nil @@ -743,7 +743,17 @@ func Convert_porch_PackageRevision_To_v1alpha1_PackageRevision(in *porch.Package func autoConvert_v1alpha1_PackageRevisionList_To_porch_PackageRevisionList(in *PackageRevisionList, out *porch.PackageRevisionList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]porch.PackageRevision)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]porch.PackageRevision, len(*in)) + for i := range *in { + if err := Convert_v1alpha1_PackageRevision_To_porch_PackageRevision(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -754,7 +764,17 @@ func Convert_v1alpha1_PackageRevisionList_To_porch_PackageRevisionList(in *Packa func autoConvert_porch_PackageRevisionList_To_v1alpha1_PackageRevisionList(in *porch.PackageRevisionList, out *PackageRevisionList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]PackageRevision)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PackageRevision, len(*in)) + for i := range *in { + if err := Convert_porch_PackageRevision_To_v1alpha1_PackageRevision(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -932,14 +952,10 @@ func autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]porch.Condition)(unsafe.Pointer(&in.Conditions)) + // WARNING: in.PrrSizeOnDisk requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus is an autogenerated conversion function. -func Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(in *PackageRevisionStatus, out *porch.PackageRevisionStatus, s conversion.Scope) error { - return autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(in, out, s) -} - func autoConvert_porch_PackageRevisionStatus_To_v1alpha1_PackageRevisionStatus(in *porch.PackageRevisionStatus, out *PackageRevisionStatus, s conversion.Scope) error { out.UpstreamLock = (*Locator)(unsafe.Pointer(in.UpstreamLock)) out.SelfLock = (*Locator)(unsafe.Pointer(in.SelfLock)) diff --git a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml index e29fdf6f3..b923bf72e 100644 --- a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml +++ b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml @@ -374,16 +374,17 @@ spec: type: object type: array prrSizeOnDisk: - description: PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. + description: PrrSizeOnDisk is the total file size, in bytes, of the + package revision's resources. type: integer publishedAt: - description: PublishedAt is the time when the package revision was + description: PublishedAt is the time when the packagerevision were approved. format: date-time type: string publishedBy: description: PublishedBy is the identity of the user who approved - the package revision. + the packagerevision. type: string renderingPrrResourceVersion: description: |- @@ -458,6 +459,8 @@ spec: description: Type is the type of origin. type: string type: object + required: + - prrSizeOnDisk type: object type: object selectableFields: diff --git a/pkg/cache/dbcache/dbreposync.go b/pkg/cache/dbcache/dbreposync.go index e2e5a4a76..c67f0b6ed 100644 --- a/pkg/cache/dbcache/dbreposync.go +++ b/pkg/cache/dbcache/dbreposync.go @@ -198,8 +198,10 @@ func (s *repositorySync) cacheExternalPRs(ctx context.Context, externalPrMap map // Guard against nil return from GetResources (interface contract allows it). var resources map[string]string + var resourcesSize int if extPRResources == nil || extPRResources.Spec.Resources == nil { resources = make(map[string]string) + resourcesSize = 0 } else { // Filter out files with invalid UTF-8 or NUL bytes to avoid PostgreSQL TEXT errors. // Both resource_key and resource_value are TEXT columns, so both must be validated. @@ -211,6 +213,7 @@ func (s *repositorySync) cacheExternalPRs(ctx context.Context, externalPrMap map continue } resources[key] = val + resourcesSize += len(val) } } @@ -232,6 +235,7 @@ func (s *repositorySync) cacheExternalPRs(ctx context.Context, externalPrMap map resources: resources, deployment: s.repo.deployment, kptfileStatus: extractKptfileStatus(resources), + resourcesSize: resourcesSize, } _, err = s.repo.savePackageRevision(ctx, &dbPR, true) if err != nil { From 4143aa9923eb99d5ae42f6ffdde0a3895fe9f9b8 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Wed, 29 Apr 2026 15:35:46 +0100 Subject: [PATCH 04/20] Fix tests, revert "Size on Disk" column from PackageRevision table - fix E2E tests by excluding package-size testing from E2E tests for CR cache - new mechanism in test suite to detect DB cache when in use - can be used in test cases to exclude/include portions depending on cache - remove "Size on Disk" column from `kubectl get packagerevisions` table - agreed not essential information, may set precedent to overload table output - also removes need for updates to E2E CLI tests Signed-off-by: James McDermott --- api/generated/openapi/zz_generated.openapi.go | 6 +- api/porch/types.go | 3 + api/porch/v1alpha1/types.go | 2 +- api/porch/v1alpha1/zz_generated.conversion.go | 36 ++++------- api/porch/v1alpha2/packagerevision_types.go | 2 +- .../porch.kpt.dev_packagerevisions.yaml | 4 +- .../en/docs/2_concepts/package-revisions.md | 26 ++++---- .../inspecting-packages.md | 32 +++++----- docs/content/en/docs/7_cli_api/api-ref.md | 2 +- pkg/cache/dbcache/dbpackagerevision.go | 57 +++++++++--------- pkg/cache/dbcache/dbpackagerevisionsql.go | 6 +- pkg/cache/dbcache/dbrepository.go | 4 +- pkg/cache/dbcache/dbreposync.go | 24 ++++---- pkg/registry/porch/table.go | 3 - test/e2e/api/repository_test.go | 6 +- test/e2e/api/rpkg_init_test.go | 4 +- test/e2e/api/rpkg_lifecycle_test.go | 4 +- test/e2e/suiteutils/suite.go | 60 +++++++++++++++++-- 18 files changed, 159 insertions(+), 122 deletions(-) diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index 512505a0d..9c278f92f 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -1090,13 +1090,11 @@ func schema_porch_api_porch_v1alpha1_PackageRevisionStatus(ref common.ReferenceC "prrSizeOnDisk": { SchemaProps: spec.SchemaProps{ Description: "PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources.", - Default: 0, - Type: []string{"integer"}, - Format: "int32", + Type: []string{"string"}, + Format: "", }, }, }, - Required: []string{"prrSizeOnDisk"}, }, }, Dependencies: []string{ diff --git a/api/porch/types.go b/api/porch/types.go index 9c2739d2c..8c39a150b 100644 --- a/api/porch/types.go +++ b/api/porch/types.go @@ -162,6 +162,9 @@ type PackageRevisionStatus struct { Deployment bool `json:"deployment,omitempty"` Conditions []Condition `json:"conditions,omitempty"` + + // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. + PrrSizeOnDisk string `json:"prrSizeOnDisk,omitempty"` } type TaskType string diff --git a/api/porch/v1alpha1/types.go b/api/porch/v1alpha1/types.go index be4a35b0f..5ffed311b 100644 --- a/api/porch/v1alpha1/types.go +++ b/api/porch/v1alpha1/types.go @@ -164,7 +164,7 @@ type PackageRevisionStatus struct { Conditions []Condition `json:"conditions,omitempty"` // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. - PrrSizeOnDisk int `json:"prrSizeOnDisk"` + PrrSizeOnDisk string `json:"prrSizeOnDisk,omitempty"` } type TaskType string diff --git a/api/porch/v1alpha1/zz_generated.conversion.go b/api/porch/v1alpha1/zz_generated.conversion.go index f0fb6aafa..820d45422 100644 --- a/api/porch/v1alpha1/zz_generated.conversion.go +++ b/api/porch/v1alpha1/zz_generated.conversion.go @@ -235,7 +235,7 @@ func RegisterConversions(s *runtime.Scheme) error { return err } if err := s.AddGeneratedConversionFunc((*PackageRevisionStatus)(nil), (*porch.PackageRevisionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(a.(*PackageRevisionStatus), b.(*porch.PackageRevisionStatus), scope) + return Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(a.(*PackageRevisionStatus), b.(*porch.PackageRevisionStatus), scope) }); err != nil { return err } @@ -714,7 +714,7 @@ func autoConvert_v1alpha1_PackageRevision_To_porch_PackageRevision(in *PackageRe if err := Convert_v1alpha1_PackageRevisionSpec_To_porch_PackageRevisionSpec(&in.Spec, &out.Spec, s); err != nil { return err } - if err := autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(&in.Status, &out.Status, s); err != nil { + if err := Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(&in.Status, &out.Status, s); err != nil { return err } return nil @@ -743,17 +743,7 @@ func Convert_porch_PackageRevision_To_v1alpha1_PackageRevision(in *porch.Package func autoConvert_v1alpha1_PackageRevisionList_To_porch_PackageRevisionList(in *PackageRevisionList, out *porch.PackageRevisionList, s conversion.Scope) error { out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]porch.PackageRevision, len(*in)) - for i := range *in { - if err := Convert_v1alpha1_PackageRevision_To_porch_PackageRevision(&(*in)[i], &(*out)[i], s); err != nil { - return err - } - } - } else { - out.Items = nil - } + out.Items = *(*[]porch.PackageRevision)(unsafe.Pointer(&in.Items)) return nil } @@ -764,17 +754,7 @@ func Convert_v1alpha1_PackageRevisionList_To_porch_PackageRevisionList(in *Packa func autoConvert_porch_PackageRevisionList_To_v1alpha1_PackageRevisionList(in *porch.PackageRevisionList, out *PackageRevisionList, s conversion.Scope) error { out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]PackageRevision, len(*in)) - for i := range *in { - if err := Convert_porch_PackageRevision_To_v1alpha1_PackageRevision(&(*in)[i], &(*out)[i], s); err != nil { - return err - } - } - } else { - out.Items = nil - } + out.Items = *(*[]PackageRevision)(unsafe.Pointer(&in.Items)) return nil } @@ -952,10 +932,15 @@ func autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]porch.Condition)(unsafe.Pointer(&in.Conditions)) - // WARNING: in.PrrSizeOnDisk requires manual conversion: does not exist in peer-type + out.PrrSizeOnDisk = in.PrrSizeOnDisk return nil } +// Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus is an autogenerated conversion function. +func Convert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(in *PackageRevisionStatus, out *porch.PackageRevisionStatus, s conversion.Scope) error { + return autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(in, out, s) +} + func autoConvert_porch_PackageRevisionStatus_To_v1alpha1_PackageRevisionStatus(in *porch.PackageRevisionStatus, out *PackageRevisionStatus, s conversion.Scope) error { out.UpstreamLock = (*Locator)(unsafe.Pointer(in.UpstreamLock)) out.SelfLock = (*Locator)(unsafe.Pointer(in.SelfLock)) @@ -963,6 +948,7 @@ func autoConvert_porch_PackageRevisionStatus_To_v1alpha1_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]Condition)(unsafe.Pointer(&in.Conditions)) + out.PrrSizeOnDisk = in.PrrSizeOnDisk return nil } diff --git a/api/porch/v1alpha2/packagerevision_types.go b/api/porch/v1alpha2/packagerevision_types.go index 93f4af01f..51fe78478 100644 --- a/api/porch/v1alpha2/packagerevision_types.go +++ b/api/porch/v1alpha2/packagerevision_types.go @@ -202,7 +202,7 @@ type PackageRevisionStatus struct { Conditions []metav1.Condition `json:"conditions,omitempty"` // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. - PrrSizeOnDisk int `json:"prrSizeOnDisk"` + PrrSizeOnDisk string `json:"prrSizeOnDisk,omitempty"` } // PackageSource specifies how a package was created. diff --git a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml index b923bf72e..1e53726e8 100644 --- a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml +++ b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml @@ -376,7 +376,7 @@ spec: prrSizeOnDisk: description: PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. - type: integer + type: string publishedAt: description: PublishedAt is the time when the packagerevision were approved. @@ -459,8 +459,6 @@ spec: description: Type is the type of origin. type: string type: object - required: - - prrSizeOnDisk type: object type: object selectableFields: diff --git a/docs/content/en/docs/2_concepts/package-revisions.md b/docs/content/en/docs/2_concepts/package-revisions.md index 0e668b285..938e50ae2 100644 --- a/docs/content/en/docs/2_concepts/package-revisions.md +++ b/docs/content/en/docs/2_concepts/package-revisions.md @@ -155,19 +155,19 @@ Porch discovers the following package revisions for the "oai-ran-operator" packa ```bash $ porchctl -n default rpkg get -NAMESPACE NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK -default catalog-main.workloads.oai.oai-ran-operator.main workloads/oai/oai-ran-operator main -1 false Published catalog-main 2999 B -default catalog-main.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-main 3003 B -default catalog-main.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-main 3003 B -default catalog-main.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 true Published catalog-main 3006 B -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v3-0-0 3003 B -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v3-0-0 3003 B -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v3-0-0 3006 B -default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3 workloads/oai/oai-ran-operator v3 3 true Published catalog-v3-0-0 3003 B -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v4-0-0 3003 B -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v4-0-0 3003 B -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v4-0-0 3006 B -default catalog-v4-0-0.workloads.oai.oai-ran-operator.v4 workloads/oai/oai-ran-operator v4 4 true Published catalog-v4-0-0 3003 B +NAMESPACE NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY +default catalog-main.workloads.oai.oai-ran-operator.main workloads/oai/oai-ran-operator main -1 false Published catalog-main +default catalog-main.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-main +default catalog-main.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-main +default catalog-main.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 true Published catalog-main +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v3-0-0 +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v3-0-0 +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v3-0-0 +default catalog-v3-0-0.workloads.oai.oai-ran-operator.v3 workloads/oai/oai-ran-operator v3 3 true Published catalog-v3-0-0 +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v2.0.0 workloads/oai/oai-ran-operator v2.0.0 -1 false Published catalog-v4-0-0 +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v3.0.0 workloads/oai/oai-ran-operator v3.0.0 -1 false Published catalog-v4-0-0 +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v1 workloads/oai/oai-ran-operator v1 1 false Published catalog-v4-0-0 +default catalog-v4-0-0.workloads.oai.oai-ran-operator.v4 workloads/oai/oai-ran-operator v4 4 true Published catalog-v4-0-0 ``` {{% /details %}} diff --git a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md index 4b43e9cbb..505ea4e15 100644 --- a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md +++ b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md @@ -35,11 +35,11 @@ porchctl rpkg list --namespace default Example output: ```bash -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK -porch-test.my-app.v1 my-app v1 1 true Published porch-test 12432 B -porch-test.my-app.v2 my-app v2 0 false Draft porch-test 12432 B -blueprints.nginx.main nginx main 5 true Published blueprints 129955 B -blueprints.postgres.v1 postgres v1 0 false Proposed blueprints 153908 B +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY +porch-test.my-app.v1 my-app v1 1 true Published porch-test +porch-test.my-app.v2 my-app v2 0 false Draft porch-test +blueprints.nginx.main nginx main 5 true Published blueprints +blueprints.postgres.v1 postgres v1 0 false Proposed blueprints ``` Understanding the output: @@ -233,10 +233,10 @@ Example output: ```bash $ porchctl rpkg get --namespace default --name network-function -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK -porch-test.network-function.v1 network-function v1 1 false Published porch-test 162831 B -porch-test.network-function.v2 network-function v2 2 true Published porch-test 162831 B -porch-test.network-function.main network-function main 0 false Draft porch-test 162831 B +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY +porch-test.network-function.v1 network-function v1 1 false Published porch-test +porch-test.network-function.v2 network-function v2 2 true Published porch-test +porch-test.network-function.main network-function main 0 false Draft porch-test ``` --- @@ -255,9 +255,9 @@ Example output: ```bash $ kubectl get packagerevisions -n default --show-labels --selector 'kpt.dev/latest-revision=true' -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK LABELS -porch-test.my-app.v2 my-app v2 2 true Published porch-test 12432 B kpt.dev/latest-revision=true -blueprints.nginx.main nginx main 5 true Published blueprints 129955 B kpt.dev/latest-revision=true +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY LABELS +porch-test.my-app.v2 my-app v2 2 true Published porch-test kpt.dev/latest-revision=true +blueprints.nginx.main nginx main 5 true Published blueprints kpt.dev/latest-revision=true ``` {{% alert title="Note" color="primary" %}} @@ -309,10 +309,10 @@ Example output: ```bash $ kubectl get packagerevisions -n default --field-selector 'spec.repository==porch-test' -NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY SIZE ON DISK -porch-test.my-app.v1 my-app v1 1 false Published porch-test 12432 B -porch-test.my-app.v2 my-app v2 2 true Published porch-test 12432 B -porch-test.my-service.main my-service main 3 true Published porch-test 11885 B +NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY +porch-test.my-app.v1 my-app v1 1 false Published porch-test +porch-test.my-app.v2 my-app v2 2 true Published porch-test +porch-test.my-service.main my-service main 3 true Published porch-test ``` {{% alert title="Note" color="primary" %}} diff --git a/docs/content/en/docs/7_cli_api/api-ref.md b/docs/content/en/docs/7_cli_api/api-ref.md index fa34fc7a6..dfcd8415d 100644 --- a/docs/content/en/docs/7_cli_api/api-ref.md +++ b/docs/content/en/docs/7_cli_api/api-ref.md @@ -367,7 +367,7 @@ _Appears in:_ | `publishTimestamp` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#time-v1-meta)_ | PublishedAt is the time when the packagerevision were approved. | | | | `deployment` _boolean_ | Deployment is true if this is a deployment package (in a deployment repository). | | | | `conditions` _[Condition](#condition) array_ | | | | -| `prrSizeOnDisk` _integer_ | PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. | | | +| `prrSizeOnDisk` _string_ | PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. | | | #### PackageSpec diff --git a/pkg/cache/dbcache/dbpackagerevision.go b/pkg/cache/dbcache/dbpackagerevision.go index 696b8ae47..f799dc9c9 100644 --- a/pkg/cache/dbcache/dbpackagerevision.go +++ b/pkg/cache/dbcache/dbpackagerevision.go @@ -19,6 +19,7 @@ import ( "database/sql" "fmt" "maps" + "strconv" "strings" "time" @@ -75,21 +76,21 @@ func extractFromKptfile(resources map[string]string) (kptfileStatus, []porchapi. } type dbPackageRevision struct { - repo *dbRepository - pkgRevKey repository.PackageRevisionKey - meta metav1.ObjectMeta - spec *porchapi.PackageRevisionSpec - updated time.Time - updatedBy string - lifecycle porchapi.PackageRevisionLifecycle - extPRID kptfile.Locator - latest bool - deployment bool - tasks []porchapi.Task - resources map[string]string - resourcesDirty bool - kptfileStatus kptfileStatus - resourcesSize int + repo *dbRepository + pkgRevKey repository.PackageRevisionKey + meta metav1.ObjectMeta + spec *porchapi.PackageRevisionSpec + updated time.Time + updatedBy string + lifecycle porchapi.PackageRevisionLifecycle + extPRID kptfile.Locator + latest bool + deployment bool + tasks []porchapi.Task + resources map[string]string + resourcesDirty bool + kptfileStatus kptfileStatus + resourcesSizeBytes int // gitDraftPR maintains the draft in the external git repository during editing (when pushDraftsToGit is true) gitPRDraft repository.PackageRevisionDraft @@ -241,7 +242,7 @@ func (pr *dbPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi. SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), Deployment: pr.deployment, Conditions: pr.kptfileStatus.Conditions, - PrrSizeOnDisk: pr.resourcesSize, + PrrSizeOnDisk: strconv.Itoa(pr.resourcesSizeBytes) + "B", } if porchapi.LifecycleIsPublished(pr.Lifecycle(ctx)) { @@ -349,18 +350,18 @@ func (pr *dbPackageRevision) ToMainPackageRevision(ctx context.Context) reposito Revision: -1, WorkspaceName: pr.Key().RKey().PlaceholderWSname, }, - meta: metav1.ObjectMeta{}, - spec: &porchapi.PackageRevisionSpec{}, - updated: time.Now(), - updatedBy: getCurrentUser(), - lifecycle: pr.lifecycle, - extPRID: pr.extPRID, - latest: false, - deployment: pr.deployment, - tasks: pr.tasks, - resources: pr.resources, - kptfileStatus: pr.kptfileStatus, - resourcesSize: pr.resourcesSize, + meta: metav1.ObjectMeta{}, + spec: &porchapi.PackageRevisionSpec{}, + updated: time.Now(), + updatedBy: getCurrentUser(), + lifecycle: pr.lifecycle, + extPRID: pr.extPRID, + latest: false, + deployment: pr.deployment, + tasks: pr.tasks, + resources: pr.resources, + kptfileStatus: pr.kptfileStatus, + resourcesSizeBytes: pr.resourcesSizeBytes, } mainPR.meta.CreationTimestamp = metav1.Time{Time: time.Now()} diff --git a/pkg/cache/dbcache/dbpackagerevisionsql.go b/pkg/cache/dbcache/dbpackagerevisionsql.go index 23c9c3d76..c0c914378 100644 --- a/pkg/cache/dbcache/dbpackagerevisionsql.go +++ b/pkg/cache/dbcache/dbpackagerevisionsql.go @@ -315,7 +315,7 @@ func pkgRevScanRowsFromDB(ctx context.Context, rows *sql.Rows) ([]*dbPackageRevi &pkgRev.latest, &tasks, &kptfileStatusJSON, - &pkgRev.resourcesSize) + &pkgRev.resourcesSizeBytes) if err != nil { klog.Warningf("pkgRevScanRowsFromDB: scanning rows failed: %q", err) @@ -360,7 +360,7 @@ func pkgRevWriteToDB(ctx context.Context, pr *dbPackageRevision) error { if _, err := GetDB().db.Exec(ctx, sqlStatement, prk.K8SNS(), prk.K8SName(), - prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus), pr.resourcesSize); err == nil { + prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus), pr.resourcesSizeBytes); err == nil { klog.V(5).Infof("pkgRevWriteToDB: query succeeded, row created") } else { klog.Warningf("pkgRevWriteToDB: query failed for %+v %q", pr.Key(), err) @@ -414,7 +414,7 @@ func pkgRevUpdateDB(ctx context.Context, pr *dbPackageRevision, updateResources result, err := GetDB().db.Exec(ctx, sqlStatement, prk.K8SNS(), prk.K8SName(), - prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus), pr.resourcesSize) + prk.PKey().K8SName(), prk.Revision, valueAsJSON(pr.meta), valueAsJSON(pr.spec), pr.updated, pr.updatedBy, pr.lifecycle, valueAsJSON(pr.extPRID), valueAsJSON(pr.tasks), valueAsJSON(pr.kptfileStatus), pr.resourcesSizeBytes) if err == nil { if rowsAffected, _ := result.RowsAffected(); rowsAffected == 1 { diff --git a/pkg/cache/dbcache/dbrepository.go b/pkg/cache/dbcache/dbrepository.go index 1ce8fcdcc..3340f0d58 100644 --- a/pkg/cache/dbcache/dbrepository.go +++ b/pkg/cache/dbcache/dbrepository.go @@ -476,9 +476,9 @@ func (r *dbRepository) ClosePackageRevisionDraft(ctx context.Context, prd reposi r.setCachedGitPR(dbPrd.Key().PkgKey, dbPrd.Key().WorkspaceName, gitPR) } - if dbPrd.resourcesSize == 0 { + if dbPrd.resourcesSizeBytes == 0 { for _, fileString := range dbPrd.resources { - dbPrd.resourcesSize += len(fileString) + dbPrd.resourcesSizeBytes += len(fileString) } } diff --git a/pkg/cache/dbcache/dbreposync.go b/pkg/cache/dbcache/dbreposync.go index c67f0b6ed..7c951b945 100644 --- a/pkg/cache/dbcache/dbreposync.go +++ b/pkg/cache/dbcache/dbreposync.go @@ -224,18 +224,18 @@ func (s *repositorySync) cacheExternalPRs(ctx context.Context, externalPrMap map _, extPRUpstreamLock, _ := extPR.GetLock(ctx) dbPR := dbPackageRevision{ - repo: s.repo, - pkgRevKey: extPRKey, - meta: extAPIPR.ObjectMeta, - spec: &extAPIPR.Spec, - updated: time.Now(), - lifecycle: extAPIPR.Spec.Lifecycle, - extPRID: extPRUpstreamLock, - tasks: extAPIPR.Spec.Tasks, - resources: resources, - deployment: s.repo.deployment, - kptfileStatus: extractKptfileStatus(resources), - resourcesSize: resourcesSize, + repo: s.repo, + pkgRevKey: extPRKey, + meta: extAPIPR.ObjectMeta, + spec: &extAPIPR.Spec, + updated: time.Now(), + lifecycle: extAPIPR.Spec.Lifecycle, + extPRID: extPRUpstreamLock, + tasks: extAPIPR.Spec.Tasks, + resources: resources, + deployment: s.repo.deployment, + kptfileStatus: extractKptfileStatus(resources), + resourcesSizeBytes: resourcesSize, } _, err = s.repo.savePackageRevision(ctx, &dbPR, true) if err != nil { diff --git a/pkg/registry/porch/table.go b/pkg/registry/porch/table.go index a9a393ef1..69809f0d5 100644 --- a/pkg/registry/porch/table.go +++ b/pkg/registry/porch/table.go @@ -16,7 +16,6 @@ package porch import ( "context" - "strconv" porchapi "github.com/kptdev/porch/api/porch/v1alpha1" "k8s.io/apimachinery/pkg/api/meta" @@ -119,7 +118,6 @@ var ( isLatest(pr), pr.Spec.Lifecycle, pr.Spec.RepositoryName, - strconv.Itoa(pr.Status.PrrSizeOnDisk) + " B", } }, columns: []metav1.TableColumnDefinition{ @@ -130,7 +128,6 @@ var ( {Name: "Latest", Type: "boolean"}, {Name: "Lifecycle", Type: "string"}, {Name: "Repository", Type: "string"}, - {Name: "Size on Disk", Type: "string"}, }, } diff --git a/test/e2e/api/repository_test.go b/test/e2e/api/repository_test.go index 03df4d00d..1572516f4 100644 --- a/test/e2e/api/repository_test.go +++ b/test/e2e/api/repository_test.go @@ -114,8 +114,10 @@ func (t *PorchSuite) TestGitRepositoryWithReleaseTagsAndDirectory() { } } - for _, pr := range list.Items { - require.Equal(t.T(), 895, pr.Status.PrrSizeOnDisk, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeOnDisk) + if t.UsingDBCache { + for _, pr := range list.Items { + require.Equal(t.T(), 895, pr.Status.PrrSizeOnDisk, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeOnDisk) + } } } diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index ef52b9306..ffb9f716a 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -44,7 +44,9 @@ func (t *PorchSuite) TestInitEmptyPackage() { Description: description, }) - assert.Equal(t, defaultEmptyResourcesSize, pr.Status.PrrSizeOnDisk) + if t.UsingDBCache { + assert.Equal(t, defaultEmptyResourcesSize, pr.Status.PrrSizeOnDisk) + } } func (t *PorchSuite) TestInitTaskPackage() { diff --git a/test/e2e/api/rpkg_lifecycle_test.go b/test/e2e/api/rpkg_lifecycle_test.go index b5349ed87..ca615c1d9 100644 --- a/test/e2e/api/rpkg_lifecycle_test.go +++ b/test/e2e/api/rpkg_lifecycle_test.go @@ -47,7 +47,9 @@ func (t *PorchSuite) TestBasicLifecycle() { TargetState: porchapi.PackageRevisionLifecyclePublished, Validate: func(t *PorchSuite, pr *porchapi.PackageRevision) { require.Equal(t.T(), 1, pr.Spec.Revision, "Expected revision 1, got %d", pr.Spec.Revision) - require.Equal(t.T(), 885, pr.Status.PrrSizeOnDisk, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeOnDisk) + if t.UsingDBCache { + require.Equal(t.T(), 885, pr.Status.PrrSizeOnDisk, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeOnDisk) + } }, }, { diff --git a/test/e2e/suiteutils/suite.go b/test/e2e/suiteutils/suite.go index 0a2cf917e..2b7afb0ad 100644 --- a/test/e2e/suiteutils/suite.go +++ b/test/e2e/suiteutils/suite.go @@ -20,6 +20,7 @@ import ( "encoding/json" "fmt" "os" + "slices" "strings" "testing" "time" @@ -27,12 +28,13 @@ import ( "github.com/google/go-cmp/cmp" kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" - porchapi "github.com/kptdev/porch/api/porch/v1alpha1" - configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1" - pvapi "github.com/kptdev/porch/controllers/packagevariants/api/v1alpha1" - pvsetapi "github.com/kptdev/porch/controllers/packagevariantsets/api/v1alpha2" - internalapi "github.com/kptdev/porch/internal/api/porchinternal/v1alpha1" - "github.com/kptdev/porch/pkg/repository" + porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" + configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" + pvapi "github.com/nephio-project/porch/controllers/packagevariants/api/v1alpha1" + pvsetapi "github.com/nephio-project/porch/controllers/packagevariantsets/api/v1alpha2" + internalapi "github.com/nephio-project/porch/internal/api/porchinternal/v1alpha1" + cachetypes "github.com/nephio-project/porch/pkg/cache/types" + "github.com/nephio-project/porch/pkg/repository" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -85,6 +87,8 @@ type TestSuite struct { TestRunnerIsLocal bool // Tests running against local dev porch porchServerInCluster *bool // Cached result of IsPorchServerInCluster check repoControllerInCluster *bool // Cached result of IsRepoControllerInCluster check + UsingDBCache bool // Tests running against Porch with database cache + } func (t *TestSuite) SetupSuite() { @@ -141,6 +145,9 @@ func (t *TestSuite) Initialize() { }) t.Namespace = namespace + + t.checkIfUsingDBCache() + c := t.Client t.Cleanup(func() { if err := c.Delete(t.GetContext(), &coreapi.Namespace{ @@ -155,6 +162,47 @@ func (t *TestSuite) Initialize() { }) } +func (t *TestSuite) checkIfUsingDBCache() { + t.UsingDBCache = func() bool { + + _, envVarOverride := os.LookupEnv("DB_CACHE") + postgresPresent := func() bool { + var dbSet appsv1.StatefulSet + if err := t.Client.Get(t.GetContext(), + client.ObjectKey{ + Namespace: "porch-system", + Name: "porch-postgresql", + }, &dbSet); err == nil { + return dbSet.Status.ReadyReplicas == *dbSet.Spec.Replicas + } + return false + }() + + serverCacheType := func() cachetypes.CacheType { + var serverDeployment appsv1.Deployment + if err := t.Client.Get(t.GetContext(), + client.ObjectKey{ + Namespace: "porch-system", + Name: "porch-server", + }, &serverDeployment); err == nil { + for _, container := range serverDeployment.Spec.Template.Spec.Containers { + if container.Name == "porch-server" { + if slices.ContainsFunc(container.Args, func(anArg string) bool { + return strings.Contains(anArg, "cache-type=db") + }) { + return cachetypes.DBCacheType + } + } + } + return cachetypes.CRCacheType + } + return cachetypes.CRCacheType + + }() + return envVarOverride || serverCacheType == cachetypes.DBCacheType || postgresPresent + }() +} + func (t *TestSuite) PorchServerServiceKey() client.ObjectKey { porchApiService := aggregatorv1.APIService{} apiServiceName := porchapi.SchemeGroupVersion.Version + "." + porchapi.SchemeGroupVersion.Group From a722cf07cef2e01f6c742215be848d4016eb5077 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Wed, 29 Apr 2026 15:49:57 +0100 Subject: [PATCH 05/20] unit test fixes after table column reversion Signed-off-by: James McDermott --- .../packagevariant_controller-with-workspacename_test.go | 9 --------- .../packagevariant/packagevariant_controller_test.go | 9 --------- 2 files changed, 18 deletions(-) diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go index 961aa4dce..237071791 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go @@ -405,7 +405,6 @@ spec: repository: deployments workspaceName: packagevariant-1 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -473,7 +472,6 @@ spec: repository: deployments workspaceName: packagevariant-2 status: - prrSizeOnDisk: 0 publishTimestamp: null `, `apiVersion: porch.kpt.dev kind: PackageRevision @@ -490,7 +488,6 @@ spec: repository: deployments workspaceName: packagevariant-3 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -566,7 +563,6 @@ spec: revision: 2 workspaceName: packagevariant-2 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -636,7 +632,6 @@ spec: revision: 1 workspaceName: packagevariant-1 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -749,7 +744,6 @@ spec: repository: deployments workspaceName: packagevariant-3 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -781,7 +775,6 @@ spec: repository: deployments workspaceName: packagevariant-3 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -886,7 +879,6 @@ spec: repository: deployments workspaceName: packagevariant-2 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -936,7 +928,6 @@ spec: repository: deployments workspaceName: packagevariant-1 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go index 81e273bd5..f2f1c1e44 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go @@ -408,7 +408,6 @@ spec: repository: deployments workspaceName: packagevariant-1 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -476,7 +475,6 @@ spec: repository: deployments workspaceName: packagevariant-2 status: - prrSizeOnDisk: 0 publishTimestamp: null `, `apiVersion: porch.kpt.dev kind: PackageRevision @@ -493,7 +491,6 @@ spec: repository: deployments workspaceName: packagevariant-3 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -569,7 +566,6 @@ spec: revision: 2 workspaceName: packagevariant-2 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -639,7 +635,6 @@ spec: revision: 1 workspaceName: packagevariant-1 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -752,7 +747,6 @@ spec: repository: deployments workspaceName: packagevariant-3 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -784,7 +778,6 @@ spec: repository: deployments workspaceName: packagevariant-3 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -889,7 +882,6 @@ spec: repository: deployments workspaceName: packagevariant-2 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, @@ -939,7 +931,6 @@ spec: repository: deployments workspaceName: packagevariant-1 status: - prrSizeOnDisk: 0 publishTimestamp: null `, }, From 07ccfff8609609c060efee73b9462d6c7082b43f Mon Sep 17 00:00:00 2001 From: James McDermott Date: Wed, 29 Apr 2026 16:13:03 +0100 Subject: [PATCH 06/20] update e2e tests' expectations Signed-off-by: James McDermott --- test/e2e/api/repository_test.go | 2 +- test/e2e/api/rpkg_init_test.go | 2 +- test/e2e/api/rpkg_lifecycle_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/api/repository_test.go b/test/e2e/api/repository_test.go index 1572516f4..4ad216520 100644 --- a/test/e2e/api/repository_test.go +++ b/test/e2e/api/repository_test.go @@ -116,7 +116,7 @@ func (t *PorchSuite) TestGitRepositoryWithReleaseTagsAndDirectory() { if t.UsingDBCache { for _, pr := range list.Items { - require.Equal(t.T(), 895, pr.Status.PrrSizeOnDisk, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeOnDisk) + require.Equal(t.T(), "895B", pr.Status.PrrSizeOnDisk, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeOnDisk) } } } diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index ffb9f716a..4c72f5004 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var defaultEmptyResourcesSize = 893 +var defaultEmptyResourcesSize = "893B" func (t *PorchSuite) TestInitEmptyPackage() { // Create a new package via init, no task specified diff --git a/test/e2e/api/rpkg_lifecycle_test.go b/test/e2e/api/rpkg_lifecycle_test.go index ca615c1d9..d0eadc908 100644 --- a/test/e2e/api/rpkg_lifecycle_test.go +++ b/test/e2e/api/rpkg_lifecycle_test.go @@ -48,7 +48,7 @@ func (t *PorchSuite) TestBasicLifecycle() { Validate: func(t *PorchSuite, pr *porchapi.PackageRevision) { require.Equal(t.T(), 1, pr.Spec.Revision, "Expected revision 1, got %d", pr.Spec.Revision) if t.UsingDBCache { - require.Equal(t.T(), 885, pr.Status.PrrSizeOnDisk, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeOnDisk) + require.Equal(t.T(), "885B", pr.Status.PrrSizeOnDisk, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeOnDisk) } }, }, From c98aa73d179170c8764e1afaf9bb68fd79f34a52 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Wed, 6 May 2026 15:49:36 +0100 Subject: [PATCH 07/20] Address review comments Signed-off-by: James McDermott --- api/generated/openapi/zz_generated.openapi.go | 12 +++--- api/porch/types.go | 4 +- api/porch/v1alpha1/types.go | 8 ++-- api/porch/v1alpha1/zz_generated.conversion.go | 4 +- api/porch/v1alpha2/packagerevision_types.go | 8 ++-- .../porch.kpt.dev_packagerevisions.yaml | 11 +++--- api/sql/porch-db-1.5.10-1.5.9.sql | 18 +++++++++ api/sql/porch-db-1.5.9-1.5.10.sql | 37 +++++++++++++++++++ api/sql/porch-db-1.5.9-1.6.0.sql | 37 +++++++++++++++++++ api/sql/porch-db-1.6.0-1.5.9.sql | 18 +++++++++ docs/content/en/docs/7_cli_api/api-ref.md | 2 +- pkg/cache/dbcache/dbpackagerevision.go | 13 +++---- pkg/cache/dbcache/dbrepository.go | 2 +- pkg/cache/dbcache/dbreposync.go | 4 +- test/e2e/api/repository_test.go | 2 +- test/e2e/api/rpkg_init_test.go | 4 +- test/e2e/api/rpkg_lifecycle_test.go | 2 +- 17 files changed, 148 insertions(+), 38 deletions(-) create mode 100644 api/sql/porch-db-1.5.10-1.5.9.sql create mode 100644 api/sql/porch-db-1.5.9-1.5.10.sql create mode 100644 api/sql/porch-db-1.5.9-1.6.0.sql create mode 100644 api/sql/porch-db-1.6.0-1.5.9.sql diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index 9c278f92f..de2bcb3b6 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -1056,14 +1056,14 @@ func schema_porch_api_porch_v1alpha1_PackageRevisionStatus(ref common.ReferenceC }, "publishedBy": { SchemaProps: spec.SchemaProps{ - Description: "PublishedBy is the identity of the user who approved the packagerevision.", + Description: "PublishedBy is the identity of the user who approved the package revision.", Type: []string{"string"}, Format: "", }, }, "publishTimestamp": { SchemaProps: spec.SchemaProps{ - Description: "PublishedAt is the time when the packagerevision were approved.", + Description: "PublishedAt is the time when the package revision was approved.", Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), }, }, @@ -1087,11 +1087,11 @@ func schema_porch_api_porch_v1alpha1_PackageRevisionStatus(ref common.ReferenceC }, }, }, - "prrSizeOnDisk": { + "prrSizeBytes": { SchemaProps: spec.SchemaProps{ - Description: "PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources.", - Type: []string{"string"}, - Format: "", + Description: "PrrSizeBytes is the total file size, in bytes, of the package revision's resources.", + Type: []string{"integer"}, + Format: "int64", }, }, }, diff --git a/api/porch/types.go b/api/porch/types.go index 8c39a150b..273bb1215 100644 --- a/api/porch/types.go +++ b/api/porch/types.go @@ -163,8 +163,8 @@ type PackageRevisionStatus struct { Conditions []Condition `json:"conditions,omitempty"` - // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. - PrrSizeOnDisk string `json:"prrSizeOnDisk,omitempty"` + // PrrSizeBytes is the total file size, in bytes, of the package revision's resources. + PrrSizeBytes int64 `json:"prrSizeBytes,omitempty"` } type TaskType string diff --git a/api/porch/v1alpha1/types.go b/api/porch/v1alpha1/types.go index 5ffed311b..56aae4614 100644 --- a/api/porch/v1alpha1/types.go +++ b/api/porch/v1alpha1/types.go @@ -152,10 +152,10 @@ type PackageRevisionStatus struct { // SelfLock identifies the location of the current package's data SelfLock *Locator `json:"selfLock,omitempty"` - // PublishedBy is the identity of the user who approved the packagerevision. + // PublishedBy is the identity of the user who approved the package revision. PublishedBy string `json:"publishedBy,omitempty"` - // PublishedAt is the time when the packagerevision were approved. + // PublishedAt is the time when the package revision was approved. PublishedAt metav1.Time `json:"publishTimestamp,omitempty"` // Deployment is true if this is a deployment package (in a deployment repository). @@ -163,8 +163,8 @@ type PackageRevisionStatus struct { Conditions []Condition `json:"conditions,omitempty"` - // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. - PrrSizeOnDisk string `json:"prrSizeOnDisk,omitempty"` + // PrrSizeBytes is the total file size, in bytes, of the package revision's resources. + PrrSizeBytes int64 `json:"prrSizeBytes,omitempty"` } type TaskType string diff --git a/api/porch/v1alpha1/zz_generated.conversion.go b/api/porch/v1alpha1/zz_generated.conversion.go index 820d45422..489a789b0 100644 --- a/api/porch/v1alpha1/zz_generated.conversion.go +++ b/api/porch/v1alpha1/zz_generated.conversion.go @@ -932,7 +932,7 @@ func autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]porch.Condition)(unsafe.Pointer(&in.Conditions)) - out.PrrSizeOnDisk = in.PrrSizeOnDisk + out.PrrSizeBytes = in.PrrSizeBytes return nil } @@ -948,7 +948,7 @@ func autoConvert_porch_PackageRevisionStatus_To_v1alpha1_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]Condition)(unsafe.Pointer(&in.Conditions)) - out.PrrSizeOnDisk = in.PrrSizeOnDisk + out.PrrSizeBytes = in.PrrSizeBytes return nil } diff --git a/api/porch/v1alpha2/packagerevision_types.go b/api/porch/v1alpha2/packagerevision_types.go index 51fe78478..60a145ae9 100644 --- a/api/porch/v1alpha2/packagerevision_types.go +++ b/api/porch/v1alpha2/packagerevision_types.go @@ -169,10 +169,10 @@ type PackageRevisionStatus struct { // SelfLock identifies the location of the current package's data SelfLock *Locator `json:"selfLock,omitempty"` - // PublishedBy is the identity of the user who approved the packagerevision. + // PublishedBy is the identity of the user who approved the package revision. PublishedBy string `json:"publishedBy,omitempty"` - // PublishedAt is the time when the packagerevision were approved. + // PublishedAt is the time when the package revision was approved. // +optional PublishedAt *metav1.Time `json:"publishedAt,omitempty"` @@ -201,8 +201,8 @@ type PackageRevisionStatus struct { // +listMapKey=type Conditions []metav1.Condition `json:"conditions,omitempty"` - // PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. - PrrSizeOnDisk string `json:"prrSizeOnDisk,omitempty"` + // PrrSizeBytes is the total file size, in bytes, of the package revision's resources. + PrrSizeBytes int64 `json:"prrSizeBytes,omitempty"` } // PackageSource specifies how a package was created. diff --git a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml index 1e53726e8..2279a57ce 100644 --- a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml +++ b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml @@ -373,18 +373,19 @@ spec: - type type: object type: array - prrSizeOnDisk: - description: PrrSizeOnDisk is the total file size, in bytes, of the + prrSizeBytes: + description: PrrSizeBytes is the total file size, in bytes, of the package revision's resources. - type: string + format: int64 + type: integer publishedAt: - description: PublishedAt is the time when the packagerevision were + description: PublishedAt is the time when the package revision was approved. format: date-time type: string publishedBy: description: PublishedBy is the identity of the user who approved - the packagerevision. + the package revision. type: string renderingPrrResourceVersion: description: |- diff --git a/api/sql/porch-db-1.5.10-1.5.9.sql b/api/sql/porch-db-1.5.10-1.5.9.sql new file mode 100644 index 000000000..56e0ec78e --- /dev/null +++ b/api/sql/porch-db-1.5.10-1.5.9.sql @@ -0,0 +1,18 @@ +/* +Copyright 2026 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +ALTER TABLE package_revisions + DROP COLUMN IF EXISTS resources_size; \ No newline at end of file diff --git a/api/sql/porch-db-1.5.9-1.5.10.sql b/api/sql/porch-db-1.5.9-1.5.10.sql new file mode 100644 index 000000000..9cd988442 --- /dev/null +++ b/api/sql/porch-db-1.5.9-1.5.10.sql @@ -0,0 +1,37 @@ +/* +Copyright 2026 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +-- Add the resources_size column - stores the total size of a package revision's +-- resource files in bytes so it can be found without having to retrieve the full +-- resources. +ALTER TABLE package_revisions + ADD COLUMN IF NOT EXISTS resources_size INTEGER NOT NULL DEFAULT 0; + +-- In the event of an upgrade with repositories already synced, Porch's sync +-- routines (manual or background) will not pick up the lack of resource size +-- data for existing package revisions. +-- Go through them once, calculating their resource sizes, and backfill the +-- resources_size column. +UPDATE package_revisions pr +SET resources_size = r.total_size +FROM ( + SELECT k8s_name_space, k8s_name, revision, SUM(OCTET_LENGTH(resource_value)) AS total_size + FROM resources + GROUP BY k8s_name_space, k8s_name, revision +) r +WHERE pr.k8s_name_space = r.k8s_name_space + AND pr.k8s_name = r.k8s_name + AND pr.revision = r.revision; \ No newline at end of file diff --git a/api/sql/porch-db-1.5.9-1.6.0.sql b/api/sql/porch-db-1.5.9-1.6.0.sql new file mode 100644 index 000000000..9cd988442 --- /dev/null +++ b/api/sql/porch-db-1.5.9-1.6.0.sql @@ -0,0 +1,37 @@ +/* +Copyright 2026 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +-- Add the resources_size column - stores the total size of a package revision's +-- resource files in bytes so it can be found without having to retrieve the full +-- resources. +ALTER TABLE package_revisions + ADD COLUMN IF NOT EXISTS resources_size INTEGER NOT NULL DEFAULT 0; + +-- In the event of an upgrade with repositories already synced, Porch's sync +-- routines (manual or background) will not pick up the lack of resource size +-- data for existing package revisions. +-- Go through them once, calculating their resource sizes, and backfill the +-- resources_size column. +UPDATE package_revisions pr +SET resources_size = r.total_size +FROM ( + SELECT k8s_name_space, k8s_name, revision, SUM(OCTET_LENGTH(resource_value)) AS total_size + FROM resources + GROUP BY k8s_name_space, k8s_name, revision +) r +WHERE pr.k8s_name_space = r.k8s_name_space + AND pr.k8s_name = r.k8s_name + AND pr.revision = r.revision; \ No newline at end of file diff --git a/api/sql/porch-db-1.6.0-1.5.9.sql b/api/sql/porch-db-1.6.0-1.5.9.sql new file mode 100644 index 000000000..56e0ec78e --- /dev/null +++ b/api/sql/porch-db-1.6.0-1.5.9.sql @@ -0,0 +1,18 @@ +/* +Copyright 2026 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +ALTER TABLE package_revisions + DROP COLUMN IF EXISTS resources_size; \ No newline at end of file diff --git a/docs/content/en/docs/7_cli_api/api-ref.md b/docs/content/en/docs/7_cli_api/api-ref.md index dfcd8415d..3c3892a4e 100644 --- a/docs/content/en/docs/7_cli_api/api-ref.md +++ b/docs/content/en/docs/7_cli_api/api-ref.md @@ -367,7 +367,7 @@ _Appears in:_ | `publishTimestamp` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#time-v1-meta)_ | PublishedAt is the time when the packagerevision were approved. | | | | `deployment` _boolean_ | Deployment is true if this is a deployment package (in a deployment repository). | | | | `conditions` _[Condition](#condition) array_ | | | | -| `prrSizeOnDisk` _string_ | PrrSizeOnDisk is the total file size, in bytes, of the package revision's resources. | | | +| `prrSizeBytes` _integer_ | PrrSizeBytes is the total file size, in bytes, of the package revision's resources. | | | #### PackageSpec diff --git a/pkg/cache/dbcache/dbpackagerevision.go b/pkg/cache/dbcache/dbpackagerevision.go index f799dc9c9..fbeab855a 100644 --- a/pkg/cache/dbcache/dbpackagerevision.go +++ b/pkg/cache/dbcache/dbpackagerevision.go @@ -19,7 +19,6 @@ import ( "database/sql" "fmt" "maps" - "strconv" "strings" "time" @@ -90,7 +89,7 @@ type dbPackageRevision struct { resources map[string]string resourcesDirty bool kptfileStatus kptfileStatus - resourcesSizeBytes int + resourcesSizeBytes int64 // gitDraftPR maintains the draft in the external git repository during editing (when pushDraftsToGit is true) gitPRDraft repository.PackageRevisionDraft @@ -238,11 +237,11 @@ func (pr *dbPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi. _, selfLock, _ := pr.GetLock(ctx) status := porchapi.PackageRevisionStatus{ - UpstreamLock: repository.KptUpstreamLock2APIUpstreamLock(upstreamLock), - SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), - Deployment: pr.deployment, - Conditions: pr.kptfileStatus.Conditions, - PrrSizeOnDisk: strconv.Itoa(pr.resourcesSizeBytes) + "B", + UpstreamLock: repository.KptUpstreamLock2APIUpstreamLock(upstreamLock), + SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), + Deployment: pr.deployment, + Conditions: pr.kptfileStatus.Conditions, + PrrSizeBytes: pr.resourcesSizeBytes, } if porchapi.LifecycleIsPublished(pr.Lifecycle(ctx)) { diff --git a/pkg/cache/dbcache/dbrepository.go b/pkg/cache/dbcache/dbrepository.go index 3340f0d58..c80cb0fc5 100644 --- a/pkg/cache/dbcache/dbrepository.go +++ b/pkg/cache/dbcache/dbrepository.go @@ -478,7 +478,7 @@ func (r *dbRepository) ClosePackageRevisionDraft(ctx context.Context, prd reposi if dbPrd.resourcesSizeBytes == 0 { for _, fileString := range dbPrd.resources { - dbPrd.resourcesSizeBytes += len(fileString) + dbPrd.resourcesSizeBytes += int64(len(fileString)) } } diff --git a/pkg/cache/dbcache/dbreposync.go b/pkg/cache/dbcache/dbreposync.go index 7c951b945..cd768b45c 100644 --- a/pkg/cache/dbcache/dbreposync.go +++ b/pkg/cache/dbcache/dbreposync.go @@ -198,7 +198,7 @@ func (s *repositorySync) cacheExternalPRs(ctx context.Context, externalPrMap map // Guard against nil return from GetResources (interface contract allows it). var resources map[string]string - var resourcesSize int + var resourcesSize int64 if extPRResources == nil || extPRResources.Spec.Resources == nil { resources = make(map[string]string) resourcesSize = 0 @@ -213,7 +213,7 @@ func (s *repositorySync) cacheExternalPRs(ctx context.Context, externalPrMap map continue } resources[key] = val - resourcesSize += len(val) + resourcesSize += int64(len(val)) } } diff --git a/test/e2e/api/repository_test.go b/test/e2e/api/repository_test.go index 4ad216520..2f3c7314f 100644 --- a/test/e2e/api/repository_test.go +++ b/test/e2e/api/repository_test.go @@ -116,7 +116,7 @@ func (t *PorchSuite) TestGitRepositoryWithReleaseTagsAndDirectory() { if t.UsingDBCache { for _, pr := range list.Items { - require.Equal(t.T(), "895B", pr.Status.PrrSizeOnDisk, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeOnDisk) + require.EqualValues(t.T(), 895, pr.Status.PrrSizeBytes, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeBytes) } } } diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index 4c72f5004..acfce9d28 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var defaultEmptyResourcesSize = "893B" +var defaultEmptyResourcesSize = 893 func (t *PorchSuite) TestInitEmptyPackage() { // Create a new package via init, no task specified @@ -45,7 +45,7 @@ func (t *PorchSuite) TestInitEmptyPackage() { }) if t.UsingDBCache { - assert.Equal(t, defaultEmptyResourcesSize, pr.Status.PrrSizeOnDisk) + assert.EqualValues(t, defaultEmptyResourcesSize, pr.Status.PrrSizeBytes) } } diff --git a/test/e2e/api/rpkg_lifecycle_test.go b/test/e2e/api/rpkg_lifecycle_test.go index d0eadc908..12801c0b1 100644 --- a/test/e2e/api/rpkg_lifecycle_test.go +++ b/test/e2e/api/rpkg_lifecycle_test.go @@ -48,7 +48,7 @@ func (t *PorchSuite) TestBasicLifecycle() { Validate: func(t *PorchSuite, pr *porchapi.PackageRevision) { require.Equal(t.T(), 1, pr.Spec.Revision, "Expected revision 1, got %d", pr.Spec.Revision) if t.UsingDBCache { - require.Equal(t.T(), "885B", pr.Status.PrrSizeOnDisk, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeOnDisk) + require.EqualValues(t.T(), 885, pr.Status.PrrSizeBytes, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeBytes) } }, }, From 98c5ac4d177debdbdb7c05d39e3046f68f55266d Mon Sep 17 00:00:00 2001 From: James McDermott Date: Mon, 11 May 2026 16:42:44 +0100 Subject: [PATCH 08/20] Address review comments part 2 - also remove restriction that meant size didn't get updated on PackageRevisionResources update Signed-off-by: James McDermott --- ...iant_controller-with-workspacename_test.go | 2 +- .../packagevariant_controller_test.go | 2 +- .../inspecting-packages.md | 2 +- pkg/cache/dbcache/dbrepository.go | 7 ++-- pkg/registry/porch/table.go | 2 +- test/e2e/api/repository_test.go | 7 +--- test/e2e/api/rpkg_clone_test.go | 5 +++ test/e2e/api/rpkg_edit_test.go | 19 ++++++++- test/e2e/api/rpkg_init_test.go | 27 ++++++++++--- test/e2e/api/rpkg_lifecycle_test.go | 5 +-- test/e2e/suiteutils/suite.go | 40 +------------------ 11 files changed, 57 insertions(+), 61 deletions(-) diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go index 237071791..882ff3e96 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller-with-workspacename_test.go @@ -1,4 +1,4 @@ -// Copyright 2022, 2026 The kpt Authors +// Copyright 2025 The kpt 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/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go index f2f1c1e44..ca94432ae 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller_test.go @@ -1,4 +1,4 @@ -// Copyright 2022, 2025-2026 The kpt Authors +// Copyright 2022, 2025 The kpt 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/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md index 505ea4e15..973697dac 100644 --- a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md +++ b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md @@ -53,7 +53,7 @@ Understanding the output: | **LATEST** | Indicates the latest published PackageRevision for the package (only one; highest revision number). | `true` / `false` | | **LIFECYCLE** | Current state of the PackageRevision.
**Draft** — in progress, editable, visible to authors
**Proposed** — read-only, pending approval (approve or reject)
**Published** — immutable, production-ready, has revision numbers
**DeletionProposed** — marked for removal, pending deletion approval. | `Draft`, `Proposed`, `Published`, `DeletionProposed` | | **REPOSITORY** | Name of the source repository. | `porch-test` | -| **SIZE ON DISK** | Total disk space, in bytes, occupied by the PackageRevision's resource files | `1492B` | + --- ### Get Detailed PackageRevision Information diff --git a/pkg/cache/dbcache/dbrepository.go b/pkg/cache/dbcache/dbrepository.go index c80cb0fc5..4c1767a1b 100644 --- a/pkg/cache/dbcache/dbrepository.go +++ b/pkg/cache/dbcache/dbrepository.go @@ -476,10 +476,9 @@ func (r *dbRepository) ClosePackageRevisionDraft(ctx context.Context, prd reposi r.setCachedGitPR(dbPrd.Key().PkgKey, dbPrd.Key().WorkspaceName, gitPR) } - if dbPrd.resourcesSizeBytes == 0 { - for _, fileString := range dbPrd.resources { - dbPrd.resourcesSizeBytes += int64(len(fileString)) - } + dbPrd.resourcesSizeBytes = 0 + for _, fileString := range dbPrd.resources { + dbPrd.resourcesSizeBytes += int64(len(fileString)) } pr, err := r.savePackageRevisionDraft(ctx, prd, version) diff --git a/pkg/registry/porch/table.go b/pkg/registry/porch/table.go index 69809f0d5..6e0f42fbb 100644 --- a/pkg/registry/porch/table.go +++ b/pkg/registry/porch/table.go @@ -1,4 +1,4 @@ -// Copyright 2022, 2025-2026 The kpt Authors +// Copyright 2022, 2025 The kpt 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/test/e2e/api/repository_test.go b/test/e2e/api/repository_test.go index 2f3c7314f..1b8199c93 100644 --- a/test/e2e/api/repository_test.go +++ b/test/e2e/api/repository_test.go @@ -23,7 +23,6 @@ import ( porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" suiteutils "github.com/nephio-project/porch/test/e2e/suiteutils" - "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -112,12 +111,8 @@ func (t *PorchSuite) TestGitRepositoryWithReleaseTagsAndDirectory() { if strings.HasPrefix(pr.Spec.PackageName, directory) { t.Errorf("package name %q should not include repo directory %q as prefix", pr.Spec.PackageName, directory) } - } - if t.UsingDBCache { - for _, pr := range list.Items { - require.EqualValues(t.T(), 895, pr.Status.PrrSizeBytes, "Expected PackageRevision %s/%s resources size of 895 bytes, got %d", pr.Namespace, pr.Name, pr.Status.PrrSizeBytes) - } + t.validatePackageResourcesSize(&pr) } } diff --git a/test/e2e/api/rpkg_clone_test.go b/test/e2e/api/rpkg_clone_test.go index ed9d9838a..a682b4986 100644 --- a/test/e2e/api/rpkg_clone_test.go +++ b/test/e2e/api/rpkg_clone_test.go @@ -96,6 +96,7 @@ func (t *PorchSuite) TestCloneFromUpstream() { t.validateKptfileBasics(kptfile, istionsPackage) t.validateUpstreamLock(kptfile, testBlueprintsRepo) t.validateUpstream(kptfile, testBlueprintsRepo) + t.validatePackageResourcesSize(clonedPr) } func (t *PorchSuite) TestCloneIntoDeploymentRepository() { @@ -148,6 +149,7 @@ func (t *PorchSuite) TestCloneIntoDeploymentRepository() { t.validateKptfileBasics(kptfile, "istions-deployment") t.validateUpstreamLock(kptfile, testBlueprintsRepo) t.validateUpstream(kptfile, testBlueprintsRepo) + t.validatePackageResourcesSize(pr) // Check generated context var configmap corev1.ConfigMap @@ -262,6 +264,9 @@ data: upgradePr.Spec.Lifecycle = porchapi.PackageRevisionLifecyclePublished upgradePr = t.UpdateApprovalF(upgradePr) + // Check its package size + t.validatePackageResourcesSize(upgradePr) + basensMain := t.MustFindPackageRevision(&list, repository.PackageRevisionKey{PkgKey: repository.PackageKey{RepoKey: repository.RepositoryKey{Name: suiteutils.TestBlueprintsRepoName}, Package: basensPackage}, Revision: -1}) upgradePrTwo := t.CreatePackageSkeleton(gitRepository, "testns", testWorkspace+"-main-upgrade") diff --git a/test/e2e/api/rpkg_edit_test.go b/test/e2e/api/rpkg_edit_test.go index a6512eb2d..eafe348ea 100644 --- a/test/e2e/api/rpkg_edit_test.go +++ b/test/e2e/api/rpkg_edit_test.go @@ -106,6 +106,9 @@ func (t *PorchSuite) TestEditPackageRevision() { assert.NotNil(t, tasks[0].Edit) assert.Equal(t, pr.Name, tasks[0].Edit.Source.Name) + // Check its package size + t.validatePackageResourcesSize(pr) + // Create a new revision with a placeholder package revision as the source. // This is not allowed. editPlaceholderPR := t.CreatePackageSkeleton(repository, packageName, workspace2) @@ -136,6 +139,9 @@ func (t *PorchSuite) TestUpdateResources() { // Create a new package (via init) pr := t.CreatePackageDraftF(repository, packageName, workspace) + // Check its package size + sizeBeforeUpdate := t.validatePackageResourcesSize(pr) + // Get the package resources var prResources porchapi.PackageRevisionResources t.GetF(client.ObjectKey{ @@ -157,9 +163,10 @@ func (t *PorchSuite) TestUpdateResources() { Name: "set-annotations", }) t.SaveKptfileF(&prResources, kptfile) + updatedKptfileLength := int64(len(prResources.Spec.Resources[kptfilev1.KptFileName])) // Add a new resource - prResources.Spec.Resources["config-map.yaml"] = `apiVersion: v1 + addedResource := `apiVersion: v1 kind: ConfigMap metadata: name: update-resources-configmap @@ -167,6 +174,8 @@ metadata: data: value: Update Resources and Render ` + addedResourceLength := int64(len(addedResource)) + prResources.Spec.Resources["config-map.yaml"] = addedResource t.UpdateF(&prResources) // Re-fetch the resources to get the actual rendered result @@ -180,6 +189,14 @@ data: t.Fatalf("Updated config map config-map.yaml not found") } + // Check the PR's package size again to ensure the PrrSizeBytes reflects the added resource + t.GetF(client.ObjectKey{ + Namespace: t.Namespace, + Name: pr.Name, + }, pr) + sizeAfterUpdate := t.validatePackageResourcesSize(pr) + assert.EqualValues(t.T(), sizeBeforeUpdate+updatedKptfileLength+addedResourceLength, sizeAfterUpdate) + renderStatus := prResources.Status.RenderStatus assert.Empty(t, renderStatus.Err, "render error must be empty for successful render operation.") assert.Zero(t, renderStatus.Result.ExitCode, "exit code must be zero for successful render operation.") diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index acfce9d28..e31571555 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -23,8 +23,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var defaultEmptyResourcesSize = 893 - func (t *PorchSuite) TestInitEmptyPackage() { // Create a new package via init, no task specified const ( @@ -44,9 +42,7 @@ func (t *PorchSuite) TestInitEmptyPackage() { Description: description, }) - if t.UsingDBCache { - assert.EqualValues(t, defaultEmptyResourcesSize, pr.Status.PrrSizeBytes) - } + t.validatePackageResourcesSize(pr) } func (t *PorchSuite) TestInitTaskPackage() { @@ -98,3 +94,24 @@ func (t *PorchSuite) validateKptFileMetadata(pr *porchapi.PackageRevision, expec t.Fatalf("unexpected %s/%s package info (-want, +got) %s", pkg.Namespace, pkg.Name, cmp.Diff(want, got)) } } + +func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) int64 { + if t.UsingDBCache { + var pkg porchapi.PackageRevisionResources + t.GetF(client.ObjectKey{ + Namespace: t.Namespace, + Name: pr.Name, + }, &pkg) + + expectedResourcesSize := 0 + for _, file := range pkg.Spec.Resources { + expectedResourcesSize += len(file) + } + assert.EqualValues(t, expectedResourcesSize, pr.Status.PrrSizeBytes, + "Expected PackageRevision %s/%s resources size of %d bytes, got %d", + pr.Namespace, pr.Name, + expectedResourcesSize, pr.Status.PrrSizeBytes) + return pr.Status.PrrSizeBytes + } + return 0 +} diff --git a/test/e2e/api/rpkg_lifecycle_test.go b/test/e2e/api/rpkg_lifecycle_test.go index 12801c0b1..fc0f1016b 100644 --- a/test/e2e/api/rpkg_lifecycle_test.go +++ b/test/e2e/api/rpkg_lifecycle_test.go @@ -47,9 +47,8 @@ func (t *PorchSuite) TestBasicLifecycle() { TargetState: porchapi.PackageRevisionLifecyclePublished, Validate: func(t *PorchSuite, pr *porchapi.PackageRevision) { require.Equal(t.T(), 1, pr.Spec.Revision, "Expected revision 1, got %d", pr.Spec.Revision) - if t.UsingDBCache { - require.EqualValues(t.T(), 885, pr.Status.PrrSizeBytes, "Expected package size 885 bytes, got %d", pr.Status.PrrSizeBytes) - } + + t.validatePackageResourcesSize(pr) }, }, { diff --git a/test/e2e/suiteutils/suite.go b/test/e2e/suiteutils/suite.go index 2b7afb0ad..6f8af4409 100644 --- a/test/e2e/suiteutils/suite.go +++ b/test/e2e/suiteutils/suite.go @@ -20,7 +20,6 @@ import ( "encoding/json" "fmt" "os" - "slices" "strings" "testing" "time" @@ -33,7 +32,6 @@ import ( pvapi "github.com/nephio-project/porch/controllers/packagevariants/api/v1alpha1" pvsetapi "github.com/nephio-project/porch/controllers/packagevariantsets/api/v1alpha2" internalapi "github.com/nephio-project/porch/internal/api/porchinternal/v1alpha1" - cachetypes "github.com/nephio-project/porch/pkg/cache/types" "github.com/nephio-project/porch/pkg/repository" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -164,43 +162,9 @@ func (t *TestSuite) Initialize() { func (t *TestSuite) checkIfUsingDBCache() { t.UsingDBCache = func() bool { - - _, envVarOverride := os.LookupEnv("DB_CACHE") - postgresPresent := func() bool { - var dbSet appsv1.StatefulSet - if err := t.Client.Get(t.GetContext(), - client.ObjectKey{ - Namespace: "porch-system", - Name: "porch-postgresql", - }, &dbSet); err == nil { - return dbSet.Status.ReadyReplicas == *dbSet.Spec.Replicas - } - return false - }() - - serverCacheType := func() cachetypes.CacheType { - var serverDeployment appsv1.Deployment - if err := t.Client.Get(t.GetContext(), - client.ObjectKey{ - Namespace: "porch-system", - Name: "porch-server", - }, &serverDeployment); err == nil { - for _, container := range serverDeployment.Spec.Template.Spec.Containers { - if container.Name == "porch-server" { - if slices.ContainsFunc(container.Args, func(anArg string) bool { - return strings.Contains(anArg, "cache-type=db") - }) { - return cachetypes.DBCacheType - } - } - } - return cachetypes.CRCacheType - } - return cachetypes.CRCacheType - - }() - return envVarOverride || serverCacheType == cachetypes.DBCacheType || postgresPresent + return os.Getenv("DB_CACHE") != "" }() + t.UsingDBCache = true } func (t *TestSuite) PorchServerServiceKey() client.ObjectKey { From 85f840cff41685107a8905bf7cb6df6a41b785e2 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 12 May 2026 09:00:10 +0100 Subject: [PATCH 09/20] fix failing CR-cache E2E tests Signed-off-by: James McDermott --- test/e2e/api/rpkg_edit_test.go | 4 +++- test/e2e/suiteutils/suite.go | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/api/rpkg_edit_test.go b/test/e2e/api/rpkg_edit_test.go index eafe348ea..7aae742d9 100644 --- a/test/e2e/api/rpkg_edit_test.go +++ b/test/e2e/api/rpkg_edit_test.go @@ -195,7 +195,9 @@ data: Name: pr.Name, }, pr) sizeAfterUpdate := t.validatePackageResourcesSize(pr) - assert.EqualValues(t.T(), sizeBeforeUpdate+updatedKptfileLength+addedResourceLength, sizeAfterUpdate) + if t.UsingDBCache { + assert.EqualValues(t.T(), sizeBeforeUpdate+updatedKptfileLength+addedResourceLength, sizeAfterUpdate) + } renderStatus := prResources.Status.RenderStatus assert.Empty(t, renderStatus.Err, "render error must be empty for successful render operation.") diff --git a/test/e2e/suiteutils/suite.go b/test/e2e/suiteutils/suite.go index 6f8af4409..c4defc4c7 100644 --- a/test/e2e/suiteutils/suite.go +++ b/test/e2e/suiteutils/suite.go @@ -164,7 +164,6 @@ func (t *TestSuite) checkIfUsingDBCache() { t.UsingDBCache = func() bool { return os.Getenv("DB_CACHE") != "" }() - t.UsingDBCache = true } func (t *TestSuite) PorchServerServiceKey() client.ObjectKey { From f9834c4a865960b9dc15fbbb9b1be3f25103f39a Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 12 May 2026 10:16:39 +0100 Subject: [PATCH 10/20] comment nitpick to retrigger CI Signed-off-by: James McDermott --- api/sql/porch-db-1.5.9-1.5.10.sql | 4 ++-- api/sql/porch-db-1.5.9-1.6.0.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/sql/porch-db-1.5.9-1.5.10.sql b/api/sql/porch-db-1.5.9-1.5.10.sql index 9cd988442..d541ba2f5 100644 --- a/api/sql/porch-db-1.5.9-1.5.10.sql +++ b/api/sql/porch-db-1.5.9-1.5.10.sql @@ -21,8 +21,8 @@ ALTER TABLE package_revisions ADD COLUMN IF NOT EXISTS resources_size INTEGER NOT NULL DEFAULT 0; -- In the event of an upgrade with repositories already synced, Porch's sync --- routines (manual or background) will not pick up the lack of resource size --- data for existing package revisions. +-- routines (manual or background) will not detect the need to backfill +-- resource sizes for existing package revisions. -- Go through them once, calculating their resource sizes, and backfill the -- resources_size column. UPDATE package_revisions pr diff --git a/api/sql/porch-db-1.5.9-1.6.0.sql b/api/sql/porch-db-1.5.9-1.6.0.sql index 9cd988442..d541ba2f5 100644 --- a/api/sql/porch-db-1.5.9-1.6.0.sql +++ b/api/sql/porch-db-1.5.9-1.6.0.sql @@ -21,8 +21,8 @@ ALTER TABLE package_revisions ADD COLUMN IF NOT EXISTS resources_size INTEGER NOT NULL DEFAULT 0; -- In the event of an upgrade with repositories already synced, Porch's sync --- routines (manual or background) will not pick up the lack of resource size --- data for existing package revisions. +-- routines (manual or background) will not detect the need to backfill +-- resource sizes for existing package revisions. -- Go through them once, calculating their resource sizes, and backfill the -- resources_size column. UPDATE package_revisions pr From 037c3b0a64c780210f4d906b05e8bf39d198e23f Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 12 May 2026 16:42:07 +0100 Subject: [PATCH 11/20] comment nitpick to retrigger CI Signed-off-by: James McDermott --- api/porch/types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/porch/types.go b/api/porch/types.go index 273bb1215..50b78919b 100644 --- a/api/porch/types.go +++ b/api/porch/types.go @@ -152,10 +152,10 @@ type PackageRevisionStatus struct { // SelfLock identifies the location of the current package's data SelfLock *Locator `json:"selfLock,omitempty"` - // PublishedBy is the identity of the user who approved the packagerevision. + // PublishedBy is the identity of the user who approved the package revision. PublishedBy string `json:"publishedBy,omitempty"` - // PublishedAt is the time when the packagerevision were approved. + // PublishedAt is the time when the package revision was approved. PublishedAt metav1.Time `json:"publishTimestamp,omitempty"` // Deployment is true if this is a deployment package (in a deployment repository). From 8487b25ad975aa59abb1ac71747cccb04d100bf2 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 12 May 2026 17:09:10 +0100 Subject: [PATCH 12/20] comment nitpick to retrigger CI Signed-off-by: James McDermott --- api/porch/types.go | 2 +- api/porch/v1alpha1/types.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/porch/types.go b/api/porch/types.go index 50b78919b..0734a73e3 100644 --- a/api/porch/types.go +++ b/api/porch/types.go @@ -149,7 +149,7 @@ type PackageRevisionStatus struct { // UpstreamLock identifies the upstream data for this package. UpstreamLock *Locator `json:"upstreamLock,omitempty"` - // SelfLock identifies the location of the current package's data + // SelfLock identifies the location of the current package's data. SelfLock *Locator `json:"selfLock,omitempty"` // PublishedBy is the identity of the user who approved the package revision. diff --git a/api/porch/v1alpha1/types.go b/api/porch/v1alpha1/types.go index 56aae4614..6d8be7617 100644 --- a/api/porch/v1alpha1/types.go +++ b/api/porch/v1alpha1/types.go @@ -149,7 +149,7 @@ type PackageRevisionStatus struct { // UpstreamLock identifies the upstream data for this package. UpstreamLock *Locator `json:"upstreamLock,omitempty"` - // SelfLock identifies the location of the current package's data + // SelfLock identifies the location of the current package's data. SelfLock *Locator `json:"selfLock,omitempty"` // PublishedBy is the identity of the user who approved the package revision. From c5135498662e87a49002f83ae908b854078d9fe2 Mon Sep 17 00:00:00 2001 From: James McDermott Date: Tue, 12 May 2026 18:02:08 +0100 Subject: [PATCH 13/20] nitpick to retrigger CI Signed-off-by: James McDermott --- pkg/cache/dbcache/dbrepository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cache/dbcache/dbrepository.go b/pkg/cache/dbcache/dbrepository.go index 4c1767a1b..aad4c2b53 100644 --- a/pkg/cache/dbcache/dbrepository.go +++ b/pkg/cache/dbcache/dbrepository.go @@ -437,7 +437,7 @@ func (r *dbRepository) ListPackages(ctx context.Context, filter repository.ListP } func (r *dbRepository) Version(ctx context.Context) (string, error) { - _, span := tracer.Start(ctx, "cachedRepository::Version", trace.WithAttributes()) + _, span := tracer.Start(ctx, "dbRepository::Version", trace.WithAttributes()) defer span.End() return r.externalRepo.Version(ctx) From b762ff69bf5c740c74382a296ff20108eb910e4a Mon Sep 17 00:00:00 2001 From: James McDermott Date: Wed, 13 May 2026 16:19:57 +0100 Subject: [PATCH 14/20] replace missed nephio-project imports with kptdev Signed-off-by: James McDermott --- test/e2e/api/repository_test.go | 6 +++--- test/e2e/api/rpkg_init_test.go | 4 ++-- test/e2e/suiteutils/suite.go | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/e2e/api/repository_test.go b/test/e2e/api/repository_test.go index 1b8199c93..3787b2665 100644 --- a/test/e2e/api/repository_test.go +++ b/test/e2e/api/repository_test.go @@ -20,9 +20,9 @@ import ( "sync" "time" - porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" - configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" - suiteutils "github.com/nephio-project/porch/test/e2e/suiteutils" + porchapi "github.com/kptdev/porch/api/porch/v1alpha1" + configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1" + suiteutils "github.com/kptdev/porch/test/e2e/suiteutils" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index e31571555..2549201e9 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -17,8 +17,8 @@ package api import ( "github.com/google/go-cmp/cmp" kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" - suiteutils "github.com/nephio-project/porch/test/e2e/suiteutils" + porchapi "github.com/kptdev/porch/api/porch/v1alpha1" + suiteutils "github.com/kptdev/porch/test/e2e/suiteutils" "github.com/stretchr/testify/assert" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/test/e2e/suiteutils/suite.go b/test/e2e/suiteutils/suite.go index c4defc4c7..b663a6730 100644 --- a/test/e2e/suiteutils/suite.go +++ b/test/e2e/suiteutils/suite.go @@ -27,12 +27,12 @@ import ( "github.com/google/go-cmp/cmp" kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" - porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" - configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" - pvapi "github.com/nephio-project/porch/controllers/packagevariants/api/v1alpha1" - pvsetapi "github.com/nephio-project/porch/controllers/packagevariantsets/api/v1alpha2" - internalapi "github.com/nephio-project/porch/internal/api/porchinternal/v1alpha1" - "github.com/nephio-project/porch/pkg/repository" + porchapi "github.com/kptdev/porch/api/porch/v1alpha1" + configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1" + pvapi "github.com/kptdev/porch/controllers/packagevariants/api/v1alpha1" + pvsetapi "github.com/kptdev/porch/controllers/packagevariantsets/api/v1alpha2" + internalapi "github.com/kptdev/porch/internal/api/porchinternal/v1alpha1" + "github.com/kptdev/porch/pkg/repository" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" From 86dbd08e2a6d5000f8bfb0541cb02df98261469f Mon Sep 17 00:00:00 2001 From: James McDermott Date: Thu, 14 May 2026 16:30:58 +0100 Subject: [PATCH 15/20] Address Copilot review comments Signed-off-by: James McDermott --- api/sql/porch-db-1.5.10-1.5.9.sql | 2 +- api/sql/porch-db-1.5.9-1.5.10.sql | 4 ++-- api/sql/porch-db-1.5.9-1.6.0.sql | 4 ++-- api/sql/porch-db-1.6.0-1.5.9.sql | 2 +- api/sql/porch-db.sql | 2 +- deployments/porch/3-porch-postgres-bundle.yaml | 2 +- pkg/cache/dbcache/dbpackagerevision.go | 1 + test/e2e/api/rpkg_edit_test.go | 10 +++------- test/e2e/api/rpkg_init_test.go | 4 +--- 9 files changed, 13 insertions(+), 18 deletions(-) diff --git a/api/sql/porch-db-1.5.10-1.5.9.sql b/api/sql/porch-db-1.5.10-1.5.9.sql index 56e0ec78e..fd9494eb7 100644 --- a/api/sql/porch-db-1.5.10-1.5.9.sql +++ b/api/sql/porch-db-1.5.10-1.5.9.sql @@ -1,5 +1,5 @@ /* -Copyright 2026 The kpt and Nephio Authors +Copyright 2026 The kpt 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/api/sql/porch-db-1.5.9-1.5.10.sql b/api/sql/porch-db-1.5.9-1.5.10.sql index d541ba2f5..710d9240c 100644 --- a/api/sql/porch-db-1.5.9-1.5.10.sql +++ b/api/sql/porch-db-1.5.9-1.5.10.sql @@ -1,5 +1,5 @@ /* -Copyright 2026 The kpt and Nephio Authors +Copyright 2026 The kpt Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ limitations under the License. -- resource files in bytes so it can be found without having to retrieve the full -- resources. ALTER TABLE package_revisions - ADD COLUMN IF NOT EXISTS resources_size INTEGER NOT NULL DEFAULT 0; + ADD COLUMN IF NOT EXISTS resources_size BIGINT NOT NULL DEFAULT 0; -- In the event of an upgrade with repositories already synced, Porch's sync -- routines (manual or background) will not detect the need to backfill diff --git a/api/sql/porch-db-1.5.9-1.6.0.sql b/api/sql/porch-db-1.5.9-1.6.0.sql index d541ba2f5..710d9240c 100644 --- a/api/sql/porch-db-1.5.9-1.6.0.sql +++ b/api/sql/porch-db-1.5.9-1.6.0.sql @@ -1,5 +1,5 @@ /* -Copyright 2026 The kpt and Nephio Authors +Copyright 2026 The kpt Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ limitations under the License. -- resource files in bytes so it can be found without having to retrieve the full -- resources. ALTER TABLE package_revisions - ADD COLUMN IF NOT EXISTS resources_size INTEGER NOT NULL DEFAULT 0; + ADD COLUMN IF NOT EXISTS resources_size BIGINT NOT NULL DEFAULT 0; -- In the event of an upgrade with repositories already synced, Porch's sync -- routines (manual or background) will not detect the need to backfill diff --git a/api/sql/porch-db-1.6.0-1.5.9.sql b/api/sql/porch-db-1.6.0-1.5.9.sql index 56e0ec78e..fd9494eb7 100644 --- a/api/sql/porch-db-1.6.0-1.5.9.sql +++ b/api/sql/porch-db-1.6.0-1.5.9.sql @@ -1,5 +1,5 @@ /* -Copyright 2026 The kpt and Nephio Authors +Copyright 2026 The kpt 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/api/sql/porch-db.sql b/api/sql/porch-db.sql index 017bacd17..c922c7080 100644 --- a/api/sql/porch-db.sql +++ b/api/sql/porch-db.sql @@ -86,7 +86,7 @@ CREATE TABLE IF NOT EXISTS package_revisions ( latest BOOLEAN NOT NULL DEFAULT FALSE, tasks TEXT NOT NULL, kptfile_status TEXT NOT NULL DEFAULT '{}', - resources_size INTEGER NOT NULL DEFAULT 0, + resources_size BIGINT NOT NULL DEFAULT 0, PRIMARY KEY (k8s_name_space, k8s_name), CONSTRAINT fk_package FOREIGN KEY (k8s_name_space, package_k8s_name) diff --git a/deployments/porch/3-porch-postgres-bundle.yaml b/deployments/porch/3-porch-postgres-bundle.yaml index 6ece91251..11894d971 100644 --- a/deployments/porch/3-porch-postgres-bundle.yaml +++ b/deployments/porch/3-porch-postgres-bundle.yaml @@ -354,7 +354,7 @@ data: latest BOOLEAN NOT NULL DEFAULT FALSE, tasks TEXT NOT NULL, kptfile_status TEXT NOT NULL DEFAULT '{}', - resources_size INTEGER NOT NULL DEFAULT 0, + resources_size BIGINT NOT NULL DEFAULT 0, PRIMARY KEY (k8s_name_space, k8s_name), CONSTRAINT fk_package FOREIGN KEY (k8s_name_space, package_k8s_name) diff --git a/pkg/cache/dbcache/dbpackagerevision.go b/pkg/cache/dbcache/dbpackagerevision.go index fbeab855a..5e9cd52ff 100644 --- a/pkg/cache/dbcache/dbpackagerevision.go +++ b/pkg/cache/dbcache/dbpackagerevision.go @@ -455,6 +455,7 @@ func (pr *dbPackageRevision) copyToThis(otherPr *dbPackageRevision) { pr.lifecycle = otherPr.lifecycle pr.tasks = otherPr.tasks pr.resources = otherPr.resources + pr.resourcesSizeBytes = otherPr.resourcesSizeBytes } func (pr *dbPackageRevision) UpdateResources(ctx context.Context, new *porchapi.PackageRevisionResources, change *porchapi.Task) error { diff --git a/test/e2e/api/rpkg_edit_test.go b/test/e2e/api/rpkg_edit_test.go index 7aae742d9..18debee2f 100644 --- a/test/e2e/api/rpkg_edit_test.go +++ b/test/e2e/api/rpkg_edit_test.go @@ -140,7 +140,7 @@ func (t *PorchSuite) TestUpdateResources() { pr := t.CreatePackageDraftF(repository, packageName, workspace) // Check its package size - sizeBeforeUpdate := t.validatePackageResourcesSize(pr) + t.validatePackageResourcesSize(pr) // Get the package resources var prResources porchapi.PackageRevisionResources @@ -162,8 +162,8 @@ func (t *PorchSuite) TestUpdateResources() { }, Name: "set-annotations", }) + t.SaveKptfileF(&prResources, kptfile) - updatedKptfileLength := int64(len(prResources.Spec.Resources[kptfilev1.KptFileName])) // Add a new resource addedResource := `apiVersion: v1 @@ -174,7 +174,6 @@ metadata: data: value: Update Resources and Render ` - addedResourceLength := int64(len(addedResource)) prResources.Spec.Resources["config-map.yaml"] = addedResource t.UpdateF(&prResources) @@ -194,10 +193,7 @@ data: Namespace: t.Namespace, Name: pr.Name, }, pr) - sizeAfterUpdate := t.validatePackageResourcesSize(pr) - if t.UsingDBCache { - assert.EqualValues(t.T(), sizeBeforeUpdate+updatedKptfileLength+addedResourceLength, sizeAfterUpdate) - } + t.validatePackageResourcesSize(pr) renderStatus := prResources.Status.RenderStatus assert.Empty(t, renderStatus.Err, "render error must be empty for successful render operation.") diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index 2549201e9..e879ffbcb 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -95,7 +95,7 @@ func (t *PorchSuite) validateKptFileMetadata(pr *porchapi.PackageRevision, expec } } -func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) int64 { +func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) { if t.UsingDBCache { var pkg porchapi.PackageRevisionResources t.GetF(client.ObjectKey{ @@ -111,7 +111,5 @@ func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) "Expected PackageRevision %s/%s resources size of %d bytes, got %d", pr.Namespace, pr.Name, expectedResourcesSize, pr.Status.PrrSizeBytes) - return pr.Status.PrrSizeBytes } - return 0 } From 6b5c7bd05ffaa47823b2df56d00cd6cf59050644 Mon Sep 17 00:00:00 2001 From: ezmcdja Date: Thu, 14 May 2026 17:20:51 +0100 Subject: [PATCH 16/20] Address Copilot review comments part 2 Signed-off-by: ezmcdja --- pkg/cache/dbcache/dbpackagerevisionsql.go | 4 ++-- test/e2e/api/rpkg_init_test.go | 4 ++++ test/e2e/suiteutils/suite.go | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/cache/dbcache/dbpackagerevisionsql.go b/pkg/cache/dbcache/dbpackagerevisionsql.go index c0c914378..284e10360 100644 --- a/pkg/cache/dbcache/dbpackagerevisionsql.go +++ b/pkg/cache/dbcache/dbpackagerevisionsql.go @@ -397,7 +397,7 @@ func pkgRevUpdateDB(ctx context.Context, pr *dbPackageRevision, updateResources DO UPDATE SET package_k8s_name = EXCLUDED.package_k8s_name, meta = EXCLUDED.meta, - revision = EXCLUDED.revision, + revision = EXCLUDED.revision, spec = EXCLUDED.spec, updated = EXCLUDED.updated, updatedby = EXCLUDED.updatedby, @@ -405,7 +405,7 @@ func pkgRevUpdateDB(ctx context.Context, pr *dbPackageRevision, updateResources ext_pr_id = EXCLUDED.ext_pr_id, tasks = EXCLUDED.tasks, kptfile_status = EXCLUDED.kptfile_status, - resources_size = EXCLUDED.resources_size; + resources_size = EXCLUDED.resources_size; ` } diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index e879ffbcb..39db3778e 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -96,7 +96,9 @@ func (t *PorchSuite) validateKptFileMetadata(pr *porchapi.PackageRevision, expec } func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) { + t.T().Helper() if t.UsingDBCache { + t.Logf("DB cache is enabled: validating package resource size") var pkg porchapi.PackageRevisionResources t.GetF(client.ObjectKey{ Namespace: t.Namespace, @@ -111,5 +113,7 @@ func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) "Expected PackageRevision %s/%s resources size of %d bytes, got %d", pr.Namespace, pr.Name, expectedResourcesSize, pr.Status.PrrSizeBytes) + } else { + t.Logf("DB cache is disabled: skipping package resource size validation") } } diff --git a/test/e2e/suiteutils/suite.go b/test/e2e/suiteutils/suite.go index b663a6730..d8ddd8c20 100644 --- a/test/e2e/suiteutils/suite.go +++ b/test/e2e/suiteutils/suite.go @@ -86,7 +86,6 @@ type TestSuite struct { porchServerInCluster *bool // Cached result of IsPorchServerInCluster check repoControllerInCluster *bool // Cached result of IsRepoControllerInCluster check UsingDBCache bool // Tests running against Porch with database cache - } func (t *TestSuite) SetupSuite() { From c1e49e22b723bae5504d60e84d182079e8e7ad21 Mon Sep 17 00:00:00 2001 From: ezmcdja Date: Thu, 14 May 2026 17:26:37 +0100 Subject: [PATCH 17/20] ssimplify tests' DB cache detection - missed Copilot review comment Signed-off-by: ezmcdja --- test/e2e/suiteutils/suite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/e2e/suiteutils/suite.go b/test/e2e/suiteutils/suite.go index d8ddd8c20..c8dad4407 100644 --- a/test/e2e/suiteutils/suite.go +++ b/test/e2e/suiteutils/suite.go @@ -160,9 +160,7 @@ func (t *TestSuite) Initialize() { } func (t *TestSuite) checkIfUsingDBCache() { - t.UsingDBCache = func() bool { - return os.Getenv("DB_CACHE") != "" - }() + t.UsingDBCache = (os.Getenv("DB_CACHE") != "") } func (t *TestSuite) PorchServerServiceKey() client.ObjectKey { From 11d264d3ec740342d8e11f0e77c9405668845b5b Mon Sep 17 00:00:00 2001 From: James McDermott Date: Fri, 15 May 2026 15:00:28 +0100 Subject: [PATCH 18/20] nitpick to retrigger CI Signed-off-by: James McDermott --- pkg/externalrepo/git/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/externalrepo/git/doc.go b/pkg/externalrepo/git/doc.go index 70e8a42a4..e6ed46880 100644 --- a/pkg/externalrepo/git/doc.go +++ b/pkg/externalrepo/git/doc.go @@ -28,7 +28,7 @@ // would add a layer of complexity where branches can become out of sync // and in need of reconciliation and conflict resolution. Instead, Porch // analyzes the remote references (refs/remotes/origin/branch...) to -// discover packges. These refs are never directly updated by Porch other +// discover packages. These refs are never directly updated by Porch other // than by push or fetch to/from remote. // Any intermediate commits Porch makes are either in 'detached HEAD' // mode, or using temporary branches (these will become relevant if/when From 76de010f065542809a2e96f7c4e44842161b1e0e Mon Sep 17 00:00:00 2001 From: James McDermott Date: Fri, 15 May 2026 15:56:49 +0100 Subject: [PATCH 19/20] Address Copilot review comments part 3 Signed-off-by: James McDermott --- api/generated/openapi/zz_generated.openapi.go | 6 +++--- api/porch/types.go | 4 ++-- api/porch/v1alpha1/types.go | 4 ++-- api/porch/v1alpha1/zz_generated.conversion.go | 4 ++-- api/porch/v1alpha2/packagerevision_types.go | 4 ++-- api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml | 10 +++++----- .../inspecting-packages.md | 1 - docs/content/en/docs/7_cli_api/api-ref.md | 10 ++++------ pkg/cache/dbcache/dbpackagerevision.go | 10 +++++----- test/e2e/api/rpkg_edit_test.go | 2 +- test/e2e/api/rpkg_init_test.go | 4 ++-- 11 files changed, 28 insertions(+), 31 deletions(-) diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index de2bcb3b6..bf1edc1a6 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -1050,7 +1050,7 @@ func schema_porch_api_porch_v1alpha1_PackageRevisionStatus(ref common.ReferenceC }, "selfLock": { SchemaProps: spec.SchemaProps{ - Description: "SelfLock identifies the location of the current package's data", + Description: "SelfLock identifies the location of the current package's data.", Ref: ref("github.com/kptdev/porch/api/porch/v1alpha1.Locator"), }, }, @@ -1087,9 +1087,9 @@ func schema_porch_api_porch_v1alpha1_PackageRevisionStatus(ref common.ReferenceC }, }, }, - "prrSizeBytes": { + "resourcesSizeBytes": { SchemaProps: spec.SchemaProps{ - Description: "PrrSizeBytes is the total file size, in bytes, of the package revision's resources.", + Description: "ResourcesSizeBytes is the total file size, in bytes, of the package revision's resources.", Type: []string{"integer"}, Format: "int64", }, diff --git a/api/porch/types.go b/api/porch/types.go index 0734a73e3..b2391b0f0 100644 --- a/api/porch/types.go +++ b/api/porch/types.go @@ -163,8 +163,8 @@ type PackageRevisionStatus struct { Conditions []Condition `json:"conditions,omitempty"` - // PrrSizeBytes is the total file size, in bytes, of the package revision's resources. - PrrSizeBytes int64 `json:"prrSizeBytes,omitempty"` + // ResourcesSizeBytes is the total file size, in bytes, of the package revision's resources. + ResourcesSizeBytes int64 `json:"resourcesSizeBytes,omitempty"` } type TaskType string diff --git a/api/porch/v1alpha1/types.go b/api/porch/v1alpha1/types.go index 6d8be7617..75205c9f2 100644 --- a/api/porch/v1alpha1/types.go +++ b/api/porch/v1alpha1/types.go @@ -163,8 +163,8 @@ type PackageRevisionStatus struct { Conditions []Condition `json:"conditions,omitempty"` - // PrrSizeBytes is the total file size, in bytes, of the package revision's resources. - PrrSizeBytes int64 `json:"prrSizeBytes,omitempty"` + // ResourcesSizeBytes is the total file size, in bytes, of the package revision's resources. + ResourcesSizeBytes int64 `json:"resourcesSizeBytes,omitempty"` } type TaskType string diff --git a/api/porch/v1alpha1/zz_generated.conversion.go b/api/porch/v1alpha1/zz_generated.conversion.go index 489a789b0..eb6b26088 100644 --- a/api/porch/v1alpha1/zz_generated.conversion.go +++ b/api/porch/v1alpha1/zz_generated.conversion.go @@ -932,7 +932,7 @@ func autoConvert_v1alpha1_PackageRevisionStatus_To_porch_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]porch.Condition)(unsafe.Pointer(&in.Conditions)) - out.PrrSizeBytes = in.PrrSizeBytes + out.ResourcesSizeBytes = in.ResourcesSizeBytes return nil } @@ -948,7 +948,7 @@ func autoConvert_porch_PackageRevisionStatus_To_v1alpha1_PackageRevisionStatus(i out.PublishedAt = in.PublishedAt out.Deployment = in.Deployment out.Conditions = *(*[]Condition)(unsafe.Pointer(&in.Conditions)) - out.PrrSizeBytes = in.PrrSizeBytes + out.ResourcesSizeBytes = in.ResourcesSizeBytes return nil } diff --git a/api/porch/v1alpha2/packagerevision_types.go b/api/porch/v1alpha2/packagerevision_types.go index 60a145ae9..89d6feae5 100644 --- a/api/porch/v1alpha2/packagerevision_types.go +++ b/api/porch/v1alpha2/packagerevision_types.go @@ -201,8 +201,8 @@ type PackageRevisionStatus struct { // +listMapKey=type Conditions []metav1.Condition `json:"conditions,omitempty"` - // PrrSizeBytes is the total file size, in bytes, of the package revision's resources. - PrrSizeBytes int64 `json:"prrSizeBytes,omitempty"` + // ResourcesSizeBytes is the total file size, in bytes, of the package revision's resources. + ResourcesSizeBytes int64 `json:"resourcesSizeBytes,omitempty"` } // PackageSource specifies how a package was created. diff --git a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml index 2279a57ce..07d0758dd 100644 --- a/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml +++ b/api/porch/v1alpha2/porch.kpt.dev_packagerevisions.yaml @@ -373,11 +373,6 @@ spec: - type type: object type: array - prrSizeBytes: - description: PrrSizeBytes is the total file size, in bytes, of the - package revision's resources. - format: int64 - type: integer publishedAt: description: PublishedAt is the time when the package revision was approved. @@ -392,6 +387,11 @@ spec: RenderingPrrResourceVersion tracks the PRR resourceVersion currently being rendered. Prevents concurrent renders. type: string + resourcesSizeBytes: + description: ResourcesSizeBytes is the total file size, in bytes, + of the package revision's resources. + format: int64 + type: integer revision: description: |- Revision identifies the version of the package. diff --git a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md index 973697dac..09df483c1 100644 --- a/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md +++ b/docs/content/en/docs/4_tutorials_and_how-tos/working_with_package_revisions/inspecting-packages.md @@ -53,7 +53,6 @@ Understanding the output: | **LATEST** | Indicates the latest published PackageRevision for the package (only one; highest revision number). | `true` / `false` | | **LIFECYCLE** | Current state of the PackageRevision.
**Draft** — in progress, editable, visible to authors
**Proposed** — read-only, pending approval (approve or reject)
**Published** — immutable, production-ready, has revision numbers
**DeletionProposed** — marked for removal, pending deletion approval. | `Draft`, `Proposed`, `Published`, `DeletionProposed` | | **REPOSITORY** | Name of the source repository. | `porch-test` | - --- ### Get Detailed PackageRevision Information diff --git a/docs/content/en/docs/7_cli_api/api-ref.md b/docs/content/en/docs/7_cli_api/api-ref.md index 3c3892a4e..0fdf93785 100644 --- a/docs/content/en/docs/7_cli_api/api-ref.md +++ b/docs/content/en/docs/7_cli_api/api-ref.md @@ -362,12 +362,12 @@ _Appears in:_ | Field | Description | Default | Validation | | --- | --- | --- | --- | | `upstreamLock` _[Locator](#locator)_ | UpstreamLock identifies the upstream data for this package. | | | -| `selfLock` _[Locator](#locator)_ | SelfLock identifies the location of the current package's data | | | -| `publishedBy` _string_ | PublishedBy is the identity of the user who approved the packagerevision. | | | -| `publishTimestamp` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#time-v1-meta)_ | PublishedAt is the time when the packagerevision were approved. | | | +| `selfLock` _[Locator](#locator)_ | SelfLock identifies the location of the current package's data. | | | +| `publishedBy` _string_ | PublishedBy is the identity of the user who approved the package revision. | | | +| `publishTimestamp` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#time-v1-meta)_ | PublishedAt is the time when the package revision was approved. | | | | `deployment` _boolean_ | Deployment is true if this is a deployment package (in a deployment repository). | | | | `conditions` _[Condition](#condition) array_ | | | | -| `prrSizeBytes` _integer_ | PrrSizeBytes is the total file size, in bytes, of the package revision's resources. | | | +| `resourcesSizeBytes` _integer_ | ResourcesSizeBytes is the total file size, in bytes, of the package revision's resources. | | | #### PackageSpec @@ -636,5 +636,3 @@ _Appears in:_ | `type` _[RepositoryType](#repositorytype)_ | Type of the repository (i.e. git). If empty, `upstreamRef` will be used. | | | | `git` _[GitPackage](#gitpackage)_ | Git upstream package specification. Required if `type` is `git`. Must be unspecified if `type` is not `git`. | | | | `upstreamRef` _[PackageRevisionRef](#packagerevisionref)_ | UpstreamRef is the reference to the package from a registered repository rather than external package. | | | - - diff --git a/pkg/cache/dbcache/dbpackagerevision.go b/pkg/cache/dbcache/dbpackagerevision.go index 5e9cd52ff..a11806b4f 100644 --- a/pkg/cache/dbcache/dbpackagerevision.go +++ b/pkg/cache/dbcache/dbpackagerevision.go @@ -237,11 +237,11 @@ func (pr *dbPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi. _, selfLock, _ := pr.GetLock(ctx) status := porchapi.PackageRevisionStatus{ - UpstreamLock: repository.KptUpstreamLock2APIUpstreamLock(upstreamLock), - SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), - Deployment: pr.deployment, - Conditions: pr.kptfileStatus.Conditions, - PrrSizeBytes: pr.resourcesSizeBytes, + UpstreamLock: repository.KptUpstreamLock2APIUpstreamLock(upstreamLock), + SelfLock: repository.KptUpstreamLock2APIUpstreamLock(selfLock), + Deployment: pr.deployment, + Conditions: pr.kptfileStatus.Conditions, + ResourcesSizeBytes: pr.resourcesSizeBytes, } if porchapi.LifecycleIsPublished(pr.Lifecycle(ctx)) { diff --git a/test/e2e/api/rpkg_edit_test.go b/test/e2e/api/rpkg_edit_test.go index 18debee2f..73664cabc 100644 --- a/test/e2e/api/rpkg_edit_test.go +++ b/test/e2e/api/rpkg_edit_test.go @@ -188,7 +188,7 @@ data: t.Fatalf("Updated config map config-map.yaml not found") } - // Check the PR's package size again to ensure the PrrSizeBytes reflects the added resource + // Check the PR's package size again to ensure the ResourcesSizeBytes reflects the added resource t.GetF(client.ObjectKey{ Namespace: t.Namespace, Name: pr.Name, diff --git a/test/e2e/api/rpkg_init_test.go b/test/e2e/api/rpkg_init_test.go index 39db3778e..ef424f5a0 100644 --- a/test/e2e/api/rpkg_init_test.go +++ b/test/e2e/api/rpkg_init_test.go @@ -109,10 +109,10 @@ func (t *PorchSuite) validatePackageResourcesSize(pr *porchapi.PackageRevision) for _, file := range pkg.Spec.Resources { expectedResourcesSize += len(file) } - assert.EqualValues(t, expectedResourcesSize, pr.Status.PrrSizeBytes, + assert.EqualValues(t, expectedResourcesSize, pr.Status.ResourcesSizeBytes, "Expected PackageRevision %s/%s resources size of %d bytes, got %d", pr.Namespace, pr.Name, - expectedResourcesSize, pr.Status.PrrSizeBytes) + expectedResourcesSize, pr.Status.ResourcesSizeBytes) } else { t.Logf("DB cache is disabled: skipping package resource size validation") } From fad77cf26b2286c016fe65e0cc94db412ee02afb Mon Sep 17 00:00:00 2001 From: James McDermott Date: Mon, 18 May 2026 11:25:02 +0100 Subject: [PATCH 20/20] fix CI - update embedded-postgres used in tests to resolve "no version found" Signed-off-by: James McDermott --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4c1bd2933..bcca49e43 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ replace k8s.io/apiserver v0.34.1 => ./third_party/k8s.io/apiserver-v0.34.1 require ( cloud.google.com/go/iam v1.5.3 - github.com/fergusstrange/embedded-postgres v1.32.0 + github.com/fergusstrange/embedded-postgres v1.34.0 github.com/fsnotify/fsnotify v1.9.0 github.com/go-git/go-billy/v5 v5.9.0 github.com/go-git/go-git/v5 v5.19.0 diff --git a/go.sum b/go.sum index 8413e1232..7650f65f6 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,8 @@ github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2 github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSYXu++VVOHnXeitef/D8n/6y4QV8uLHSFXX4NeXMGc= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fergusstrange/embedded-postgres v1.32.0 h1:kh2ozEvAx2A0LoIJZEGNwHmoFTEQD243KrHjifcYGMo= -github.com/fergusstrange/embedded-postgres v1.32.0/go.mod h1:w0YvnCgf19o6tskInrOOACtnqfVlOvluz3hlNLY7tRk= +github.com/fergusstrange/embedded-postgres v1.34.0 h1:c6RKhPKFsLVU+Tdxsx8q0UxCHsvZZ/iShAnljRBXs6s= +github.com/fergusstrange/embedded-postgres v1.34.0/go.mod h1:w0YvnCgf19o6tskInrOOACtnqfVlOvluz3hlNLY7tRk= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=