From f82f16bc19a2536f1660998f96732d1099d482a2 Mon Sep 17 00:00:00 2001 From: Alexander Dammeier Date: Mon, 7 Oct 2024 09:26:22 +0200 Subject: [PATCH] #81 create wrapper adapter for new DoguConfigRepository We need a wrapper because of our specific errors in the blueprint operator. Maybe we can introduce them in the registry-lib as well, so we can completely remove this wrapper adapter. For now, the plan is to replace the old etcd adapter step by step with the new adapter. --- .../config/kubernetes/doguConfigRepository.go | 33 +++++++++++++++++++ pkg/domainservice/adapterInterfaces.go | 7 ++++ 2 files changed, 40 insertions(+) create mode 100644 pkg/adapter/config/kubernetes/doguConfigRepository.go diff --git a/pkg/adapter/config/kubernetes/doguConfigRepository.go b/pkg/adapter/config/kubernetes/doguConfigRepository.go new file mode 100644 index 00000000..ed22f82d --- /dev/null +++ b/pkg/adapter/config/kubernetes/doguConfigRepository.go @@ -0,0 +1,33 @@ +package kubernetes + +import ( + "context" + "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" + "github.com/cloudogu/k8s-blueprint-operator/pkg/domainservice" + "github.com/cloudogu/k8s-registry-lib/config" + "github.com/cloudogu/k8s-registry-lib/repository" +) + +type DoguConfigRepository struct { + repo repository.DoguConfigRepository +} + +func NewDoguConfigRepository(repo repository.DoguConfigRepository) *DoguConfigRepository { + return &DoguConfigRepository{repo: repo} +} + +func (e DoguConfigRepository) Get(ctx context.Context, doguName common.SimpleDoguName) (config.DoguConfig, error) { + // TODO: There seems to be no way to know, if we have a NotFoundError or a connection error. + return e.repo.Get(ctx, config.SimpleDoguName(doguName)) +} + +func (e DoguConfigRepository) Update(ctx context.Context, entry config.DoguConfig) (config.DoguConfig, error) { + mergedConfig, err := e.repo.Update(ctx, entry) + // TODO: we cannot see here, if there is a real conflict or there was a connection error. + // With a conflict, we can immediately restart the business process + // With an connection error we need a longer backoff (internalError) + if err != nil { + return entry, domainservice.NewInternalError(err, "failed to save or merge config for %s", entry.DoguName) + } + return mergedConfig, nil +} diff --git a/pkg/domainservice/adapterInterfaces.go b/pkg/domainservice/adapterInterfaces.go index cba876b2..a9d86130 100644 --- a/pkg/domainservice/adapterInterfaces.go +++ b/pkg/domainservice/adapterInterfaces.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" + "github.com/cloudogu/k8s-registry-lib/config" "github.com/cloudogu/cesapp-lib/core" @@ -170,6 +171,12 @@ type GlobalConfigEntryRepository interface { DeleteAllByKeys(context.Context, []common.GlobalConfigKey) error } +// DoguConfigRepository TODO: add go doc, especially for errors +type DoguConfigRepository interface { + Get(ctx context.Context, doguName common.SimpleDoguName) (config.DoguConfig, error) + Update(ctx context.Context, entry config.DoguConfig) (config.DoguConfig, error) +} + type DoguConfigEntryRepository interface { // Get retrieves a key from the dogu's config. // It can throw the following errors: