Skip to content

Commit

Permalink
#81 add globalConfigRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-dammeier committed Oct 7, 2024
1 parent 0c71dd4 commit 8dfbdce
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/adapter/config/kubernetes/doguConfigRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func (e DoguConfigRepository) Get(ctx context.Context, doguName common.SimpleDog
return e.repo.Get(ctx, doguName)
}

func (e DoguConfigRepository) Update(ctx context.Context, entry config.DoguConfig) (config.DoguConfig, error) {
mergedConfig, err := e.repo.Update(ctx, entry)
func (e DoguConfigRepository) Update(ctx context.Context, config config.DoguConfig) (config.DoguConfig, error) {
updatedConfig, err := e.repo.Update(ctx, config)
// 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 config, domainservice.NewInternalError(err, "failed to update config for %s", config.DoguName)
}
return mergedConfig, nil
return updatedConfig, nil
}
37 changes: 37 additions & 0 deletions pkg/adapter/config/kubernetes/globalConfigRepository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package kubernetes

import (
"context"
"github.com/cloudogu/k8s-blueprint-operator/pkg/domainservice"
"github.com/cloudogu/k8s-registry-lib/config"
"github.com/cloudogu/k8s-registry-lib/repository"
)

type GlobalConfigRepository struct {
repo repository.GlobalConfigRepository
}

func NewGlobalConfigRepository(repo repository.GlobalConfigRepository) *GlobalConfigRepository {
return &GlobalConfigRepository{repo: repo}
}

func (e GlobalConfigRepository) Get(ctx context.Context) (config.GlobalConfig, error) {
return e.repo.Get(ctx)
//TODO: add own error types again
//if registry.IsKeyNotFoundError(err) {
// return nil, domainservice.NewNotFoundError(err, "could not find key %q from global config in etcd", key)
//} else if err != nil {
// return nil, domainservice.NewInternalError(err, "failed to get value for key %q from global config in etcd", key)
//}
}

func (e GlobalConfigRepository) Update(ctx context.Context, config config.GlobalConfig) (config.GlobalConfig, error) {
updatedConfig, err := e.repo.Update(ctx, config)
// 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 config, domainservice.NewInternalError(err, "failed to update global config")
}
return updatedConfig, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func (e SensitiveDoguConfigRepository) Get(ctx context.Context, doguName common.
return e.repo.Get(ctx, doguName)
}

func (e SensitiveDoguConfigRepository) Update(ctx context.Context, entry config.DoguConfig) (config.DoguConfig, error) {
mergedConfig, err := e.repo.Update(ctx, entry)
func (e SensitiveDoguConfigRepository) Update(ctx context.Context, config config.DoguConfig) (config.DoguConfig, error) {
updatedConfig, err := e.repo.Update(ctx, config)
// 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 config, domainservice.NewInternalError(err, "failed to update sensitive config for %s", config.DoguName)
}
return mergedConfig, nil
return updatedConfig, nil
}
6 changes: 6 additions & 0 deletions pkg/application/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ type remoteDoguRegistry interface {
type maintenanceMode interface {
domainservice.MaintenanceMode
}

// TODO: remove this when refactoring is done
type globalConfigEntryRepository interface {
domainservice.GlobalConfigEntryRepository
}

type globalConfigRepository interface {
domainservice.GlobalConfigRepository
}

// TODO: remove this when refactoring is done
type doguConfigEntryRepository interface {
domainservice.DoguConfigEntryRepository
Expand Down
10 changes: 8 additions & 2 deletions pkg/domainservice/adapterInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,22 @@ type GlobalConfigEntryRepository interface {
DeleteAllByKeys(context.Context, []common.GlobalConfigKey) error
}

// GlobalConfigRepository TODO: add go doc, especially for errors
type GlobalConfigRepository interface {
Get(ctx context.Context) (config.GlobalConfig, error)
Update(ctx context.Context, config config.GlobalConfig) (config.GlobalConfig, 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)
Update(ctx context.Context, config config.DoguConfig) (config.DoguConfig, error)
}

// SensitiveDoguConfigRepository TODO: add go doc, especially for errors
type SensitiveDoguConfigRepository interface {
Get(ctx context.Context, doguName common.SimpleDoguName) (config.DoguConfig, error)
Update(ctx context.Context, entry config.DoguConfig) (config.DoguConfig, error)
Update(ctx context.Context, config config.DoguConfig) (config.DoguConfig, error)
}

type DoguConfigEntryRepository interface {
Expand Down

0 comments on commit 8dfbdce

Please sign in to comment.