Skip to content

Commit

Permalink
Merge branch 'nephio-project:main' into pv-pipeline-readiness-gates
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMcDermott authored Dec 12, 2024
2 parents 9828161 + 0b92c55 commit 12102c7
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 143 deletions.
1 change: 0 additions & 1 deletion api/porch/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ type NameMeta struct {
Namespace string `json:"namespace,omitempty"`
}


// PackageRevisionResources
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
3 changes: 1 addition & 2 deletions api/porch/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ type PackageRevisionResourcesStatus struct {
RenderStatus RenderStatus `json:"renderStatus,omitempty"`
}


// Package
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -559,4 +558,4 @@ type PackageStatus struct {
// LatestRevision identifies the package revision that is the latest
// published package revision belonging to this package
LatestRevision string `json:"latestRevision,omitempty"`
}
}
3 changes: 1 addition & 2 deletions api/porch/v1alpha1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func LifecycleIsPublished(lifecycle PackageRevisionLifecycle) bool {
return lifecycle == PackageRevisionLifecyclePublished || lifecycle == PackageRevisionLifecycleDeletionProposed
}


// Check ReadinessGates checks if the package has met all readiness gates
func PackageRevisionIsReady(readinessGates []ReadinessGate, conditions []Condition) bool {
// Index our conditions
Expand All @@ -38,4 +37,4 @@ func PackageRevisionIsReady(readinessGates []ReadinessGate, conditions []Conditi
}

return true
}
}
6 changes: 3 additions & 3 deletions api/porchconfig/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
type RepositoryContent string

const (
RepositoryContentPackage RepositoryContent = "Package"
RepositoryContentPackage RepositoryContent = "Package"
)

