repository

package
v1.5.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package repository defines Porch generic repository interfaces and provides utility functions for repositories.

Index

Constants

View Source
const LocalUpdateDir = "kpt-pkg-update-*"

Variables

This section is empty.

Functions

func AnyBlockOwnerDeletionSet

func AnyBlockOwnerDeletionSet(obj metav1.ObjectMeta) bool

AnyBlockOwnerDeletionSet checks whether there are any ownerReferences in the Object which have blockOwnerDeletion enabled (meaning either nil or true).

func ComposePkgObjName

func ComposePkgObjName(key PackageKey) string

func ComposePkgRevObjName

func ComposePkgRevObjName(key PackageRevisionKey) string

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error indicates that a package or resource was not found. This is used to handle cases where a package exists in cache but not in external repository.

func K8SName2PkgName

func K8SName2PkgName(k8sName string) string

func K8SName2PkgRevWSName

func K8SName2PkgRevWSName(k8sNamePkg, k8sName string) string

func KptUpstreamLock2APIUpstreamLock

func KptUpstreamLock2APIUpstreamLock(kptLock kptfilev1.Locator) *porchapi.Locator

func KptUpstreamLock2KptUpstream

func KptUpstreamLock2KptUpstream(kptLock kptfilev1.Locator) kptfilev1.Upstream

func PathsOverlap

func PathsOverlap(path1, path2 string) bool

PathsOverlap checks if two package paths would create a nesting conflict

func PrSlice2Map

func PrSlice2Map(prSlice []PackageRevision) map[PackageRevisionKey]PackageRevision

func Revision2Int

func Revision2Int(revisionStr string) int

func Revision2Str

func Revision2Str(revision int) string

func SplitPackagePathName

func SplitPackagePathName(fullpath string) (path, name string)

func ToAPIConditions

func ToAPIConditions(kf kptfilev1.KptFile) []porchapi.Condition

func ToAPIReadinessGates

func ToAPIReadinessGates(kf kptfilev1.KptFile) []porchapi.ReadinessGate

func UpsertAPICondition

func UpsertAPICondition(conditions []porchapi.Condition, condition porchapi.Condition) []porchapi.Condition

func ValidatePackagePathOverlap

func ValidatePackagePathOverlap(newPr *porchapi.PackageRevision, existingRevs []PackageRevision) error

ValidatePackagePathOverlap checks for path conflicts with existing packages

func WritePackage

func WritePackage(t *testing.T, packageDir string, contents PackageResources)

Types

type Credential

type Credential interface {
	Valid() bool
	ToAuthMethod() transport.AuthMethod
	ToString() string
}

type CredentialResolver

type CredentialResolver interface {
	ResolveCredential(ctx context.Context, namespace, name string) (Credential, error)
}

type DefaultPackageUpdater

type DefaultPackageUpdater struct{}

DefaultPackageUpdater implements packageUpdater interface.

func (*DefaultPackageUpdater) Update

func (m *DefaultPackageUpdater) Update(
	ctx context.Context,
	localResources,
	originalResources,
	upstreamResources PackageResources,
	strategy string) (updatedResources PackageResources, err error)

type ListPackageFilter

type ListPackageFilter struct {
	Key PackageKey
}

ListPackageFilter is a predicate for filtering Package objects; only matching Package objects will be returned.

func (*ListPackageFilter) Matches

func (f *ListPackageFilter) Matches(p Package) bool

Matches returns true if the provided Package satisfies the conditions in the filter.

type ListPackageRevisionFilter

type ListPackageRevisionFilter struct {
	Key PackageRevisionKey

	// Lifecycle matches the spec.lifecycle of the package
	Lifecycles []porchapi.PackageRevisionLifecycle

	// KptfileLabels matches labels specified in the Kptfile
	KptfileLabels map[string]string

	Label labels.Selector
}

ListPackageRevisionFilter is a predicate for filtering PackageRevision objects; only matching PackageRevision objects will be returned.

func (*ListPackageRevisionFilter) FilteredRepository

func (f *ListPackageRevisionFilter) FilteredRepository() string

func (*ListPackageRevisionFilter) Matches

Matches returns true if the provided PackageRevision satisfies the conditions in the filter.

func (*ListPackageRevisionFilter) MatchesLabels

MatchesLabels returns true if the filter either:

  • does not filter on labels (nil Label field), OR
  • matches on labels of the provided PackageRevision

func (*ListPackageRevisionFilter) MatchesNamespace

