Skip to content

Commit

Permalink
#81 fix problems after conflict merge
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-dammeier committed Oct 28, 2024
1 parent c9cc910 commit b983beb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
12 changes: 6 additions & 6 deletions pkg/application/ecosystemConfigUseCase.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ func (useCase *EcosystemConfigUseCase) ApplyConfig(ctx context.Context, blueprin

err = useCase.markApplyConfigStart(ctx, blueprintSpec)
if err != nil {
return useCase.handleFailedApplyRegistryConfig(ctx, blueprintSpec, err)
return useCase.handleFailedApplyEcosystemConfig(ctx, blueprintSpec, err)
}

// do not apply further configs if error happens, we don't want to corrupt the system more than needed
// apply normal and sensitive config with this
err = useCase.applyDoguConfigDiffs(ctx, blueprintSpec.StateDiff.DoguConfigDiffs)
if err != nil {
return useCase.handleFailedApplyRegistryConfig(ctx, blueprintSpec, err)
return useCase.handleFailedApplyEcosystemConfig(ctx, blueprintSpec, err)
}
err = useCase.applyGlobalConfigDiffs(ctx, globalConfigDiffs.GetGlobalConfigDiffsByAction())
if err != nil {
return useCase.handleFailedApplyRegistryConfig(ctx, blueprintSpec, fmt.Errorf("could not apply global config: %w", err))
return useCase.handleFailedApplyEcosystemConfig(ctx, blueprintSpec, fmt.Errorf("could not apply global config: %w", err))
}

return useCase.markConfigApplied(ctx, blueprintSpec)
Expand Down Expand Up @@ -177,9 +177,9 @@ func (useCase *EcosystemConfigUseCase) markApplyConfigStart(ctx context.Context,
return nil
}

func (useCase *EcosystemConfigUseCase) handleFailedApplyRegistryConfig(ctx context.Context, blueprintSpec *domain.BlueprintSpec, err error) error {
func (useCase *EcosystemConfigUseCase) handleFailedApplyEcosystemConfig(ctx context.Context, blueprintSpec *domain.BlueprintSpec, err error) error {
logger := log.FromContext(ctx).
WithName("EcosystemConfigUseCase.handleFailedApplyRegistryConfig").
WithName("EcosystemConfigUseCase.handleFailedApplyEcosystemConfig").
WithValues("blueprintId", blueprintSpec.Id)

blueprintSpec.MarkApplyEcosystemConfigFailed(err)
Expand All @@ -197,7 +197,7 @@ func (useCase *EcosystemConfigUseCase) markConfigApplied(ctx context.Context, bl
blueprintSpec.MarkEcosystemConfigApplied()
err := useCase.blueprintRepository.Update(ctx, blueprintSpec)
if err != nil {
return fmt.Errorf("failed to mark registry config applied: %w", err)
return fmt.Errorf("failed to mark ecosystem config applied: %w", err)
}
return nil
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/application/ecosystemConfigUseCase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) {

// then
require.NoError(t, err)
assert.Equal(t, spec.Status, domain.StatusPhaseApplyRegistryConfigFailed)
assert.Equal(t, spec.Status, domain.StatusPhaseApplyEcosystemConfigFailed)
})

t.Run("error applying dogu config", func(t *testing.T) {
Expand Down Expand Up @@ -614,8 +614,8 @@ func TestEcosystemConfigUseCase_markConfigApplied(t *testing.T) {
// given
spec := &domain.BlueprintSpec{}
expectedSpec := &domain.BlueprintSpec{}
expectedSpec.Status = domain.StatusPhaseRegistryConfigApplied
expectedSpec.Events = append(spec.Events, domain.RegistryConfigAppliedEvent{})
expectedSpec.Status = domain.StatusPhaseEcosystemConfigApplied
expectedSpec.Events = append(spec.Events, domain.EcosystemConfigAppliedEvent{})
blueprintRepoMock := newMockBlueprintSpecRepository(t)

blueprintRepoMock.EXPECT().Update(testCtx, expectedSpec).Return(nil)
Expand All @@ -633,8 +633,8 @@ func TestEcosystemConfigUseCase_markConfigApplied(t *testing.T) {
// given
spec := &domain.BlueprintSpec{}
expectedSpec := &domain.BlueprintSpec{}
expectedSpec.Status = domain.StatusPhaseRegistryConfigApplied
expectedSpec.Events = append(spec.Events, domain.RegistryConfigAppliedEvent{})
expectedSpec.Status = domain.StatusPhaseEcosystemConfigApplied
expectedSpec.Events = append(spec.Events, domain.EcosystemConfigAppliedEvent{})
blueprintRepoMock := newMockBlueprintSpecRepository(t)

blueprintRepoMock.EXPECT().Update(testCtx, expectedSpec).Return(assert.AnError)
Expand All @@ -646,7 +646,7 @@ func TestEcosystemConfigUseCase_markConfigApplied(t *testing.T) {

// then
require.Error(t, err)
assert.ErrorContains(t, err, "failed to mark registry config applied")
assert.ErrorContains(t, err, "failed to mark ecosystem config applied")
assert.ErrorIs(t, err, assert.AnError)
})
}
Expand All @@ -656,8 +656,8 @@ func TestEcosystemConfigUseCase_markApplyConfigStart(t *testing.T) {
// given
spec := &domain.BlueprintSpec{}
expectedSpec := &domain.BlueprintSpec{}
expectedSpec.Status = domain.StatusPhaseApplyRegistryConfig
expectedSpec.Events = append(spec.Events, domain.ApplyRegistryConfigEvent{})
expectedSpec.Status = domain.StatusPhaseApplyEcosystemConfig
expectedSpec.Events = append(spec.Events, domain.ApplyEcosystemConfigEvent{})
blueprintRepoMock := newMockBlueprintSpecRepository(t)

blueprintRepoMock.EXPECT().Update(testCtx, expectedSpec).Return(nil)
Expand All @@ -675,8 +675,8 @@ func TestEcosystemConfigUseCase_markApplyConfigStart(t *testing.T) {
// given
spec := &domain.BlueprintSpec{}
expectedSpec := &domain.BlueprintSpec{}
expectedSpec.Status = domain.StatusPhaseApplyRegistryConfig
expectedSpec.Events = append(spec.Events, domain.ApplyRegistryConfigEvent{})
expectedSpec.Status = domain.StatusPhaseApplyEcosystemConfig
expectedSpec.Events = append(spec.Events, domain.ApplyEcosystemConfigEvent{})
blueprintRepoMock := newMockBlueprintSpecRepository(t)

blueprintRepoMock.EXPECT().Update(testCtx, expectedSpec).Return(assert.AnError)
Expand All @@ -693,7 +693,7 @@ func TestEcosystemConfigUseCase_markApplyConfigStart(t *testing.T) {
})
}

func TestEcosystemConfigUseCase_handleFailedApplyRegistryConfig(t *testing.T) {
func TestEcosystemConfigUseCase_handleFailedApplyEcosystemConfig(t *testing.T) {
t.Run("should set applied status and event", func(t *testing.T) {
// given
spec := &domain.BlueprintSpec{}
Expand All @@ -704,12 +704,12 @@ func TestEcosystemConfigUseCase_handleFailedApplyRegistryConfig(t *testing.T) {
sut := EcosystemConfigUseCase{blueprintRepository: blueprintRepoMock}

// when
err := sut.handleFailedApplyRegistryConfig(testCtx, spec, assert.AnError)
err := sut.handleFailedApplyEcosystemConfig(testCtx, spec, assert.AnError)

// then
require.NoError(t, err)
assert.Equal(t, domain.StatusPhaseApplyRegistryConfigFailed, spec.Status)
assert.IsType(t, domain.ApplyRegistryConfigFailedEvent{}, spec.Events[0])
assert.Equal(t, domain.StatusPhaseApplyEcosystemConfigFailed, spec.Status)
assert.IsType(t, domain.ApplyEcosystemConfigFailedEvent{}, spec.Events[0])
})

t.Run("should return error on update error", func(t *testing.T) {
Expand All @@ -722,11 +722,11 @@ func TestEcosystemConfigUseCase_handleFailedApplyRegistryConfig(t *testing.T) {
sut := EcosystemConfigUseCase{blueprintRepository: blueprintRepoMock}

// when
err := sut.handleFailedApplyRegistryConfig(testCtx, spec, assert.AnError)
err := sut.handleFailedApplyEcosystemConfig(testCtx, spec, assert.AnError)

// then
require.Error(t, err)
assert.ErrorContains(t, err, "cannot mark blueprint config apply as failed while handling \"applyRegistryConfigFailed\" status")
assert.ErrorContains(t, err, "cannot mark blueprint config apply as failed while handling \"applyEcosystemConfigFailed\" status")
assert.ErrorIs(t, err, assert.AnError)
})
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const (

const registryCacheDir = "/tmp/dogu-registry-cache"

const ApplicationContextKey = "applicationContext"

var log = ctrl.Log.WithName("config")
var Stage = StageProduction

Expand Down
2 changes: 0 additions & 2 deletions pkg/domain/common/componentName.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"strings"
)

var K8sK8sLonghornName = QualifiedComponentName{Namespace: "k8s", SimpleName: "k8s-longhorn"}

type QualifiedComponentName struct {
Namespace ComponentNamespace
SimpleName SimpleComponentName
Expand Down

0 comments on commit b983beb

Please sign in to comment.