Skip to content

Commit 0b4348f

Browse files
authored
Make imports of the Porch API consistent across the go codebase (kptdev#340)
* Refactor install into v1alpha1 versioned api directroy Signed-off-by: liamfallon <liam.fallon@est.tech> * Removed unversioned types.go and docs.go Signed-off-by: liamfallon <liam.fallon@est.tech> * Refactored code generation to be in the api/porch directory Signed-off-by: liamfallon <liam.fallon@est.tech> * Revert generation artifact for Repository CRD Signed-off-by: liamfallon <liam.fallon@est.tech> * Generation cleaned up and yaml descriptions of CRDs and API resources being generated Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix linter errors Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix path to CRD yaml files in deployment builder Signed-off-by: liamfallon <liam.fallon@est.tech> * revert changes until API v2 Signed-off-by: liamfallon <liam.fallon@est.tech> * Rebased to main Signed-off-by: liamfallon <liam.fallon@est.tech> * Make Porch API imports consistent across go files Signed-off-by: liamfallon <liam.fallon@est.tech> --------- Signed-off-by: liamfallon <liam.fallon@est.tech>
1 parent 47a232b commit 0b4348f

77 files changed

Lines changed: 876 additions & 880 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/kpt/util/porch/approval.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ import (
1717
"context"
1818
"fmt"
1919

20-
"github.com/nephio-project/porch/api/porch/v1alpha1"
20+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2121
"sigs.k8s.io/controller-runtime/pkg/client"
2222
)
2323

2424
const ApproveErrorOut = "cannot change approval from %s to %s"
2525

26-
func UpdatePackageRevisionApproval(ctx context.Context, client client.Client, pr *v1alpha1.PackageRevision, new v1alpha1.PackageRevisionLifecycle) error {
26+
func UpdatePackageRevisionApproval(ctx context.Context, client client.Client, pr *porchapi.PackageRevision, new porchapi.PackageRevisionLifecycle) error {
2727

2828
switch lifecycle := pr.Spec.Lifecycle; lifecycle {
29-
case v1alpha1.PackageRevisionLifecycleProposed:
29+
case porchapi.PackageRevisionLifecycleProposed:
3030
// Approve - change the package revision kind to 'final'.
31-
if new != v1alpha1.PackageRevisionLifecyclePublished && new != v1alpha1.PackageRevisionLifecycleDraft {
31+
if new != porchapi.PackageRevisionLifecyclePublished && new != porchapi.PackageRevisionLifecycleDraft {
3232
return fmt.Errorf(ApproveErrorOut, lifecycle, new)
3333
}
34-
case v1alpha1.PackageRevisionLifecycleDeletionProposed:
35-
if new != v1alpha1.PackageRevisionLifecyclePublished {
34+
case porchapi.PackageRevisionLifecycleDeletionProposed:
35+
if new != porchapi.PackageRevisionLifecyclePublished {
3636
return fmt.Errorf(ApproveErrorOut, lifecycle, new)
3737
}
3838
case new:

pkg/cache/crcache/cache_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/google/go-cmp/cmp"
27-
api "github.com/nephio-project/porch/api/porch/v1alpha1"
27+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2828
"github.com/nephio-project/porch/api/porchconfig/v1alpha1"
2929
"github.com/nephio-project/porch/pkg/cache/crcache/meta"
3030
fakemeta "github.com/nephio-project/porch/pkg/cache/crcache/meta/fake"
@@ -64,9 +64,9 @@ func TestLatestPackages(t *testing.T) {
6464
t.Errorf("didn't expect error, but got %v", err)
6565
}
6666

67-
if latest, ok := rev.Labels[api.LatestPackageRevisionKey]; ok {
68-
if got, want := latest, api.LatestPackageRevisionValue; got != want {
69-
t.Errorf("%s label value: got %q, want %q", api.LatestPackageRevisionKey, got, want)
67+
if latest, ok := rev.Labels[porchapi.LatestPackageRevisionKey]; ok {
68+
if got, want := latest, porchapi.LatestPackageRevisionValue; got != want {
69+
t.Errorf("%s label value: got %q, want %q", porchapi.LatestPackageRevisionKey, got, want)
7070
continue
7171
}
7272

@@ -110,15 +110,15 @@ func TestPublishedLatest(t *testing.T) {
110110

111111
bucket := revisions[0]
112112
// Expect draft package
113-
if got, want := bucket.Lifecycle(ctx), api.PackageRevisionLifecycleDraft; got != want {
113+
if got, want := bucket.Lifecycle(ctx), porchapi.PackageRevisionLifecycleDraft; got != want {
114114
t.Fatalf("Bucket package lifecycle: got %s, want %s", got, want)
115115
}
116116

117117
update, err := cachedRepo.UpdatePackageRevision(ctx, bucket)
118118
if err != nil {
119119
t.Fatalf("UpdatePackaeg(%s) failed: %v", bucket.Key(), err)
120120
}
121-
if err := update.UpdateLifecycle(ctx, api.PackageRevisionLifecyclePublished); err != nil {
121+
if err := update.UpdateLifecycle(ctx, porchapi.PackageRevisionLifecyclePublished); err != nil {
122122
t.Fatalf("UpdateLifecycle failed; %v", err)
123123
}
124124
closed, err := cachedRepo.ClosePackageRevisionDraft(ctx, update, 0)
@@ -129,9 +129,9 @@ func TestPublishedLatest(t *testing.T) {
129129
if err != nil {
130130
t.Errorf("didn't expect error, but got %v", err)
131131
}
132-
if got, ok := resource.Labels[api.LatestPackageRevisionKey]; !ok {
133-
t.Errorf("Label %s not found as expected", api.LatestPackageRevisionKey)
134-
} else if want := api.LatestPackageRevisionValue; got != want {
132+
if got, ok := resource.Labels[porchapi.LatestPackageRevisionKey]; !ok {
133+
t.Errorf("Label %s not found as expected", porchapi.LatestPackageRevisionKey)
134+
} else if want := porchapi.LatestPackageRevisionValue; got != want {
135135
t.Errorf("Latest label: got %s, want %s", got, want)
136136
}
137137
}
@@ -161,15 +161,15 @@ func TestDeletePublishedMain(t *testing.T) {
161161

162162
bucket := revisions[0]
163163
// Expect draft package
164-
if got, want := bucket.Lifecycle(ctx), api.PackageRevisionLifecycleDraft; got != want {
164+
if got, want := bucket.Lifecycle(ctx), porchapi.PackageRevisionLifecycleDraft; got != want {
165165
t.Fatalf("Bucket package lifecycle: got %s, want %s", got, want)
166166
}
167167

168168
update, err := cachedRepo.UpdatePackageRevision(ctx, bucket)
169169
if err != nil {
170170
t.Fatalf("UpdatePackage(%s) failed: %v", bucket.Key(), err)
171171
}
172-
if err := update.UpdateLifecycle(ctx, api.PackageRevisionLifecyclePublished); err != nil {
172+
if err := update.UpdateLifecycle(ctx, porchapi.PackageRevisionLifecyclePublished); err != nil {
173173
t.Fatalf("UpdateLifecycle failed; %v", err)
174174
}
175175
closed, err := cachedRepo.ClosePackageRevisionDraft(ctx, update, 0)
@@ -190,7 +190,7 @@ func TestDeletePublishedMain(t *testing.T) {
190190
WorkspaceName: "main",
191191
Revision: -1,
192192
},
193-
Lifecycles: []api.PackageRevisionLifecycle{api.PackageRevisionLifecyclePublished},
193+
Lifecycles: []porchapi.PackageRevisionLifecycle{porchapi.PackageRevisionLifecyclePublished},
194194
})
195195
if err != nil {
196196
t.Fatalf("ListPackageRevisions failed: %v", err)
@@ -203,11 +203,11 @@ func TestDeletePublishedMain(t *testing.T) {
203203

204204
approvedBucket := publishedRevisions[0]
205205

206-
if got, want := approvedBucket.Lifecycle(ctx), api.PackageRevisionLifecyclePublished; got != want {
206+
if got, want := approvedBucket.Lifecycle(ctx), porchapi.PackageRevisionLifecyclePublished; got != want {
207207
t.Fatalf("Approved Bucket package lifecycle: got %s, want %s", got, want)
208208
}
209209

210-
err = approvedBucket.UpdateLifecycle(ctx, api.PackageRevisionLifecycleDeletionProposed)
210+
err = approvedBucket.UpdateLifecycle(ctx, porchapi.PackageRevisionLifecycleDeletionProposed)
211211
if err != nil {
212212
t.Fatalf("Deletion proposal for approved Bucket failed; %v", err)
213213
}
@@ -225,7 +225,7 @@ func TestDeletePublishedMain(t *testing.T) {
225225
WorkspaceName: "main",
226226
Revision: -1,
227227
},
228-
Lifecycles: []api.PackageRevisionLifecycle{api.PackageRevisionLifecyclePublished},
228+
Lifecycles: []porchapi.PackageRevisionLifecycle{porchapi.PackageRevisionLifecyclePublished},
229229
})
230230

231231
if err != nil {
@@ -276,9 +276,9 @@ func openRepositoryFromArchive(t *testing.T, ctx context.Context, testPath, name
276276
metadataStore: metadataStore,
277277
options: cachetypes.CacheOptions{
278278
ExternalRepoOptions: externalrepotypes.ExternalRepoOptions{
279-
LocalDirectory: t.TempDir(),
280-
UseUserDefinedCaBundle: true,
281-
CredentialResolver: &fakecache.CredentialResolver{},
279+
LocalDirectory: t.TempDir(),
280+
UseUserDefinedCaBundle: true,
281+
CredentialResolver: &fakecache.CredentialResolver{},
282282
RepoOperationRetryAttempts: 3,
283283
},
284284
CoreClient: fakeClient,

pkg/cache/crcache/packagerevision.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"sync"
2020

21-
api "github.com/nephio-project/porch/api/porch/v1alpha1"
21+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2222
"github.com/nephio-project/porch/pkg/cache/crcache/meta"
2323
"github.com/nephio-project/porch/pkg/repository"
2424
"github.com/nephio-project/porch/pkg/util"
@@ -54,7 +54,7 @@ func (c *cachedPackageRevision) UID() types.UID {
5454
return util.GenerateUid("packagerevision:", c.KubeObjectNamespace(), c.KubeObjectName())
5555
}
5656

57-
func (c *cachedPackageRevision) GetPackageRevision(ctx context.Context) (*api.PackageRevision, error) {
57+
func (c *cachedPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi.PackageRevision, error) {
5858
ctx, span := tracer.Start(ctx, "cachedPackageRevision::GetPackageRevision", trace.WithAttributes())
5959
defer span.End()
6060

@@ -77,7 +77,7 @@ func (c *cachedPackageRevision) GetPackageRevision(ctx context.Context) (*api.Pa
7777
for k, v := range apiPR.Labels {
7878
labels[k] = v
7979
}
80-
labels[api.LatestPackageRevisionKey] = api.LatestPackageRevisionValue
80+
labels[porchapi.LatestPackageRevisionKey] = porchapi.LatestPackageRevisionValue
8181
apiPR.Labels = labels
8282
}
8383

pkg/cache/crcache/repository.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
stdSync "sync"
2121
"time"
2222

23-
"github.com/nephio-project/porch/api/porch/v1alpha1"
23+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2424
configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1"
2525
"github.com/nephio-project/porch/pkg/cache/crcache/meta"
2626
"github.com/nephio-project/porch/pkg/cache/sync"
@@ -197,7 +197,7 @@ func (r *cachedRepository) getCachedPackages(ctx context.Context, forceRefresh b
197197
return packages, packageRevisions, err
198198
}
199199

200-
func (r *cachedRepository) CreatePackageRevisionDraft(ctx context.Context, obj *v1alpha1.PackageRevision) (repository.PackageRevisionDraft, error) {
200+
func (r *cachedRepository) CreatePackageRevisionDraft(ctx context.Context, obj *porchapi.PackageRevision) (repository.PackageRevisionDraft, error) {
201201
return r.repo.CreatePackageRevisionDraft(ctx, obj)
202202
}
203203

@@ -233,7 +233,7 @@ func (r *cachedRepository) ClosePackageRevisionDraft(ctx context.Context, prd re
233233

234234
highestRevision := 0
235235
for _, rev := range revisions {
236-
if v1alpha1.LifecycleIsPublished(rev.Lifecycle(ctx)) && rev.Key().Revision > highestRevision {
236+
if porchapi.LifecycleIsPublished(rev.Lifecycle(ctx)) && rev.Key().Revision > highestRevision {
237237
highestRevision = rev.Key().Revision
238238
}
239239
}
@@ -286,7 +286,7 @@ func (r *cachedRepository) update(ctx context.Context, updated repository.Packag
286286
}
287287

288288
r.mutex.Lock()
289-
if v1alpha1.LifecycleIsPublished(updated.Lifecycle(ctx)) {
289+
if porchapi.LifecycleIsPublished(updated.Lifecycle(ctx)) {
290290
prevKey := updated.Key()
291291
prevKey.Revision = 0 // Drafts always have revision of 0
292292
delete(r.cachedPackageRevisions, prevKey)
@@ -303,7 +303,7 @@ func (r *cachedRepository) update(ctx context.Context, updated repository.Packag
303303
r.mutex.Unlock()
304304

305305
// Create the main package revision
306-
if v1alpha1.LifecycleIsPublished(updated.Lifecycle(ctx)) {
306+
if porchapi.LifecycleIsPublished(updated.Lifecycle(ctx)) {
307307
updatedMain := updated.ToMainPackageRevision(ctx)
308308
err := r.createMainPackageRevision(ctx, updatedMain)
309309
if err != nil {
@@ -445,7 +445,7 @@ func (r *cachedRepository) ListPackages(ctx context.Context, filter repository.L
445445
return packages, nil
446446
}
447447

448-
func (r *cachedRepository) CreatePackage(ctx context.Context, obj *v1alpha1.PorchPackage) (repository.Package, error) {
448+
func (r *cachedRepository) CreatePackage(ctx context.Context, obj *porchapi.PorchPackage) (repository.Package, error) {
449449
klog.Infoln("cachedRepository::CreatePackage")
450450
return r.repo.CreatePackage(ctx, obj)
451451
}

pkg/cache/crcache/repository_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121
"time"
2222

23-
porchtypes "github.com/nephio-project/porch/api/porch/v1alpha1"
23+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2424
configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1"
2525
"github.com/nephio-project/porch/pkg/cache/testutil"
2626
cachetypes "github.com/nephio-project/porch/pkg/cache/types"
@@ -128,7 +128,7 @@ func TestCachedRepoRefresh(t *testing.T) {
128128
cr.flush()
129129
assert.True(t, cr.cachedPackageRevisions == nil)
130130

131-
prMeta := porchtypes.PackageRevision{}
131+
prMeta := porchapi.PackageRevision{}
132132

133133
repoCreatePRDCall := mockRepo.EXPECT().CreatePackageRevisionDraft(mock.Anything, mock.Anything).Return(nil, errors.New("create draft error")).Maybe()
134134
_, err = cr.CreatePackageRevisionDraft(context.TODO(), &prMeta)

pkg/cache/crcache/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"sort"
2020
"strings"
2121

22-
"github.com/nephio-project/porch/api/porch/v1alpha1"
22+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2323
"github.com/nephio-project/porch/pkg/repository"
2424
)
2525

@@ -36,7 +36,7 @@ func identifyLatestRevisions(ctx context.Context, result map[repository.PackageR
3636

3737
// Check if the current package revision is more recent than the one seen so far.
3838
// Only consider Published packages
39-
if !v1alpha1.LifecycleIsPublished(current.Lifecycle(ctx)) {
39+
if !porchapi.LifecycleIsPublished(current.Lifecycle(ctx)) {
4040
continue
4141
}
4242

pkg/cache/dbcache/dbpackage.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"database/sql"
2020
"time"
2121

22-
"github.com/nephio-project/porch/api/porch/v1alpha1"
22+
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
2323
"github.com/nephio-project/porch/pkg/repository"
2424
"github.com/nephio-project/porch/pkg/util"
2525
"go.opentelemetry.io/otel/trace"
@@ -34,7 +34,7 @@ type dbPackage struct {
3434
repo *dbRepository
3535
pkgKey repository.PackageKey
3636
meta metav1.ObjectMeta
37-
spec *v1alpha1.PackageSpec
37+
spec *porchapi.PackageSpec
3838
updated time.Time
3939
updatedBy string
4040
}
@@ -71,24 +71,24 @@ func (p *dbPackage) savePackage(ctx context.Context) (*dbPackage, error) {
7171
Namespace: p.KubeObjectNamespace(),
7272
}
7373

74-
p.spec = &v1alpha1.PackageSpec{
74+
p.spec = &porchapi.PackageSpec{
7575
PackageName: p.pkgKey.Package,
7676
RepositoryName: p.Key().RKey().Name,
7777
}
7878

7979
return p, pkgWriteToDB(ctx, p)
8080
}
8181

82-
func (p *dbPackage) GetPackage(ctx context.Context) *v1alpha1.PorchPackage {
82+
func (p *dbPackage) GetPackage(ctx context.Context) *porchapi.PorchPackage {
8383
_, span := tracer.Start(ctx, "dbPackage:GetPackage", trace.WithAttributes())
8484
defer span.End()
8585

8686
key := p.Key()
8787

88-
return &v1alpha1.PorchPackage{
88+
return &porchapi.PorchPackage{
8989
TypeMeta: metav1.TypeMeta{
9090
Kind: "PorchPackage",
91-
APIVersion: v1alpha1.SchemeGroupVersion.Identifier(),
91+
APIVersion: porchapi.SchemeGroupVersion.Identifier(),
9292
},
9393
ObjectMeta: metav1.ObjectMeta{
9494
Name: p.KubeObjectName(),
@@ -99,11 +99,11 @@ func (p *dbPackage) GetPackage(ctx context.Context) *v1alpha1.PorchPackage {
9999
Time: p.updated,
100100
},
101101
},
102-
Spec: v1alpha1.PackageSpec{
102+
Spec: porchapi.PackageSpec{
103103
PackageName: key.Package,
104104
RepositoryName: key.RKey().Name,
105105
},
106-
Status: v1alpha1.PackageStatus{
106+
Status: porchapi.PackageStatus{
107107
LatestRevision: p.GetLatestRevision(ctx),
108108
},
109109
}

0 commit comments

Comments
 (0)