// RepositorySpec defines the desired state of Repository
Expand All @@ -60,12 +60,12 @@ type RepositorySpec struct {
Deployment bool `json:"deployment,omitempty"`
// Type of the repository (i.e. git, OCI)
Type RepositoryType `json:"type,omitempty"`
// The Content field is deprecated, please do not specify it in new manifests.
// The Content field is deprecated, please do not specify it in new manifests.
// For partial backward compatibility it is still recognized, but its only valid value is "Package", and if not specified its default value is also "Package".
// +kubebuilder:validation:XValidation:message="The 'content' field is deprecated, its only valid value is 'Package'",rule="self == '' || self == 'Package'"
// +kubebuilder:default="Package"
Content *RepositoryContent `json:"content,omitempty"`

// Git repository details. Required if `type` is `git`. Ignored if `type` is not `git`.
Git *GitRepository `json:"git,omitempty"`
// OCI repository details. Required if `type` is `oci`. Ignored if `type` is not `oci`.
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/fake/credentialresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package fake

import (
"context"
"github.com/nephio-project/porch/pkg/repository"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/nephio-project/porch/pkg/repository"
)

type credential struct {
Expand All @@ -36,7 +36,7 @@ func (c *credential) ToAuthMethod() transport.AuthMethod {
panic("unimplemented")
}

type CredentialResolver struct{
type CredentialResolver struct {
cabundle string
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/memory/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestPublishedLatest(t *testing.T) {
if err := update.UpdateLifecycle(ctx, api.PackageRevisionLifecyclePublished); err != nil {
t.Fatalf("UpdateLifecycle failed; %v", err)
}
closed, err := update.Close(ctx, "")
closed, err := cachedRepo.ClosePackageRevisionDraft(ctx, update, "")
if err != nil {
t.Fatalf("Close failed: %v", err)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestDeletePublishedMain(t *testing.T) {
if err := update.UpdateLifecycle(ctx, api.PackageRevisionLifecyclePublished); err != nil {
t.Fatalf("UpdateLifecycle failed; %v", err)
}
closed, err := update.Close(ctx, "")
closed, err := cachedRepo.ClosePackageRevisionDraft(ctx, update, "")
if err != nil {
t.Fatalf("Close failed: %v", err)
}
Expand Down
71 changes: 0 additions & 71 deletions pkg/cache/memory/draft.go

This file was deleted.

55 changes: 41 additions & 14 deletions pkg/cache/memory/repository.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022,2024 The kpt and Nephio Authors
// Copyright 2022, 2024 The kpt and Nephio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -168,29 +168,56 @@ func (r *cachedRepository) getCachedPackages(ctx context.Context, forceRefresh b
}

func (r *cachedRepository) CreatePackageRevision(ctx context.Context, obj *v1alpha1.PackageRevision) (repository.PackageRevisionDraft, error) {
created, err := r.repo.CreatePackageRevision(ctx, obj)
return r.repo.CreatePackageRevision(ctx, obj)
}

func (r *cachedRepository) ClosePackageRevisionDraft(ctx context.Context, prd repository.PackageRevisionDraft, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "cachedRepository::ClosePackageRevisionDraft", trace.WithAttributes())
defer span.End()

v, err := r.Version(ctx)
if err != nil {
return nil, err
}

if v != r.lastVersion {
_, _, err = r.refreshAllCachedPackages(ctx)
if err != nil {
return nil, err
}
}

revisions, err := r.ListPackageRevisions(ctx, repository.ListPackageRevisionFilter{
Package: prd.GetName(),
})
if err != nil {
return nil, err
}

return &cachedDraft{
PackageRevisionDraft: created,
cache: r,
}, nil
var publishedRevisions []string
for _, rev := range revisions {
if v1alpha1.LifecycleIsPublished(rev.Lifecycle()) {
publishedRevisions = append(publishedRevisions, rev.Key().Revision)
}
}

nextVersion, err := repository.NextRevisionNumber(publishedRevisions)
if err != nil {
return nil, err
}

if closed, err := r.repo.ClosePackageRevisionDraft(ctx, prd, nextVersion); err != nil {
return nil, err
} else {
return r.update(ctx, closed)
}
}

func (r *cachedRepository) UpdatePackageRevision(ctx context.Context, old repository.PackageRevision) (repository.PackageRevisionDraft, error) {
// Unwrap
unwrapped := old.(*cachedPackageRevision).PackageRevision
created, err := r.repo.UpdatePackageRevision(ctx, unwrapped)
if err != nil {
return nil, err
}

return &cachedDraft{
PackageRevisionDraft: created,
cache: r,
}, nil
return r.repo.UpdatePackageRevision(ctx, unwrapped)
}

func (r *cachedRepository) update(ctx context.Context, updated repository.PackageRevision) (*cachedPackageRevision, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/commands/rpkg/approve/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ func TestCmd(t *testing.T) {
Spec: porchapi.PackageRevisionSpec{
Lifecycle: porchapi.PackageRevisionLifecycleProposed,
RepositoryName: repoName,
ReadinessGates: []porchapi.ReadinessGate {
ReadinessGates: []porchapi.ReadinessGate{
{
ConditionType: "nephio.org.Specializer.specialize",
},
},
},
Status: porchapi.PackageRevisionStatus{
Conditions: []porchapi.Condition {
Conditions: []porchapi.Condition{
{
Type: "nephio.org.Specializer.specialize",
Type: "nephio.org.Specializer.specialize",
Status: "False",
},
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022,2024 The kpt and Nephio Authors
// Copyright 2022, 2024 The kpt and Nephio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -184,7 +184,7 @@ func (cad *cadEngine) CreatePackageRevision(ctx context.Context, repositoryObj *
}

// Updates are done.
repoPkgRev, err := draft.Close(ctx, "")
repoPkgRev, err := repo.ClosePackageRevisionDraft(ctx, draft, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -312,7 +312,7 @@ func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, version string,
}

// Updates are done.
repoPkgRev, err = draft.Close(ctx, version)
repoPkgRev, err = repo.ClosePackageRevisionDraft(ctx, draft, version)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -512,7 +512,7 @@ func (cad *cadEngine) UpdatePackageResources(ctx context.Context, repositoryObj
return nil, renderStatus, err
}
// No lifecycle change when updating package resources; updates are done.
repoPkgRev, err := draft.Close(ctx, "")
repoPkgRev, err := repo.ClosePackageRevisionDraft(ctx, draft, "")
if err != nil {
return nil, renderStatus, err
}
Expand Down Expand Up @@ -565,7 +565,7 @@ func (cad *cadEngine) RecloneAndReplay(ctx context.Context, parentPR repository.
return nil, err
}

repoPkgRev, err := draft.Close(ctx, version)
repoPkgRev, err := repo.ClosePackageRevisionDraft(ctx, draft, version)

if err != nil {
return nil, err
Expand Down
10 changes: 1 addition & 9 deletions pkg/git/draft.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The kpt and Nephio Authors
// Copyright 2022, 2024 The kpt and Nephio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,14 +63,6 @@ func (d *gitPackageRevisionDraft) UpdateLifecycle(ctx context.Context, new v1alp
return nil
}

// Finish round of updates.
func (d *gitPackageRevisionDraft) Close(ctx context.Context, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "gitPackageDraft::Close", trace.WithAttributes())
defer span.End()

return d.parent.CloseDraft(ctx, version, d)
}

func (d *gitPackageRevisionDraft) GetName() string {
packageDirectory := d.parent.directory
packageName := strings.TrimPrefix(d.path, packageDirectory+"/")
Expand Down
7 changes: 6 additions & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,15 @@ func (r *gitRepository) UpdateDraftResources(ctx context.Context, draft *gitPack
return nil
}

func (r *gitRepository) CloseDraft(ctx context.Context, version string, d *gitPackageRevisionDraft) (*gitPackageRevision, error) {
func (r *gitRepository) ClosePackageRevisionDraft(ctx context.Context, prd repository.PackageRevisionDraft, version string) (repository.PackageRevision, error) {
ctx, span := tracer.Start(ctx, "GitRepository::UpdateLifecycle", trace.WithAttributes())
defer span.End()

r.mutex.Lock()
defer r.mutex.Unlock()

d := prd.(*gitPackageRevisionDraft)

refSpecs := newPushRefSpecBuilder()
draftBranch := createDraftName(d.path, d.workspaceName)
proposedBranch := createProposedName(d.path, d.workspaceName)
Expand Down
Loading

0 comments on commit 12102c7

Please sign in to comment.