func (f *ListPackageRevisionFilter) MatchesNamespace(namespace string) (bool, string)

type Object

type Object interface {
	metav1.Object
	runtime.Object
}

type Package

type Package interface {
	KubeObjectNamespace() string
	KubeObjectName() string
	Key() PackageKey

	// GetPackage returns the object representing this package
	GetPackage(ctx context.Context) *porchapi.PorchPackage

	// GetLatestRevision returns the name of the package revision that is the "latest" package
	// revision belonging to this package
	GetLatestRevision(ctx context.Context) int
}

Package is an abstract package.

type PackageFetcher

type PackageFetcher struct {
	RepoOpener        RepositoryOpener
	ReferenceResolver ReferenceResolver
}

func (*PackageFetcher) FetchResources

func (p *PackageFetcher) FetchResources(ctx context.Context, packageRevisionRef *porchapi.PackageRevisionRef, namespace string) (*porchapi.PackageRevisionResources, error)

func (*PackageFetcher) FetchRevision

func (p *PackageFetcher) FetchRevision(ctx context.Context, packageRevisionRef *porchapi.PackageRevisionRef, namespace string) (PackageRevision, error)

type PackageKey

type PackageKey struct {
	RepoKey       RepositoryKey
	Path, Package string
}

func FromFullPathname

func FromFullPathname(repoKey RepositoryKey, fullpath string) PackageKey

func PkgK8sName2Key

func PkgK8sName2Key(k8sNamespace, k8sName string) (PackageKey, error)

func (PackageKey) DeepCopy

func (k PackageKey) DeepCopy(outKey *PackageKey)

func (PackageKey) K8SNS

func (k PackageKey) K8SNS() string

func (PackageKey) K8SName

func (k PackageKey) K8SName() string

func (PackageKey) Matches

func (k PackageKey) Matches(other PackageKey) bool

func (PackageKey) RKey

func (k PackageKey) RKey() RepositoryKey

func (PackageKey) String

func (k PackageKey) String() string

func (PackageKey) ToFullPathname

func (k PackageKey) ToFullPathname() string

func (PackageKey) ToPkgPathname

func (k PackageKey) ToPkgPathname() string

type PackageResources

type PackageResources struct {
	Contents map[string]string
}

TODO: "sigs.k8s.io/kustomize/kyaml/filesys" FileSystem?

func ReadPackage

func ReadPackage(t *testing.T, packageDir string) PackageResources

type PackageRevision

type PackageRevision interface {
	KubeObjectNamespace() string
	KubeObjectName() string
	Key() PackageRevisionKey

	// UID returns a unique identifier for the PackageRevision.
	UID() types.UID

	// Lifecycle returns the current lifecycle state of the package.
	Lifecycle(ctx context.Context) porchapi.PackageRevisionLifecycle

	// UpdateLifecycle updates the desired lifecycle of the package. This can only
	// be used for Published package revisions to go from Published to DeletionProposed
	// or vice versa. Draft revisions should use PackageDraft.UpdateLifecycle.
	UpdateLifecycle(ctx context.Context, lifecycle porchapi.PackageRevisionLifecycle) error

	// GetPackageRevision returns the PackageRevision ("DRY") API representation of this package-revision
	GetPackageRevision(ctx context.Context) (*porchapi.PackageRevision, error)

	// GetResources returns the PackageRevisionResources ("WET") API representation of this package-revision
	// TODO: return PackageResources or filesystem abstraction?
	GetResources(ctx context.Context) (*porchapi.PackageRevisionResources, error)

	// GetUpstreamLock returns the kpt lock information.
	GetUpstreamLock(ctx context.Context) (kptfilev1.Upstream, kptfilev1.Locator, error)

	// GetKptfile returns the Kptfile for the package
	GetKptfile(ctx context.Context) (kptfilev1.KptFile, error)

	// GetLock returns the current revision's lock information.
	// This will be the upstream info for downstream revisions.
	GetLock(ctx context.Context) (kptfilev1.Upstream, kptfilev1.Locator, error)

	// ResourceVersion returns the Kube resource version of the package
	ResourceVersion() string

	// Create the main package revision
	// TODO: This is a git thing and probably shouldn't be on the generic PackageRevision interface
	ToMainPackageRevision(ctx context.Context) PackageRevision

	// Get the Kubernetes metadata for the package revision
	GetMeta() metav1.ObjectMeta

	// Set the Kubernetes metadata for the package revision
	SetMeta(ctx context.Context, meta metav1.ObjectMeta) error
}

