Skip to content
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

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 21 additions & 11 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
internalapi "github.com/nephio-project/porch/internal/api/porchinternal/v1alpha1"
"github.com/nephio-project/porch/internal/kpt/fnruntime"
"github.com/nephio-project/porch/pkg/cache"
memorycache "github.com/nephio-project/porch/pkg/cache/memory"
cachetypes "github.com/nephio-project/porch/pkg/cache/types"
"github.com/nephio-project/porch/pkg/engine"
externalrepotypes "github.com/nephio-project/porch/pkg/externalrepo/types"
"github.com/nephio-project/porch/pkg/meta"
"github.com/nephio-project/porch/pkg/registry/porch"
"google.golang.org/api/option"
Expand Down Expand Up @@ -94,7 +95,7 @@ type Config struct {
type PorchServer struct {
GenericAPIServer *genericapiserver.GenericAPIServer
coreClient client.WithWatch
cache cache.Cache
cache cachetypes.Cache
PeriodicRepoSyncFrequency time.Duration
}

Expand Down Expand Up @@ -227,13 +228,22 @@ func (c completedConfig) New() (*PorchServer, error) {
userInfoProvider := &porch.ApiserverUserInfoProvider{}

watcherMgr := engine.NewWatcherManager()

memoryCache := memorycache.NewCache(c.ExtraConfig.CacheDirectory, c.ExtraConfig.RepoSyncFrequency, c.ExtraConfig.UseUserDefinedCaBundle, memorycache.CacheOptions{
CredentialResolver: credentialResolver,
UserInfoProvider: userInfoProvider,
MetadataStore: metadataStore,
ObjectNotifier: watcherMgr,
})
cacheImpl, err := cache.CreateCacheImpl(
context.TODO(),
cachetypes.CacheOptions{
ExternalRepoOptions: externalrepotypes.ExternalRepoOptions{
LocalDirectory: c.ExtraConfig.CacheDirectory,
UseUserDefinedCaBundle: c.ExtraConfig.UseUserDefinedCaBundle,
CredentialResolver: credentialResolver,
UserInfoProvider: userInfoProvider,
},
RepoSyncFrequency: c.ExtraConfig.RepoSyncFrequency,
MetadataStore: metadataStore,
RepoPRChangeNotifier: watcherMgr,
})
if err != nil {
return nil, fmt.Errorf("failed to creeate repository cache: %w", err)
}

runnerOptionsResolver := func(namespace string) fnruntime.RunnerOptions {
runnerOptions := fnruntime.RunnerOptions{}
Expand All @@ -243,7 +253,7 @@ func (c completedConfig) New() (*PorchServer, error) {
}

cad, err := engine.NewCaDEngine(
engine.WithCache(memoryCache),
engine.WithCache(cacheImpl),
// The order of registering the function runtimes matters here. When
// evaluating a function, the runtimes will be tried in the same
// order as they are registered.
Expand All @@ -268,7 +278,7 @@ func (c completedConfig) New() (*PorchServer, error) {
s := &PorchServer{
GenericAPIServer: genericServer,
coreClient: coreClient,
cache: memoryCache,
cache: cacheImpl,
// Set background job periodic frequency the same as repo sync frequency.
PeriodicRepoSyncFrequency: c.ExtraConfig.RepoSyncFrequency,
}
Expand Down
17 changes: 12 additions & 5 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ package cache
import (
"context"

configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1"
"github.com/nephio-project/porch/pkg/repository"
memorycache "github.com/nephio-project/porch/pkg/cache/memorycache"
cachetypes "github.com/nephio-project/porch/pkg/cache/types"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

type Cache interface {
OpenRepository(ctx context.Context, repositorySpec *configapi.Repository) (repository.Repository, error)
CloseRepository(ctx context.Context, repositorySpec *configapi.Repository, allRepos []configapi.Repository) error
var tracer = otel.Tracer("cache")

func CreateCacheImpl(ctx context.Context, options cachetypes.CacheOptions) (cachetypes.Cache, error) {
ctx, span := tracer.Start(ctx, "Repository::RepositoryFactory", trace.WithAttributes())
defer span.End()

var cacheFactory = new(memorycache.MemoryCacheFactory)
return cacheFactory.NewCache(ctx, options)
}
213 changes: 0 additions & 213 deletions pkg/cache/memory/cache.go

This file was deleted.

Loading
Loading