Skip to content

Place repositories (git/oci) behind the Repository interface and use a Factory to create instances of implementations #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 25, 2025

Conversation

liamfallon
Copy link
Member

@liamfallon liamfallon commented Jan 20, 2025

This PR refactors the existing Porch code to make it easier to introduce a database cache.

It reinforces the structure of the code so that repository implementations (git/oci) are behind the interface and are only used by calling the interface. The externalrepo package is introduced as a package that contains "external" repository implementations. The following list details the refactors:

  • A new pkg/externalrepo package is introduced, this package contains a factory for creating implementations of the Repository type that store packages that are source or target packages for Porch (such as git and oci), that is Repository implementations that are not Porch internal caches
  • The pkg/git' package is moved to pkg/externalrepo/git`
  • The pkg/oci' package is moved to pkg/externalrepo/oci`
  • Types for the repoimpl factory are in pkg/externalrepo/types (to avoid circular imports)
  • The ExternalRepoFactory interface is introduced to create instances of repos (git or oci today)
  • The CreateExternalRepo function in pkg/externalrepo/externalrepo.go creates an instance of a repo based on the incoming configuration, calling the factory in either git or oci
  • The cache options are restructured with a contained ExternalRepoOptions struct containing the options that the ExternalRepo implementations use but the cache does not use
  • The memory cache is renamed as the CR (Custom Resource) cache to better reflect how it works
  • A CacheFactory interface is introduced for creating cache implementations, where the implementation of the cache is behind the factory interlace
  • A CacheFactory implementation is added to the CR cache cache.

@liamfallon
Copy link
Member Author

Copy link
Collaborator

@efiacor efiacor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments.
Do we need some unit test coverage on the new repoimpl stuff? Not sure if it's covered currently.

@liamfallon
Copy link
Member Author

Few minor comments. Do we need some unit test coverage on the new repoimpl stuff? Not sure if it's covered currently.

yes, I'll do the unit tests in a later PR.

@kushnaidu
Copy link
Contributor

Looks great Liam.

@liamfallon
Copy link
Member Author

/test presubmit-nephio-go-test

@efiacor
Copy link
Collaborator

efiacor commented Feb 25, 2025

/approve
/lgtm

@nephio-prow nephio-prow bot added the lgtm label Feb 25, 2025
Copy link
Contributor

nephio-prow bot commented Feb 25, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: efiacor, liamfallon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@nephio-prow nephio-prow bot merged commit adc3632 into nephio-project:main Feb 25, 2025
8 checks passed
@liamfallon liamfallon deleted the refactor-git branch February 27, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants