Skip to content

Commit

Permalink
#81 create wrapper adapter for new DoguConfigRepository
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexander-dammeier committed Oct 7, 2024
1 parent 4f3222c commit f82f16b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/adapter/config/kubernetes/doguConfigRepository.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions pkg/domainservice/adapterInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f82f16b

Please sign in to comment.