diff --git a/api/generated/clientset/versioned/clientset.go b/api/generated/clientset/versioned/clientset.go index c1d2d31d..4c55ca25 100644 --- a/api/generated/clientset/versioned/clientset.go +++ b/api/generated/clientset/versioned/clientset.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/fake/clientset_generated.go b/api/generated/clientset/versioned/fake/clientset_generated.go index 1802933c..b6a71bdf 100644 --- a/api/generated/clientset/versioned/fake/clientset_generated.go +++ b/api/generated/clientset/versioned/fake/clientset_generated.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/fake/doc.go b/api/generated/clientset/versioned/fake/doc.go index 8e6fa905..8cc6f8cc 100644 --- a/api/generated/clientset/versioned/fake/doc.go +++ b/api/generated/clientset/versioned/fake/doc.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/fake/register.go b/api/generated/clientset/versioned/fake/register.go index 8dbb9971..26205193 100644 --- a/api/generated/clientset/versioned/fake/register.go +++ b/api/generated/clientset/versioned/fake/register.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/scheme/doc.go b/api/generated/clientset/versioned/scheme/doc.go index 81a94ca6..1d9c2aea 100644 --- a/api/generated/clientset/versioned/scheme/doc.go +++ b/api/generated/clientset/versioned/scheme/doc.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/scheme/register.go b/api/generated/clientset/versioned/scheme/register.go index a889a6bf..5f1a6c5d 100644 --- a/api/generated/clientset/versioned/scheme/register.go +++ b/api/generated/clientset/versioned/scheme/register.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/doc.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/doc.go index a8c5ba49..21e66db1 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/doc.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/doc.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/doc.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/doc.go index 2cb0c371..a9148e54 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/doc.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/doc.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevision.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevision.go index 0de0d829..d5def6e7 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevision.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevision.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevisionresources.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevisionresources.go index 15285f65..22ff9e2f 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevisionresources.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_packagerevisionresources.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porch_client.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porch_client.go index 11209b2b..950f2cfe 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porch_client.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porch_client.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porchpackage.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porchpackage.go index f4c0df9e..cfc0fb05 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porchpackage.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/fake/fake_porchpackage.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/generated_expansion.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/generated_expansion.go index d7722a27..fe83e229 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/generated_expansion.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevision.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevision.go index 404d0fc4..a01a3e6b 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevision.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevision.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevisionresources.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevisionresources.go index f5d91905..3cb86034 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevisionresources.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/packagerevisionresources.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/porch_client.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/porch_client.go index 3db8a589..2c2a0353 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/porch_client.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/porch_client.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/clientset/versioned/typed/porch/v1alpha1/porchpackage.go b/api/generated/clientset/versioned/typed/porch/v1alpha1/porchpackage.go index e0a40e42..1abf8476 100644 --- a/api/generated/clientset/versioned/typed/porch/v1alpha1/porchpackage.go +++ b/api/generated/clientset/versioned/typed/porch/v1alpha1/porchpackage.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/factory.go b/api/generated/informers/externalversions/factory.go index 056434d1..f4fd2a07 100644 --- a/api/generated/informers/externalversions/factory.go +++ b/api/generated/informers/externalversions/factory.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/generic.go b/api/generated/informers/externalversions/generic.go index b1bf2dab..34acf91f 100644 --- a/api/generated/informers/externalversions/generic.go +++ b/api/generated/informers/externalversions/generic.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/api/generated/informers/externalversions/internalinterfaces/factory_interfaces.go index 55bb9088..780df1d5 100644 --- a/api/generated/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/api/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/porch/interface.go b/api/generated/informers/externalversions/porch/interface.go index cbb41410..971c3213 100644 --- a/api/generated/informers/externalversions/porch/interface.go +++ b/api/generated/informers/externalversions/porch/interface.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/porch/v1alpha1/interface.go b/api/generated/informers/externalversions/porch/v1alpha1/interface.go index bf0ad9da..ec2d783e 100644 --- a/api/generated/informers/externalversions/porch/v1alpha1/interface.go +++ b/api/generated/informers/externalversions/porch/v1alpha1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/porch/v1alpha1/packagerevision.go b/api/generated/informers/externalversions/porch/v1alpha1/packagerevision.go index 8d91a896..08518499 100644 --- a/api/generated/informers/externalversions/porch/v1alpha1/packagerevision.go +++ b/api/generated/informers/externalversions/porch/v1alpha1/packagerevision.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/porch/v1alpha1/packagerevisionresources.go b/api/generated/informers/externalversions/porch/v1alpha1/packagerevisionresources.go index c53e97c6..f9c77375 100644 --- a/api/generated/informers/externalversions/porch/v1alpha1/packagerevisionresources.go +++ b/api/generated/informers/externalversions/porch/v1alpha1/packagerevisionresources.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/informers/externalversions/porch/v1alpha1/porchpackage.go b/api/generated/informers/externalversions/porch/v1alpha1/porchpackage.go index 9a73cd64..f3145349 100644 --- a/api/generated/informers/externalversions/porch/v1alpha1/porchpackage.go +++ b/api/generated/informers/externalversions/porch/v1alpha1/porchpackage.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/listers/porch/v1alpha1/expansion_generated.go b/api/generated/listers/porch/v1alpha1/expansion_generated.go index 0697e553..236ef1d5 100644 --- a/api/generated/listers/porch/v1alpha1/expansion_generated.go +++ b/api/generated/listers/porch/v1alpha1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/listers/porch/v1alpha1/packagerevision.go b/api/generated/listers/porch/v1alpha1/packagerevision.go index 4e5367f1..39655843 100644 --- a/api/generated/listers/porch/v1alpha1/packagerevision.go +++ b/api/generated/listers/porch/v1alpha1/packagerevision.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/listers/porch/v1alpha1/packagerevisionresources.go b/api/generated/listers/porch/v1alpha1/packagerevisionresources.go index 6674e6fb..8d76a8ff 100644 --- a/api/generated/listers/porch/v1alpha1/packagerevisionresources.go +++ b/api/generated/listers/porch/v1alpha1/packagerevisionresources.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/listers/porch/v1alpha1/porchpackage.go b/api/generated/listers/porch/v1alpha1/porchpackage.go index c4667444..19837949 100644 --- a/api/generated/listers/porch/v1alpha1/porchpackage.go +++ b/api/generated/listers/porch/v1alpha1/porchpackage.go @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index eb9a6477..6bc787e4 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 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. @@ -1158,7 +1158,7 @@ func schema_porch_api_porch_v1alpha1_PackageStatus(ref common.ReferenceCallback) Properties: map[string]spec.Schema{ "latestRevision": { SchemaProps: spec.SchemaProps{ - Description: "LatestRevision identifies the package revision that is the latest published package revision belonging to this package", + Description: "LatestRevision identifies the package revision that is the latest published package revision belonging to this package. Latest is determined by comparing packages that have valid semantic version as their revision. In case of git backend, branch tracking revisions like \"main\" and in case of oci backend, revisions tracking \"latest\" are not considered during selection of the latest revision.", Type: []string{"string"}, Format: "", }, diff --git a/api/porch/types.go b/api/porch/types.go index 3f041283..5e028b1d 100644 --- a/api/porch/types.go +++ b/api/porch/types.go @@ -526,6 +526,9 @@ type PackageSpec struct { // PackageStatus defines the observed state of Package type PackageStatus struct { // LatestRevision identifies the package revision that is the latest - // published package revision belonging to this package + // published package revision belonging to this package. Latest is determined by comparing + // packages that have valid semantic version as their revision. In case of git backend, branch tracking + // revisions like "main" and in case of oci backend, revisions tracking "latest" are not considered during + // selection of the latest revision. LatestRevision string `json:"latestRevision,omitempty"` } diff --git a/api/porch/v1alpha1/types.go b/api/porch/v1alpha1/types.go index 1d5dd3f3..1447ce4a 100644 --- a/api/porch/v1alpha1/types.go +++ b/api/porch/v1alpha1/types.go @@ -556,6 +556,9 @@ type PackageSpec struct { // PackageStatus defines the observed state of Package type PackageStatus struct { // LatestRevision identifies the package revision that is the latest - // published package revision belonging to this package + // published package revision belonging to this package. Latest is determined by comparing + // packages that have valid semantic version as their revision. In case of git backend, branch tracking + // revisions like "main" and in case of oci backend, revisions tracking "latest" are not considered during + // selection of the latest revision. LatestRevision string `json:"latestRevision,omitempty"` } diff --git a/api/porch/v1alpha1/zz_generated.conversion.go b/api/porch/v1alpha1/zz_generated.conversion.go index 11849652..4dce7740 100644 --- a/api/porch/v1alpha1/zz_generated.conversion.go +++ b/api/porch/v1alpha1/zz_generated.conversion.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/porch/v1alpha1/zz_generated.deepcopy.go b/api/porch/v1alpha1/zz_generated.deepcopy.go index 643b6b80..aa4d1689 100644 --- a/api/porch/v1alpha1/zz_generated.deepcopy.go +++ b/api/porch/v1alpha1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/porch/v1alpha1/zz_generated.defaults.go b/api/porch/v1alpha1/zz_generated.defaults.go index a4ed0202..bb55b733 100644 --- a/api/porch/v1alpha1/zz_generated.defaults.go +++ b/api/porch/v1alpha1/zz_generated.defaults.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/api/porch/zz_generated.deepcopy.go b/api/porch/zz_generated.deepcopy.go index 03c20e61..25baa1d4 100644 --- a/api/porch/zz_generated.deepcopy.go +++ b/api/porch/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023-2024 The kpt and Nephio Authors +// Copyright 2022-2025 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index f4c1c94e..9cdde840 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -2969,6 +2969,73 @@ func (t *PorchSuite) TestPackageRevisionFieldSelectors(ctx context.Context) { } } +func (t *PorchSuite) TestLatestVersionOnDelete(ctx context.Context) { + const ( + repositoryName = "test-latest-on-delete-repository" + workspacev1 = "test-latest-on-delete-workspace-v1" + workspacev2 = "test-latest-on-delete-workspace-v2" + packageName = "test-latest-on-delete-package" + ) + + t.RegisterMainGitRepositoryF(ctx, repositoryName) + + pr1 := t.CreatePackageDraftF(ctx, repositoryName, packageName, workspacev1) + + pr1.Spec.Lifecycle = porchapi.PackageRevisionLifecycleProposed + t.UpdateF(ctx, pr1) + + pr1.Spec.Lifecycle = porchapi.PackageRevisionLifecyclePublished + t.UpdateApprovalF(ctx, pr1, metav1.UpdateOptions{}) + + //After approval of the first revision, the package should be labeled as latest + t.MustHaveLabels(ctx, pr1.Name, map[string]string{ + porchapi.LatestPackageRevisionKey: porchapi.LatestPackageRevisionValue, + }) + + pr2 := t.CreatePackageDraftF(ctx, repositoryName, packageName, workspacev2) + + pr2.Spec.Lifecycle = porchapi.PackageRevisionLifecycleProposed + t.UpdateF(ctx, pr2) + + pr2.Spec.Lifecycle = porchapi.PackageRevisionLifecyclePublished + t.UpdateApprovalF(ctx, pr2, metav1.UpdateOptions{}) + + //After approval of the second revision, the latest label should migrate to the + //v2 packageRevision + t.MustNotHaveLabels(ctx, pr1.Name, []string{ + porchapi.LatestPackageRevisionKey, + }) + + t.MustHaveLabels(ctx, pr2.Name, map[string]string{ + porchapi.LatestPackageRevisionKey: porchapi.LatestPackageRevisionValue, + }) + + t.GetF(ctx, client.ObjectKeyFromObject(pr2), pr2) + + pr2.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed + t.UpdateF(ctx, pr2) + + t.DeleteF(ctx, pr2) + //After deletion of the v2 pacakgeRevision, + //the label should migrate back to the v2 packageRevision + t.MustHaveLabels(ctx, pr1.Name, map[string]string{ + porchapi.LatestPackageRevisionKey: porchapi.LatestPackageRevisionValue, + }) + + t.GetF(ctx, client.ObjectKeyFromObject(pr1), pr1) + + pr1.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed + t.UpdateF(ctx, pr1) + + t.DeleteF(ctx, pr1) + //After the removal of all versioned packageRevisions, the main branch + //packageRevision should still not get the latest label. + mainPr := t.GetPackageRevision(ctx, repositoryName, packageName, "main") + t.MustNotHaveLabels(ctx, mainPr.Name, []string{ + porchapi.LatestPackageRevisionKey, + }) +} + func (t *PorchSuite) TestRepositoryModify(ctx context.Context) { const ( repositoryName = "repo-modify-test" @@ -3051,4 +3118,5 @@ func (t *PorchSuite) TestRepositoryModify(ctx context.Context) { } break } + } diff --git a/test/e2e/suite_utils.go b/test/e2e/suite_utils.go index d1c5c53c..6068c9b7 100644 --- a/test/e2e/suite_utils.go +++ b/test/e2e/suite_utils.go @@ -145,6 +145,41 @@ func (t *TestSuite) ValidateLabelsAndAnnos(ctx context.Context, name string, lab } } +func (t *TestSuite) MustHaveLabels(ctx context.Context, name string, labels map[string]string) { + t.Helper() + var pr porchapi.PackageRevision + t.GetF(ctx, client.ObjectKey{ + Namespace: t.Namespace, + Name: name, + }, &pr) + + for labelKey, labelValue := range labels { + actualValue, ok := pr.Labels[labelKey] + if !ok { + t.Errorf("Expected PR %s to have label %s, but didn't find it", pr.Name, labelKey) + } + if actualValue != labelValue { + t.Errorf("Expected PR %s to have label %s value %s but got %s", pr.Name, labelKey, labelValue, actualValue) + } + } +} + +func (t *TestSuite) MustNotHaveLabels(ctx context.Context, name string, labels []string) { + t.Helper() + var pr porchapi.PackageRevision + t.GetF(ctx, client.ObjectKey{ + Namespace: t.Namespace, + Name: name, + }, &pr) + + for _, label := range labels { + _, ok := pr.Labels[label] + if ok { + t.Errorf("Expected PR %s not to have label %s, but found it", pr.Name, label) + } + } +} + func (t *TestSuite) RegisterGitRepositoryF(ctx context.Context, repo, name, directory string, opts ...RepositoryOption) { t.Helper() config := GitConfig{ @@ -508,6 +543,25 @@ func (t *TestSuite) WaitUntilPackageRevisionResourcesExists( return foundPrr } +func (t *TestSuite) GetPackageRevision(ctx context.Context, repository string, pkgName string, revision string) *porchapi.PackageRevision { + t.Helper() + var prList porchapi.PackageRevisionList + selector := client.MatchingFields(fields.Set{ + "spec.repository": repository, + "spec.packageName": pkgName, + "spec.revision": revision, + }) + t.ListF(ctx, &prList, selector, client.InNamespace(t.Namespace)) + + if len(prList.Items) == 0 { + t.Fatalf("PackageRevision object wasn't found for package revision %v/%v/%v", repository, pkgName, revision) + } + if len(prList.Items) > 1 { + t.Fatalf("Multiple PackageRevision objects were found for package revision %v/%v/%v", repository, pkgName, revision) + } + return &prList.Items[0] +} + func (t *TestSuite) GetContentsOfPackageRevision(ctx context.Context, repository string, pkgName string, revision string) map[string]string { t.Helper()