PackageRevision is an abstract package version. We have a single object for both Revision and Resources, because conceptually they are one object. The best way we've found (so far) to represent them in k8s is as two resources, but they map to the same object. Interesting reading: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#differing-representations

type PackageRevisionDraft

type PackageRevisionDraft interface {
	Key() PackageRevisionKey
	GetMeta() metav1.ObjectMeta
	UpdateResources(context.Context, *porchapi.PackageRevisionResources, *porchapi.Task) error
	// Updates desired lifecycle of the package. The lifecycle is applied on Close.
	UpdateLifecycle(context.Context, porchapi.PackageRevisionLifecycle) error
}

type PackageRevisionKey

type PackageRevisionKey struct {
	PkgKey        PackageKey
	Revision      int
	WorkspaceName string
}

func PkgRevK8sName2Key

func PkgRevK8sName2Key(k8sNamespace, k8sName string) (PackageRevisionKey, error)

func (PackageRevisionKey) DeepCopy

func (k PackageRevisionKey) DeepCopy(outKey *PackageRevisionKey)

func (PackageRevisionKey) K8SNS

func (k PackageRevisionKey) K8SNS() string

func (PackageRevisionKey) K8SName

func (k PackageRevisionKey) K8SName() string

func (PackageRevisionKey) Matches

func (k PackageRevisionKey) Matches(other PackageRevisionKey) bool

func (PackageRevisionKey) PKey

func (k PackageRevisionKey) PKey() PackageKey

func (PackageRevisionKey) RKey

func (PackageRevisionKey) String

func (k PackageRevisionKey) String() string

type ReferenceResolver

type ReferenceResolver interface {
	ResolveReference(ctx context.Context, namespace, name string, result Object) error
}

type Repository

type Repository interface {
	KubeObjectNamespace() string
	KubeObjectName() string
	Key() RepositoryKey

	// ListPackageRevisions lists the existing package revisions in the repository
	ListPackageRevisions(ctx context.Context, filter ListPackageRevisionFilter) ([]PackageRevision, error)

	// CreatePackageRevision creates a new package revision
	CreatePackageRevisionDraft(ctx context.Context, obj *porchapi.PackageRevision) (PackageRevisionDraft, error)

	// ClosePackageRevisionDraft closes out a Package Revision Draft
	ClosePackageRevisionDraft(ctx context.Context, prd PackageRevisionDraft, version int) (PackageRevision, error)

	// DeletePackageRevision deletes a package revision
	DeletePackageRevision(ctx context.Context, old PackageRevision) error

	// UpdatePackageRevision updates a package
	UpdatePackageRevision(ctx context.Context, old PackageRevision) (PackageRevisionDraft, error)

	// ListPackages lists all packages in the repository
	ListPackages(ctx context.Context, filter ListPackageFilter) ([]Package, error)

	// Version returns a string that is guaranteed to be different if any change has been made to the repo contents
	Version(ctx context.Context) (string, error)

	// Close cleans up any resources associated with the repository
	Close(ctx context.Context) error

	// Refresh the repository
	Refresh(ctx context.Context) error
}

Repository is the interface for interacting with packages in repositories TODO: we may need interface to manage repositories too. Stay tuned.

type RepositoryKey

type RepositoryKey struct {
	Namespace, Name, Path, PlaceholderWSname string
}

func (RepositoryKey) DeepCopy

func (k RepositoryKey) DeepCopy(outKey *RepositoryKey)

func (RepositoryKey) K8SNS

func (k RepositoryKey) K8SNS() string

func (RepositoryKey) K8SName

func (k RepositoryKey) K8SName() string

func (RepositoryKey) Matches

func (k RepositoryKey) Matches(other RepositoryKey) bool

func (RepositoryKey) String

func (k RepositoryKey) String() string

type RepositoryOpener

type RepositoryOpener interface {
	OpenRepository(ctx context.Context, repositorySpec *configapi.Repository) (Repository, error)
}

type UserInfo

type UserInfo struct {
	Name  string
	Email string
}

type UserInfoProvider

type UserInfoProvider interface {
	// GetUserInfo returns the information about the user on whose behalf the request is being
	// processed, if any. If user cannot be determnined, returns nil.
	GetUserInfo(ctx context.Context) *UserInfo
}

UserInfoProvider providers name of the authenticated user on whose behalf the request is being processed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL