diff --git a/pkg/adapter/config/kubernetes/doguConfigRepository.go b/pkg/adapter/config/kubernetes/doguConfigRepository.go index aac81a0..a4b0f81 100644 --- a/pkg/adapter/config/kubernetes/doguConfigRepository.go +++ b/pkg/adapter/config/kubernetes/doguConfigRepository.go @@ -12,6 +12,11 @@ type DoguConfigRepository struct { repo repository.DoguConfigRepository } +func (e DoguConfigRepository) GetAll(ctx context.Context, doguNames []common.SimpleDoguName) (map[common.SimpleDoguName]config.DoguConfig, error) { + //TODO implement me + panic("implement me") +} + func NewDoguConfigRepository(repo repository.DoguConfigRepository) *DoguConfigRepository { return &DoguConfigRepository{repo: repo} } diff --git a/pkg/adapter/config/kubernetes/sensitiveDoguConfigRepository.go b/pkg/adapter/config/kubernetes/sensitiveDoguConfigRepository.go index 41638af..a2963e5 100644 --- a/pkg/adapter/config/kubernetes/sensitiveDoguConfigRepository.go +++ b/pkg/adapter/config/kubernetes/sensitiveDoguConfigRepository.go @@ -12,6 +12,11 @@ type SensitiveDoguConfigRepository struct { repo repository.DoguConfigRepository } +func (e SensitiveDoguConfigRepository) GetAll(ctx context.Context, doguNames []common.SimpleDoguName) (map[common.SimpleDoguName]config.DoguConfig, error) { + //TODO implement me + panic("implement me") +} + func NewSensitiveDoguConfigRepository(repo repository.DoguConfigRepository) *SensitiveDoguConfigRepository { return &SensitiveDoguConfigRepository{repo: repo} } diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go index a426486..da4a1e0 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go @@ -23,11 +23,10 @@ type DoguConfigEntryDiff struct { type SensitiveDoguConfigDiff []SensitiveDoguConfigEntryDiff type SensitiveDoguConfigEntryDiff struct { - Key string `json:"key"` - Actual DoguConfigValueState `json:"actual"` - Expected DoguConfigValueState `json:"expected"` - DoguNotInstalled bool `json:"doguNotInstalled,omitempty"` - NeededAction ConfigAction `json:"neededAction"` + Key string `json:"key"` + Actual DoguConfigValueState `json:"actual"` + Expected DoguConfigValueState `json:"expected"` + NeededAction ConfigAction `json:"neededAction"` } func convertToCombinedDoguConfigDiffDomain(doguName string, dto CombinedDoguConfigDiff) domain.CombinedDoguConfigDiffs { @@ -87,8 +86,7 @@ func convertToSensitiveDoguConfigEntryDiffDomain(doguName string, dto SensitiveD Value: dto.Expected.Value, Exists: dto.Expected.Exists, }, - DoguAlreadyInstalled: !dto.DoguNotInstalled, - NeededAction: domain.ConfigAction(dto.NeededAction), + NeededAction: domain.ConfigAction(dto.NeededAction), } } @@ -141,7 +139,6 @@ func convertToSensitiveDoguConfigEntryDiffDTO(domainModel domain.SensitiveDoguCo Value: domainModel.Expected.Value, Exists: domainModel.Expected.Exists, }, - DoguNotInstalled: !domainModel.DoguAlreadyInstalled, - NeededAction: ConfigAction(domainModel.NeededAction), + NeededAction: ConfigAction(domainModel.NeededAction), } } diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go index 51ee579..263d79b 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go @@ -98,8 +98,7 @@ func Test_convertToCombinedDoguConfigDiffDTO(t *testing.T) { Value: "1024m", Exists: true, }, - DoguAlreadyInstalled: true, - NeededAction: domain.ConfigActionSet, + NeededAction: domain.ConfigActionSet, }, { Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ @@ -113,8 +112,7 @@ func Test_convertToCombinedDoguConfigDiffDTO(t *testing.T) { Value: "512m", Exists: true, }, - DoguAlreadyInstalled: false, - NeededAction: domain.ConfigActionSet, + NeededAction: domain.ConfigActionSet, }, }, }, @@ -130,8 +128,7 @@ func Test_convertToCombinedDoguConfigDiffDTO(t *testing.T) { Value: "1024m", Exists: true, }, - DoguNotInstalled: false, - NeededAction: "set", + NeededAction: "set", }, { Key: "container_config/swap_limit", @@ -142,8 +139,7 @@ func Test_convertToCombinedDoguConfigDiffDTO(t *testing.T) { Value: "512m", Exists: true, }, - DoguNotInstalled: true, - NeededAction: "set", + NeededAction: "set", }, }, }, @@ -244,8 +240,7 @@ func Test_convertToCombinedDoguConfigDiffDomain(t *testing.T) { Value: "1024m", Exists: true, }, - DoguNotInstalled: false, - NeededAction: "set", + NeededAction: "set", }, { Key: "container_config/swap_limit", @@ -256,8 +251,7 @@ func Test_convertToCombinedDoguConfigDiffDomain(t *testing.T) { Value: "512m", Exists: true, }, - DoguNotInstalled: true, - NeededAction: "set", + NeededAction: "set", }, }, }, @@ -276,8 +270,7 @@ func Test_convertToCombinedDoguConfigDiffDomain(t *testing.T) { Value: "1024m", Exists: true, }, - DoguAlreadyInstalled: true, - NeededAction: domain.ConfigActionSet, + NeededAction: domain.ConfigActionSet, }, { Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ @@ -291,8 +284,7 @@ func Test_convertToCombinedDoguConfigDiffDomain(t *testing.T) { Value: "512m", Exists: true, }, - DoguAlreadyInstalled: false, - NeededAction: domain.ConfigActionSet, + NeededAction: domain.ConfigActionSet, }, }, }, diff --git a/pkg/application/mock_doguConfigRepository_test.go b/pkg/application/mock_doguConfigRepository_test.go index a92e5b7..0a8d8c5 100644 --- a/pkg/application/mock_doguConfigRepository_test.go +++ b/pkg/application/mock_doguConfigRepository_test.go @@ -80,6 +80,65 @@ func (_c *mockDoguConfigRepository_Get_Call) RunAndReturn(run func(context.Conte return _c } +// GetAll provides a mock function with given fields: ctx, doguNames +func (_m *mockDoguConfigRepository) GetAll(ctx context.Context, doguNames []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error) { + ret := _m.Called(ctx, doguNames) + + if len(ret) == 0 { + panic("no return value specified for GetAll") + } + + var r0 map[config.SimpleDoguName]config.DoguConfig + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)); ok { + return rf(ctx, doguNames) + } + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) map[config.SimpleDoguName]config.DoguConfig); ok { + r0 = rf(ctx, doguNames) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[config.SimpleDoguName]config.DoguConfig) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []config.SimpleDoguName) error); ok { + r1 = rf(ctx, doguNames) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDoguConfigRepository_GetAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAll' +type mockDoguConfigRepository_GetAll_Call struct { + *mock.Call +} + +// GetAll is a helper method to define mock.On call +// - ctx context.Context +// - doguNames []config.SimpleDoguName +func (_e *mockDoguConfigRepository_Expecter) GetAll(ctx interface{}, doguNames interface{}) *mockDoguConfigRepository_GetAll_Call { + return &mockDoguConfigRepository_GetAll_Call{Call: _e.mock.On("GetAll", ctx, doguNames)} +} + +func (_c *mockDoguConfigRepository_GetAll_Call) Run(run func(ctx context.Context, doguNames []config.SimpleDoguName)) *mockDoguConfigRepository_GetAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]config.SimpleDoguName)) + }) + return _c +} + +func (_c *mockDoguConfigRepository_GetAll_Call) Return(_a0 map[config.SimpleDoguName]config.DoguConfig, _a1 error) *mockDoguConfigRepository_GetAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDoguConfigRepository_GetAll_Call) RunAndReturn(run func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)) *mockDoguConfigRepository_GetAll_Call { + _c.Call.Return(run) + return _c +} + // Update provides a mock function with given fields: ctx, _a1 func (_m *mockDoguConfigRepository) Update(ctx context.Context, _a1 config.DoguConfig) (config.DoguConfig, error) { ret := _m.Called(ctx, _a1) diff --git a/pkg/application/mock_sensitiveDoguConfigRepository_test.go b/pkg/application/mock_sensitiveDoguConfigRepository_test.go index 2fc48db..61b37a8 100644 --- a/pkg/application/mock_sensitiveDoguConfigRepository_test.go +++ b/pkg/application/mock_sensitiveDoguConfigRepository_test.go @@ -80,6 +80,65 @@ func (_c *mockSensitiveDoguConfigRepository_Get_Call) RunAndReturn(run func(cont return _c } +// GetAll provides a mock function with given fields: ctx, doguNames +func (_m *mockSensitiveDoguConfigRepository) GetAll(ctx context.Context, doguNames []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error) { + ret := _m.Called(ctx, doguNames) + + if len(ret) == 0 { + panic("no return value specified for GetAll") + } + + var r0 map[config.SimpleDoguName]config.DoguConfig + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)); ok { + return rf(ctx, doguNames) + } + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) map[config.SimpleDoguName]config.DoguConfig); ok { + r0 = rf(ctx, doguNames) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[config.SimpleDoguName]config.DoguConfig) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []config.SimpleDoguName) error); ok { + r1 = rf(ctx, doguNames) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockSensitiveDoguConfigRepository_GetAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAll' +type mockSensitiveDoguConfigRepository_GetAll_Call struct { + *mock.Call +} + +// GetAll is a helper method to define mock.On call +// - ctx context.Context +// - doguNames []config.SimpleDoguName +func (_e *mockSensitiveDoguConfigRepository_Expecter) GetAll(ctx interface{}, doguNames interface{}) *mockSensitiveDoguConfigRepository_GetAll_Call { + return &mockSensitiveDoguConfigRepository_GetAll_Call{Call: _e.mock.On("GetAll", ctx, doguNames)} +} + +func (_c *mockSensitiveDoguConfigRepository_GetAll_Call) Run(run func(ctx context.Context, doguNames []config.SimpleDoguName)) *mockSensitiveDoguConfigRepository_GetAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]config.SimpleDoguName)) + }) + return _c +} + +func (_c *mockSensitiveDoguConfigRepository_GetAll_Call) Return(_a0 map[config.SimpleDoguName]config.DoguConfig, _a1 error) *mockSensitiveDoguConfigRepository_GetAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockSensitiveDoguConfigRepository_GetAll_Call) RunAndReturn(run func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)) *mockSensitiveDoguConfigRepository_GetAll_Call { + _c.Call.Return(run) + return _c +} + // Update provides a mock function with given fields: ctx, _a1 func (_m *mockSensitiveDoguConfigRepository) Update(ctx context.Context, _a1 config.DoguConfig) (config.DoguConfig, error) { ret := _m.Called(ctx, _a1) diff --git a/pkg/application/stateDiffUseCase.go b/pkg/application/stateDiffUseCase.go index 4577dea..60164e9 100644 --- a/pkg/application/stateDiffUseCase.go +++ b/pkg/application/stateDiffUseCase.go @@ -15,8 +15,8 @@ type StateDiffUseCase struct { doguInstallationRepo doguInstallationRepository componentInstallationRepo componentInstallationRepository globalConfigRepo globalConfigRepository - doguConfigRepo doguConfigEntryRepository - sensitiveDoguConfigRepo sensitiveDoguConfigEntryRepository + doguConfigRepo doguConfigRepository + sensitiveDoguConfigRepo sensitiveDoguConfigRepository } func NewStateDiffUseCase( @@ -24,8 +24,8 @@ func NewStateDiffUseCase( doguInstallationRepo domainservice.DoguInstallationRepository, componentInstallationRepo domainservice.ComponentInstallationRepository, globalConfigRepo domainservice.GlobalConfigRepository, - doguConfigRepo domainservice.DoguConfigEntryRepository, - sensitiveDoguConfigRepo domainservice.SensitiveDoguConfigEntryRepository, + doguConfigRepo domainservice.DoguConfigRepository, + sensitiveDoguConfigRepo domainservice.SensitiveDoguConfigRepository, ) *StateDiffUseCase { return &StateDiffUseCase{ blueprintSpecRepo: blueprintSpecRepo, @@ -92,9 +92,9 @@ func (useCase *StateDiffUseCase) collectEcosystemState(ctx context.Context, effe logger.Info("collect needed global config") globalConfig, globalConfigErr := useCase.globalConfigRepo.Get(ctx) logger.Info("collect needed dogu config") - doguConfig, doguConfigErr := useCase.doguConfigRepo.GetAllByKey(ctx, effectiveBlueprint.Config.GetDoguConfigKeys()) + configByDogu, doguConfigErr := useCase.doguConfigRepo.GetAll(ctx, effectiveBlueprint.Config.GetDogusWithChangedConfig()) logger.Info("collect needed sensitive dogu config") - sensitiveDoguConfig, sensitiveConfigErr := useCase.sensitiveDoguConfigRepo.GetAllByKey(ctx, effectiveBlueprint.Config.GetSensitiveDoguConfigKeys()) + sensitiveConfigByDogu, sensitiveConfigErr := useCase.sensitiveDoguConfigRepo.GetAll(ctx, effectiveBlueprint.Config.GetDogusWithChangedSensitiveConfig()) joinedError := errors.Join(doguErr, componentErr, globalConfigErr, doguConfigErr, sensitiveConfigErr) @@ -106,10 +106,10 @@ func (useCase *StateDiffUseCase) collectEcosystemState(ctx context.Context, effe } return ecosystem.EcosystemState{ - InstalledDogus: installedDogus, - InstalledComponents: installedComponents, - GlobalConfig: globalConfig, - DoguConfig: doguConfig, - SensitiveDoguConfig: sensitiveDoguConfig, + InstalledDogus: installedDogus, + InstalledComponents: installedComponents, + GlobalConfig: globalConfig, + ConfigByDogu: configByDogu, + SensitiveConfigByDogu: sensitiveConfigByDogu, }, nil } diff --git a/pkg/application/stateDiffUseCase_test.go b/pkg/application/stateDiffUseCase_test.go index 5b4a94b..908916e 100644 --- a/pkg/application/stateDiffUseCase_test.go +++ b/pkg/application/stateDiffUseCase_test.go @@ -12,25 +12,34 @@ import ( "testing" ) -var postfixQualifiedDoguName = common.QualifiedDoguName{ - Namespace: "official", - SimpleName: "postfix", -} - -var ldapQualifiedDoguName = common.QualifiedDoguName{ - Namespace: "official", - SimpleName: "ldap", -} - -var nginxIngressQualifiedDoguName = common.QualifiedDoguName{ - Namespace: "k8s", - SimpleName: "nginx-ingress", -} - -var nginxStaticQualifiedDoguName = common.QualifiedDoguName{ - Namespace: "k8s", - SimpleName: "nginx-static", -} +var ( + nsOfficial = common.DoguNamespace("official") + nsK8s = common.DoguNamespace("k8s") + + postfix = common.SimpleDoguName("postfix") + ldap = common.SimpleDoguName("ldap") + nginxIngress = common.SimpleDoguName("nginx-ingress") + nginxStatic = common.SimpleDoguName("nginx-static") + + postfixQualifiedDoguName = common.QualifiedDoguName{ + Namespace: nsOfficial, + SimpleName: postfix, + } + ldapQualifiedDoguName = common.QualifiedDoguName{ + Namespace: nsOfficial, + SimpleName: ldap, + } + nginxIngressQualifiedDoguName = common.QualifiedDoguName{ + Namespace: nsK8s, + SimpleName: nginxIngress, + } + nginxStaticQualifiedDoguName = common.QualifiedDoguName{ + Namespace: nsK8s, + SimpleName: nginxStatic, + } + + nilDoguNameList []common.SimpleDoguName +) var ( internalTestError = domainservice.NewInternalError(assert.AnError, "internal error") @@ -75,11 +84,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { entries, _ := config.MapToEntries(map[string]any{}) globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -109,10 +117,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -142,10 +150,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, domainservice.NewInternalError(assert.AnError, "internal error")) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -177,12 +185,12 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, []common.DoguConfigKey(nil)). - Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, domainservice.NewInternalError(assert.AnError, "internal error")) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT(). + GetAll(testCtx, nilDoguNameList). + Return(map[config.SimpleDoguName]config.DoguConfig{}, domainservice.NewInternalError(assert.AnError, "internal error")) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -214,12 +222,12 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) sensitiveDoguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)). - Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, domainservice.NewInternalError(assert.AnError, "internal error")) + GetAll(testCtx, nilDoguNameList). + Return(map[config.SimpleDoguName]config.DoguConfig{}, domainservice.NewInternalError(assert.AnError, "internal error")) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -251,10 +259,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -283,10 +291,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -348,10 +356,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -451,10 +459,10 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)).Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -522,26 +530,22 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigEntries, entryErr := config.MapToEntries(map[string]any{ + "nginxKey1": "val1", + "nginxKey2": "val2", + }) + require.NoError(t, entryErr) doguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, []common.DoguConfigKey{ - nginxStaticConfigKeyNginxKey1, - nginxStaticConfigKeyNginxKey2, + GetAll(testCtx, []common.SimpleDoguName{ + nginxStatic, }). - Return(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{ - nginxStaticConfigKeyNginxKey1: { - Key: nginxStaticConfigKeyNginxKey1, - Value: "val1", - }, - nginxStaticConfigKeyNginxKey2: { - Key: nginxStaticConfigKeyNginxKey2, - Value: "val2", - }, + Return(map[config.SimpleDoguName]config.DoguConfig{ + nginxStatic: config.CreateDoguConfig(nginxStatic, doguConfigEntries), }, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) - sensitiveDoguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, []common.SensitiveDoguConfigKey(nil)). - Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, nil) + + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + sensitiveDoguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -613,23 +617,21 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, nil) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) - doguConfigRepoMock.EXPECT().GetAllByKey(testCtx, []common.DoguConfigKey(nil)).Return(nil, nil) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) + doguConfigRepoMock := newMockDoguConfigRepository(t) + doguConfigRepoMock.EXPECT().GetAll(testCtx, nilDoguNameList).Return(map[config.SimpleDoguName]config.DoguConfig{}, nil) + + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + doguConfigEntries, entryErr := config.MapToEntries(map[string]any{ + "nginxKey1": "val1", + "nginxKey2": "val2", + }) + require.NoError(t, entryErr) sensitiveDoguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, []common.SensitiveDoguConfigKey{ - nginxStaticSensitiveConfigKeyNginxKey1, - nginxStaticSensitiveConfigKeyNginxKey2, + GetAll(testCtx, []common.SimpleDoguName{ + nginxStatic, }). - Return(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{ - nginxStaticSensitiveConfigKeyNginxKey1: { - Key: nginxStaticSensitiveConfigKeyNginxKey1, - Value: "val1", - }, - nginxStaticSensitiveConfigKeyNginxKey2: { - Key: nginxStaticSensitiveConfigKeyNginxKey2, - Value: "val2", - }, + Return(map[config.SimpleDoguName]config.DoguConfig{ + nginxStatic: config.CreateDoguConfig(nginxStatic, doguConfigEntries), }, nil) sut := NewStateDiffUseCase(blueprintRepoMock, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -644,18 +646,16 @@ func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { "nginx-static": { SensitiveDoguConfigDiff: []domain.SensitiveDoguConfigEntryDiff{ { - Key: nginxStaticSensitiveConfigKeyNginxKey1, - Actual: domain.DoguConfigValueState{Value: "val1", Exists: true}, - Expected: domain.DoguConfigValueState{Value: "nginxVal1", Exists: true}, - NeededAction: domain.ConfigActionSet, - DoguAlreadyInstalled: true, + Key: nginxStaticSensitiveConfigKeyNginxKey1, + Actual: domain.DoguConfigValueState{Value: "val1", Exists: true}, + Expected: domain.DoguConfigValueState{Value: "nginxVal1", Exists: true}, + NeededAction: domain.ConfigActionSet, }, { - Key: nginxStaticSensitiveConfigKeyNginxKey2, - Actual: domain.DoguConfigValueState{Value: "val2", Exists: true}, - Expected: domain.DoguConfigValueState{Value: "", Exists: false}, - NeededAction: domain.ConfigActionRemove, - DoguAlreadyInstalled: true, + Key: nginxStaticSensitiveConfigKeyNginxKey2, + Actual: domain.DoguConfigValueState{Value: "val2", Exists: true}, + Expected: domain.DoguConfigValueState{Value: "", Exists: false}, + NeededAction: domain.ConfigActionRemove, }, }, }, @@ -711,11 +711,6 @@ func TestStateDiffUseCase_collectEcosystemState(t *testing.T) { doguConfigNotFoundError := domainservice.NewNotFoundError(assert.AnError, "dogu config not found") sensitiveConfigNotFoundError := domainservice.NewNotFoundError(assert.AnError, "sensitive config not found") - encryptedEntry := &ecosystem.SensitiveDoguConfigEntry{ - Key: nginxStaticSensitiveConfigKeyNginxKey1, - Value: "val1", - } - doguInstallRepoMock := newMockDoguInstallationRepository(t) doguInstallRepoMock.EXPECT().GetAll(testCtx).Return(nil, nil) componentInstallRepoMock := newMockComponentInstallationRepository(t) @@ -726,22 +721,20 @@ func TestStateDiffUseCase_collectEcosystemState(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, globalConfigNotFoundError) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) + doguConfigRepoMock := newMockDoguConfigRepository(t) doguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, effectiveBlueprint.Config.GetDoguConfigKeys()). - Return( - map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, - doguConfigNotFoundError, - ) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) + GetAll(testCtx, effectiveBlueprint.Config.GetDogusWithChangedConfig()). + Return(map[config.SimpleDoguName]config.DoguConfig{}, doguConfigNotFoundError) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) + doguConfigEntries, entryErr := config.MapToEntries(map[string]any{ + "nginxKey1": "val1", + }) + require.NoError(t, entryErr) sensitiveDoguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, effectiveBlueprint.Config.GetSensitiveDoguConfigKeys()). - Return( - map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{ - nginxStaticSensitiveConfigKeyNginxKey1: encryptedEntry, - }, - sensitiveConfigNotFoundError, - ) + GetAll(testCtx, effectiveBlueprint.Config.GetDogusWithChangedSensitiveConfig()). + Return(map[config.SimpleDoguName]config.DoguConfig{ + nginxStatic: config.CreateDoguConfig(nginxStatic, doguConfigEntries), + }, sensitiveConfigNotFoundError) sut := NewStateDiffUseCase(nil, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) @@ -753,9 +746,9 @@ func TestStateDiffUseCase_collectEcosystemState(t *testing.T) { assert.Equal(t, ecosystem.EcosystemState{ GlobalConfig: globalConfig, - DoguConfig: map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, - SensitiveDoguConfig: map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{ - nginxStaticSensitiveConfigKeyNginxKey1: encryptedEntry, + ConfigByDogu: map[common.SimpleDoguName]config.DoguConfig{}, + SensitiveConfigByDogu: map[config.SimpleDoguName]config.DoguConfig{ + nginxStatic: config.CreateDoguConfig(nginxStatic, doguConfigEntries), }, }, ecosystemState) }) @@ -808,20 +801,14 @@ func TestStateDiffUseCase_collectEcosystemState(t *testing.T) { globalConfig := config.CreateGlobalConfig(entries) globalConfigRepoMock.EXPECT().Get(testCtx).Return(globalConfig, globalConfigNotFoundError) - doguConfigRepoMock := newMockDoguConfigEntryRepository(t) + doguConfigRepoMock := newMockDoguConfigRepository(t) doguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, effectiveBlueprint.Config.GetDoguConfigKeys()). - Return( - map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, - doguConfigNotFoundError, - ) - sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigEntryRepository(t) + GetAll(testCtx, effectiveBlueprint.Config.GetDogusWithChangedConfig()). + Return(map[config.SimpleDoguName]config.DoguConfig{}, doguConfigNotFoundError) + sensitiveDoguConfigRepoMock := newMockSensitiveDoguConfigRepository(t) sensitiveDoguConfigRepoMock.EXPECT(). - GetAllByKey(testCtx, effectiveBlueprint.Config.GetSensitiveDoguConfigKeys()). - Return( - map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, - internalTestError, - ) + GetAll(testCtx, effectiveBlueprint.Config.GetDogusWithChangedSensitiveConfig()). + Return(map[config.SimpleDoguName]config.DoguConfig{}, internalTestError) sut := NewStateDiffUseCase(nil, doguInstallRepoMock, componentInstallRepoMock, globalConfigRepoMock, doguConfigRepoMock, sensitiveDoguConfigRepoMock) diff --git a/pkg/bootstrap.go b/pkg/bootstrap.go index 5bed7ce..982619e 100644 --- a/pkg/bootstrap.go +++ b/pkg/bootstrap.go @@ -83,6 +83,10 @@ func Bootstrap(restConfig *rest.Config, eventRecorder record.EventRecorder, name doguConfigAdapter := adapterconfigetcd.NewDoguConfigRepository(configRegistry) sensitiveDoguConfigAdapter := adapterconfigetcd.NewSensitiveDoguConfigRepository(configRegistry) + k8sDoguConfigRepo := repository.NewDoguConfigRepository(ecosystemClientSet.CoreV1().ConfigMaps(namespace)) + doguConfigRepo := adapterconfigk8s.NewDoguConfigRepository(*k8sDoguConfigRepo) + k8sSensitiveDoguConfigRepo := repository.NewSensitiveDoguConfigRepository(ecosystemClientSet.CoreV1().Secrets(namespace)) + sensitiveDoguConfigRepo := adapterconfigk8s.NewSensitiveDoguConfigRepository(*k8sSensitiveDoguConfigRepo) k8sGlobalConfigRepo := repository.NewGlobalConfigRepository(ecosystemClientSet.CoreV1().ConfigMaps(namespace)) globalConfigRepoAdapter := adapterconfigk8s.NewGlobalConfigRepository(*k8sGlobalConfigRepo) @@ -95,7 +99,7 @@ func Bootstrap(restConfig *rest.Config, eventRecorder record.EventRecorder, name blueprintSpecDomainUseCase := domainservice.NewValidateDependenciesDomainUseCase(remoteDoguRegistry) blueprintValidationUseCase := application.NewBlueprintSpecValidationUseCase(blueprintSpecRepository, blueprintSpecDomainUseCase) effectiveBlueprintUseCase := application.NewEffectiveBlueprintUseCase(blueprintSpecRepository) - stateDiffUseCase := application.NewStateDiffUseCase(blueprintSpecRepository, doguInstallationRepo, componentInstallationRepo, globalConfigRepoAdapter, doguConfigAdapter, sensitiveDoguConfigAdapter) + stateDiffUseCase := application.NewStateDiffUseCase(blueprintSpecRepository, doguInstallationRepo, componentInstallationRepo, globalConfigRepoAdapter, doguConfigRepo, sensitiveDoguConfigRepo) doguInstallationUseCase := application.NewDoguInstallationUseCase(blueprintSpecRepository, doguInstallationRepo, healthConfigRepo) componentInstallationUseCase := application.NewComponentInstallationUseCase(blueprintSpecRepository, componentInstallationRepo, healthConfigRepo) ecosystemHealthUseCase := application.NewEcosystemHealthUseCase(doguInstallationUseCase, componentInstallationUseCase, healthConfigRepo) diff --git a/pkg/domain/blueprintSpec.go b/pkg/domain/blueprintSpec.go index 44cc67e..5224478 100644 --- a/pkg/domain/blueprintSpec.go +++ b/pkg/domain/blueprintSpec.go @@ -275,7 +275,9 @@ func (spec *BlueprintSpec) DetermineStateDiff( } doguConfigDiffs, globalConfigDiffs := determineConfigDiffs( spec.EffectiveBlueprint.Config, - ecosystemState, + ecosystemState.GlobalConfig, + ecosystemState.ConfigByDogu, + ecosystemState.SensitiveConfigByDogu, ) spec.StateDiff = StateDiff{ diff --git a/pkg/domain/config.go b/pkg/domain/config.go index 4110be6..5afe258 100644 --- a/pkg/domain/config.go +++ b/pkg/domain/config.go @@ -60,6 +60,28 @@ func (config Config) GetSensitiveDoguConfigKeys() []common.SensitiveDoguConfigKe return keys } +// GetDogusWithChangedConfig returns a list of dogus for which possible config changes are needed. +func (config Config) GetDogusWithChangedConfig() []common.SimpleDoguName { + var dogus []common.SimpleDoguName + for dogu, doguConfig := range config.Dogus { + if len(doguConfig.Config.Present) != 0 || len(doguConfig.Config.Absent) != 0 { + dogus = append(dogus, dogu) + } + } + return dogus +} + +// GetDogusWithChangedSensitiveConfig returns a list of dogus for which possible sensitive config changes are needed. +func (config Config) GetDogusWithChangedSensitiveConfig() []common.SimpleDoguName { + var dogus []common.SimpleDoguName + for dogu, doguConfig := range config.Dogus { + if len(doguConfig.SensitiveConfig.Present) != 0 || len(doguConfig.SensitiveConfig.Absent) != 0 { + dogus = append(dogus, dogu) + } + } + return dogus +} + // censorValues censors all sensitive configuration data to make them unrecognisable. func (config Config) censorValues() Config { for _, doguConfig := range config.Dogus { diff --git a/pkg/domain/ecosystem/EcosystemState.go b/pkg/domain/ecosystem/EcosystemState.go index 0b565a7..8b2dd3e 100644 --- a/pkg/domain/ecosystem/EcosystemState.go +++ b/pkg/domain/ecosystem/EcosystemState.go @@ -3,17 +3,12 @@ package ecosystem import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" "github.com/cloudogu/k8s-registry-lib/config" - "golang.org/x/exp/maps" ) type EcosystemState struct { - InstalledDogus map[common.SimpleDoguName]*DoguInstallation - InstalledComponents map[common.SimpleComponentName]*ComponentInstallation - GlobalConfig config.GlobalConfig - DoguConfig map[common.DoguConfigKey]*DoguConfigEntry - SensitiveDoguConfig map[common.SensitiveDoguConfigKey]*SensitiveDoguConfigEntry -} - -func (state EcosystemState) GetInstalledDoguNames() []common.SimpleDoguName { - return maps.Keys(state.InstalledDogus) + InstalledDogus map[common.SimpleDoguName]*DoguInstallation + InstalledComponents map[common.SimpleComponentName]*ComponentInstallation + GlobalConfig config.GlobalConfig + ConfigByDogu map[common.SimpleDoguName]config.DoguConfig + SensitiveConfigByDogu map[common.SimpleDoguName]config.DoguConfig } diff --git a/pkg/domain/ecosystem/EcosystemState_test.go b/pkg/domain/ecosystem/EcosystemState_test.go deleted file mode 100644 index 8f08b77..0000000 --- a/pkg/domain/ecosystem/EcosystemState_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package ecosystem - -import ( - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestEcosystemState_GetInstalledDoguNames(t *testing.T) { - nginx := common.SimpleDoguName("nginx") - officialNginx := common.QualifiedDoguName{ - Namespace: "official", - SimpleName: nginx, - } - state := EcosystemState{ - InstalledDogus: map[common.SimpleDoguName]*DoguInstallation{ - nginx: {Name: officialNginx}, - }, - } - - names := state.GetInstalledDoguNames() - - assert.Equal(t, []common.SimpleDoguName{nginx}, names) -} diff --git a/pkg/domain/stateDiffConfig.go b/pkg/domain/stateDiffConfig.go index eb9b720..33b094a 100644 --- a/pkg/domain/stateDiffConfig.go +++ b/pkg/domain/stateDiffConfig.go @@ -2,8 +2,7 @@ package domain import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - "slices" + "github.com/cloudogu/k8s-registry-lib/config" ) type CombinedDoguConfigDiffs struct { @@ -50,29 +49,28 @@ func countByAction(combinedDogusConfigDiffs map[common.SimpleDoguName]CombinedDo func determineConfigDiffs( blueprintConfig Config, - clusterState ecosystem.EcosystemState, + globalConfig config.GlobalConfig, + configByDogu map[common.SimpleDoguName]config.DoguConfig, + SensitiveConfigByDogu map[common.SimpleDoguName]config.DoguConfig, ) (map[common.SimpleDoguName]CombinedDoguConfigDiffs, GlobalConfigDiffs) { - - sensitiveConfig := map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{} - for key, entry := range clusterState.SensitiveDoguConfig { - sensitiveConfig[key] = entry.Value - } - - return determineDogusConfigDiffs(blueprintConfig.Dogus, clusterState.DoguConfig, sensitiveConfig, clusterState.GetInstalledDoguNames()), - determineGlobalConfigDiffs(blueprintConfig.Global, clusterState.GlobalConfig) + return determineDogusConfigDiffs( + blueprintConfig.Dogus, + configByDogu, + SensitiveConfigByDogu, + ), + determineGlobalConfigDiffs(blueprintConfig.Global, globalConfig) } func determineDogusConfigDiffs( combinedDoguConfigs map[common.SimpleDoguName]CombinedDoguConfig, - actualDoguConfig map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, - actualSensitiveDoguConfig map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue, - installedDogus []common.SimpleDoguName, + configByDogu map[common.SimpleDoguName]config.DoguConfig, + sensitiveConfigByDogu map[common.SimpleDoguName]config.DoguConfig, ) map[common.SimpleDoguName]CombinedDoguConfigDiffs { diffsPerDogu := map[common.SimpleDoguName]CombinedDoguConfigDiffs{} for doguName, combinedDoguConfig := range combinedDoguConfigs { diffsPerDogu[doguName] = CombinedDoguConfigDiffs{ - DoguConfigDiff: determineDoguConfigDiffs(combinedDoguConfig.Config, actualDoguConfig), - SensitiveDoguConfigDiff: determineSensitiveDoguConfigDiffs(combinedDoguConfig.SensitiveConfig, actualSensitiveDoguConfig, slices.Contains(installedDogus, doguName)), + DoguConfigDiff: determineDoguConfigDiffs(combinedDoguConfig.Config, configByDogu), + SensitiveDoguConfigDiff: determineSensitiveDoguConfigDiffs(combinedDoguConfig.SensitiveConfig, sensitiveConfigByDogu), } } return diffsPerDogu diff --git a/pkg/domain/stateDiffConfig_test.go b/pkg/domain/stateDiffConfig_test.go index 83d3b04..eb8f900 100644 --- a/pkg/domain/stateDiffConfig_test.go +++ b/pkg/domain/stateDiffConfig_test.go @@ -2,7 +2,6 @@ package domain import ( "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/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -10,11 +9,13 @@ import ( ) var ( - dogu1Key1 = common.DoguConfigKey{DoguName: "dogu1", Key: "key1"} - dogu1Key2 = common.DoguConfigKey{DoguName: "dogu1", Key: "key2"} - dogu1Key3 = common.DoguConfigKey{DoguName: "dogu1", Key: "key3"} - dogu1Key4 = common.DoguConfigKey{DoguName: "dogu1", Key: "key4"} - dogu2Key1 = common.DoguConfigKey{DoguName: "dogu2", Key: "key1"} + dogu1 = common.SimpleDoguName("dogu1") + dogu2 = common.SimpleDoguName("dogu2") + dogu1Key1 = common.DoguConfigKey{DoguName: dogu1, Key: "key1"} + dogu1Key2 = common.DoguConfigKey{DoguName: dogu1, Key: "key2"} + dogu1Key3 = common.DoguConfigKey{DoguName: dogu1, Key: "key3"} + dogu1Key4 = common.DoguConfigKey{DoguName: dogu1, Key: "key4"} + dogu2Key1 = common.DoguConfigKey{DoguName: dogu2, Key: "key1"} sensitiveDogu1Key1 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key1} sensitiveDogu1Key2 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key2} sensitiveDogu1Key3 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key3} @@ -26,8 +27,12 @@ func Test_determineConfigDiff(t *testing.T) { t.Run("empty", func(t *testing.T) { emptyConfig := Config{} - clusterState := ecosystem.EcosystemState{} - dogusConfigDiffs, globalConfigDiff := determineConfigDiffs(emptyConfig, clusterState) + dogusConfigDiffs, globalConfigDiff := determineConfigDiffs( + emptyConfig, + config.CreateGlobalConfig(map[config.Key]config.Value{}), + map[common.SimpleDoguName]config.DoguConfig{}, + map[common.SimpleDoguName]config.DoguConfig{}, + ) assert.Equal(t, map[common.SimpleDoguName]CombinedDoguConfigDiffs{}, dogusConfigDiffs) assert.Equal(t, GlobalConfigDiffs(nil), globalConfigDiff) @@ -42,11 +47,6 @@ func Test_determineConfigDiff(t *testing.T) { // key4 is absent -> action none }) globalConfig := config.CreateGlobalConfig(entries) - clusterState := ecosystem.EcosystemState{ - GlobalConfig: globalConfig, - DoguConfig: map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{}, - SensitiveDoguConfig: map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, - } //given blueprint config givenConfig := Config{ Global: GlobalConfig{ @@ -61,7 +61,12 @@ func Test_determineConfigDiff(t *testing.T) { } //when - dogusConfigDiffs, globalConfigDiff := determineConfigDiffs(givenConfig, clusterState) + dogusConfigDiffs, globalConfigDiff := determineConfigDiffs( + givenConfig, + globalConfig, + map[common.SimpleDoguName]config.DoguConfig{}, + map[common.SimpleDoguName]config.DoguConfig{}, + ) //then assert.Equal(t, map[common.SimpleDoguName]CombinedDoguConfigDiffs{}, dogusConfigDiffs) @@ -116,21 +121,17 @@ func Test_determineConfigDiff(t *testing.T) { }) }) t.Run("all actions normal dogu config", func(t *testing.T) { - - entries, _ := config.MapToEntries(map[string]any{}) - globalConfig := config.CreateGlobalConfig(entries) //given ecosystem config - clusterState := ecosystem.EcosystemState{ - GlobalConfig: globalConfig, - DoguConfig: map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{ - dogu1Key1: {Key: dogu1Key1, Value: "value"}, //action none - dogu1Key2: {Key: dogu1Key2, Value: "value"}, //action set - dogu1Key3: {Key: dogu1Key3, Value: "value"}, //action delete - //dogu1Key4 -> absent, so action none - }, - SensitiveDoguConfig: map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{}, - InstalledDogus: map[common.SimpleDoguName]*ecosystem.DoguInstallation{"dogu1": {}}, - } + globalConfigEntries, _ := config.MapToEntries(map[string]any{}) + globalConfig := config.CreateGlobalConfig(globalConfigEntries) + + doguConfigEntries, _ := config.MapToEntries(map[string]any{ + "key1": "value", //action none + "key2": "value", //action set + "key3": "value", //action delete + //key4 -> absent, so action none + }) + doguConfig := config.CreateDoguConfig(dogu1, doguConfigEntries) //given blueprint config givenConfig := Config{ @@ -151,7 +152,14 @@ func Test_determineConfigDiff(t *testing.T) { } //when - dogusConfigDiffs, globalConfigDiff := determineConfigDiffs(givenConfig, clusterState) + dogusConfigDiffs, globalConfigDiff := determineConfigDiffs( + givenConfig, + globalConfig, + map[common.SimpleDoguName]config.DoguConfig{ + dogu1: doguConfig, + }, + map[common.SimpleDoguName]config.DoguConfig{}, + ) //then assert.Equal(t, GlobalConfigDiffs(nil), globalConfigDiff) require.NotNil(t, dogusConfigDiffs["dogu1"]) @@ -212,16 +220,15 @@ func Test_determineConfigDiff(t *testing.T) { }) t.Run("all actions for sensitive dogu config for present dogu", func(t *testing.T) { //given ecosystem config - clusterState := ecosystem.EcosystemState{ - SensitiveDoguConfig: map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{ - sensitiveDogu1Key1: {Key: sensitiveDogu1Key1, Value: "value"}, //action none - sensitiveDogu1Key2: {Key: sensitiveDogu1Key2, Value: "value"}, //action set - sensitiveDogu1Key3: {Key: sensitiveDogu1Key3, Value: "value"}, //action setEncrypted - //sensitiveDogu1Key4 absent, action none - //sensitiveDogu2Key1 absent, action setToEncrypt - }, - InstalledDogus: map[common.SimpleDoguName]*ecosystem.DoguInstallation{"dogu1": {}}, - } + globalConfigEntries, _ := config.MapToEntries(map[string]any{}) + globalConfig := config.CreateGlobalConfig(globalConfigEntries) + + sensitiveDoguConfigEntries, _ := config.MapToEntries(map[string]any{ + "key1": "value", //action none + "key2": "value", //action set + //key3 absent, action none + }) + sensitiveDoguConfig := config.CreateDoguConfig(dogu1, sensitiveDoguConfigEntries) //given blueprint config givenConfig := Config{ @@ -235,14 +242,6 @@ func Test_determineConfigDiff(t *testing.T) { }, Absent: []common.SensitiveDoguConfigKey{ sensitiveDogu1Key3, - sensitiveDogu1Key4, - }, - }, - }, - "dogu2": { - SensitiveConfig: SensitiveDoguConfig{ - Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - sensitiveDogu2Key1: "value", }, }, }, @@ -250,18 +249,23 @@ func Test_determineConfigDiff(t *testing.T) { } //when - dogusConfigDiffs, globalConfigDiff := determineConfigDiffs(givenConfig, clusterState) + dogusConfigDiffs, globalConfigDiff := determineConfigDiffs( + givenConfig, + globalConfig, + map[common.SimpleDoguName]config.DoguConfig{}, + map[common.SimpleDoguName]config.DoguConfig{ + dogu1: sensitiveDoguConfig, + }, + ) //then assert.Equal(t, GlobalConfigDiffs(nil), globalConfigDiff) require.NotNil(t, dogusConfigDiffs["dogu1"]) assert.Equal(t, DoguConfigDiffs(nil), dogusConfigDiffs["dogu1"].DoguConfigDiff) - assert.Equal(t, 4, len(dogusConfigDiffs["dogu1"].SensitiveDoguConfigDiff)) - assert.Equal(t, 1, len(dogusConfigDiffs["dogu2"].SensitiveDoguConfigDiff)) + assert.Equal(t, 3, len(dogusConfigDiffs["dogu1"].SensitiveDoguConfigDiff)) entriesDogu1 := []SensitiveDoguConfigEntryDiff{ { - Key: sensitiveDogu1Key1, - DoguAlreadyInstalled: true, + Key: sensitiveDogu1Key1, Actual: DoguConfigValueState{ Value: "value", Exists: true, @@ -273,8 +277,7 @@ func Test_determineConfigDiff(t *testing.T) { NeededAction: ConfigActionNone, }, { - Key: sensitiveDogu1Key2, - DoguAlreadyInstalled: true, + Key: sensitiveDogu1Key2, Actual: DoguConfigValueState{ Value: "value", Exists: true, @@ -286,21 +289,7 @@ func Test_determineConfigDiff(t *testing.T) { NeededAction: ConfigActionSet, }, { - Key: sensitiveDogu1Key3, - DoguAlreadyInstalled: true, - Actual: DoguConfigValueState{ - Value: "value", - Exists: true, - }, - Expected: DoguConfigValueState{ - Value: "", - Exists: false, - }, - NeededAction: ConfigActionRemove, - }, - { - Key: sensitiveDogu1Key4, - DoguAlreadyInstalled: true, + Key: sensitiveDogu1Key3, Actual: DoguConfigValueState{ Value: "", Exists: false, @@ -312,27 +301,18 @@ func Test_determineConfigDiff(t *testing.T) { NeededAction: ConfigActionNone, }, } - entriesDogu2 := []SensitiveDoguConfigEntryDiff{ - { - Key: sensitiveDogu2Key1, - DoguAlreadyInstalled: false, - Actual: DoguConfigValueState{ - Value: "", - Exists: false, - }, - Expected: DoguConfigValueState{ - Value: "value", - Exists: true, - }, - NeededAction: ConfigActionSet, - }, - } assert.ElementsMatch(t, dogusConfigDiffs["dogu1"].SensitiveDoguConfigDiff, entriesDogu1) - assert.ElementsMatch(t, dogusConfigDiffs["dogu2"].SensitiveDoguConfigDiff, entriesDogu2) }) t.Run("all actions for sensitive dogu config for absent dogu", func(t *testing.T) { //given ecosystem config - clusterState := ecosystem.EcosystemState{} + globalConfigEntries, _ := config.MapToEntries(map[string]any{}) + globalConfig := config.CreateGlobalConfig(globalConfigEntries) + + doguConfigEntries, _ := config.MapToEntries(map[string]any{}) + doguConfig := config.CreateDoguConfig(dogu1, doguConfigEntries) + + sensitiveDoguConfigEntries, _ := config.MapToEntries(map[string]any{}) + sensitiveDoguConfig := config.CreateDoguConfig(dogu1, sensitiveDoguConfigEntries) //given blueprint config givenConfig := Config{ @@ -350,13 +330,21 @@ func Test_determineConfigDiff(t *testing.T) { } //when - dogusConfigDiffs, _ := determineConfigDiffs(givenConfig, clusterState) + dogusConfigDiffs, _ := determineConfigDiffs( + givenConfig, + globalConfig, + map[common.SimpleDoguName]config.DoguConfig{ + dogu1: doguConfig, + }, + map[common.SimpleDoguName]config.DoguConfig{ + dogu1: sensitiveDoguConfig, + }, + ) //then require.NotNil(t, dogusConfigDiffs["dogu1"]) require.Equal(t, 1, len(dogusConfigDiffs["dogu1"].SensitiveDoguConfigDiff)) assert.Equal(t, dogusConfigDiffs["dogu1"].SensitiveDoguConfigDiff[0], SensitiveDoguConfigEntryDiff{ - Key: sensitiveDogu1Key1, - DoguAlreadyInstalled: false, + Key: sensitiveDogu1Key1, Actual: DoguConfigValueState{ Value: "", Exists: false, diff --git a/pkg/domain/stateDiffDoguConfig.go b/pkg/domain/stateDiffDoguConfig.go index cbb0850..e25e774 100644 --- a/pkg/domain/stateDiffDoguConfig.go +++ b/pkg/domain/stateDiffDoguConfig.go @@ -2,8 +2,8 @@ package domain import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" "github.com/cloudogu/k8s-blueprint-operator/pkg/util" + "github.com/cloudogu/k8s-registry-lib/config" ) type DoguConfigDiffs []DoguConfigEntryDiff @@ -27,24 +27,17 @@ type DoguConfigEntryDiff struct { NeededAction ConfigAction } -func NewDoguConfigValueStateFromEntry(actualEntry *ecosystem.DoguConfigEntry) DoguConfigValueState { - actualValue := common.DoguConfigValue("") - if actualEntry != nil { - actualValue = actualEntry.Value - } - return DoguConfigValueState{ - Value: string(actualValue), - Exists: actualEntry != nil, - } -} - func newDoguConfigEntryDiff( key common.DoguConfigKey, - actualEntry *ecosystem.DoguConfigEntry, + actualValue config.Value, + actualExists bool, expectedValue common.DoguConfigValue, expectedExists bool, ) DoguConfigEntryDiff { - actual := NewDoguConfigValueStateFromEntry(actualEntry) + actual := DoguConfigValueState{ + Value: string(actualValue), + Exists: actualExists, + } expected := DoguConfigValueState{ Value: string(expectedValue), Exists: expectedExists, @@ -58,19 +51,19 @@ func newDoguConfigEntryDiff( } func determineDoguConfigDiffs( - config DoguConfig, - actualDoguConfig map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, + wantedConfig DoguConfig, + actualConfig map[common.SimpleDoguName]config.DoguConfig, ) DoguConfigDiffs { var doguConfigDiff []DoguConfigEntryDiff // present entries - for key, expectedValue := range config.Present { - actualEntry := actualDoguConfig[key] - doguConfigDiff = append(doguConfigDiff, newDoguConfigEntryDiff(key, actualEntry, expectedValue, true)) + for key, expectedValue := range wantedConfig.Present { + actualEntry, exists := actualConfig[key.DoguName].Get(key.Key) + doguConfigDiff = append(doguConfigDiff, newDoguConfigEntryDiff(key, actualEntry, exists, expectedValue, true)) } // absent entries - for _, key := range config.Absent { - actualEntry := actualDoguConfig[key] - doguConfigDiff = append(doguConfigDiff, newDoguConfigEntryDiff(key, actualEntry, "", false)) + for _, key := range wantedConfig.Absent { + actualEntry, exists := actualConfig[key.DoguName].Get(key.Key) + doguConfigDiff = append(doguConfigDiff, newDoguConfigEntryDiff(key, actualEntry, exists, "", false)) } return doguConfigDiff } diff --git a/pkg/domain/stateDiffGlobalConfig.go b/pkg/domain/stateDiffGlobalConfig.go index 53d7b4b..0131ec2 100644 --- a/pkg/domain/stateDiffGlobalConfig.go +++ b/pkg/domain/stateDiffGlobalConfig.go @@ -2,7 +2,6 @@ package domain import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" "github.com/cloudogu/k8s-blueprint-operator/pkg/util" "github.com/cloudogu/k8s-registry-lib/config" ) @@ -32,17 +31,6 @@ type GlobalConfigEntryDiff struct { NeededAction ConfigAction } -func NewGlobalConfigValueStateFromEntry(actualEntry *ecosystem.GlobalConfigEntry) GlobalConfigValueState { - actualValue := common.GlobalConfigValue("") - if actualEntry != nil { - actualValue = actualEntry.Value - } - return GlobalConfigValueState{ - Value: string(actualValue), - Exists: actualEntry != nil, - } -} - func (diffs GlobalConfigDiffs) countByAction() map[ConfigAction]int { countByAction := map[ConfigAction]int{} for _, diff := range diffs { @@ -76,18 +64,18 @@ func newGlobalConfigEntryDiff( func determineGlobalConfigDiffs( config GlobalConfig, - actualDoguConfig config.GlobalConfig, + actualConfig config.GlobalConfig, ) GlobalConfigDiffs { var configDiffs []GlobalConfigEntryDiff // present entries for key, expectedValue := range config.Present { - actualEntry, actualExists := actualDoguConfig.Get(key) + actualEntry, actualExists := actualConfig.Get(key) configDiffs = append(configDiffs, newGlobalConfigEntryDiff(key, actualEntry, actualExists, expectedValue, true)) } // absent entries for _, key := range config.Absent { - actualEntry, actualExists := actualDoguConfig.Get(key) + actualEntry, actualExists := actualConfig.Get(key) configDiffs = append(configDiffs, newGlobalConfigEntryDiff(key, actualEntry, actualExists, "", false)) } return configDiffs diff --git a/pkg/domain/stateDiffSensitiveDoguConfig.go b/pkg/domain/stateDiffSensitiveDoguConfig.go index d880bb6..516cd66 100644 --- a/pkg/domain/stateDiffSensitiveDoguConfig.go +++ b/pkg/domain/stateDiffSensitiveDoguConfig.go @@ -3,6 +3,7 @@ package domain import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" "github.com/cloudogu/k8s-blueprint-operator/pkg/util" + "github.com/cloudogu/k8s-registry-lib/config" ) type SensitiveDoguConfigDiffs []SensitiveDoguConfigEntryDiff @@ -14,21 +15,10 @@ func (diffs SensitiveDoguConfigDiffs) GetSensitiveDoguConfigDiffByAction() map[C } type SensitiveDoguConfigEntryDiff struct { - Key common.SensitiveDoguConfigKey - Actual DoguConfigValueState - Expected DoguConfigValueState - DoguAlreadyInstalled bool - NeededAction ConfigAction -} - -func NewDoguConfigValueStateFromSensitiveValue(actualValue common.SensitiveDoguConfigValue, actualExists bool) DoguConfigValueState { - if !actualExists { - actualValue = "" - } - return DoguConfigValueState{ - Value: string(actualValue), - Exists: actualExists, - } + Key common.SensitiveDoguConfigKey + Actual DoguConfigValueState + Expected DoguConfigValueState + NeededAction ConfigAction } func newSensitiveDoguConfigEntryDiff( @@ -37,37 +27,37 @@ func newSensitiveDoguConfigEntryDiff( actualExists bool, expectedValue common.SensitiveDoguConfigValue, expectedExists bool, - doguAlreadyInstalled bool, ) SensitiveDoguConfigEntryDiff { - actual := NewDoguConfigValueStateFromSensitiveValue(actualValue, actualExists) + actual := DoguConfigValueState{ + Value: string(actualValue), + Exists: actualExists, + } expected := DoguConfigValueState{ Value: string(expectedValue), Exists: expectedExists, } return SensitiveDoguConfigEntryDiff{ - Key: key, - Actual: actual, - Expected: expected, - DoguAlreadyInstalled: doguAlreadyInstalled, - NeededAction: getNeededConfigAction(ConfigValueState(expected), ConfigValueState(actual)), + Key: key, + Actual: actual, + Expected: expected, + NeededAction: getNeededConfigAction(ConfigValueState(expected), ConfigValueState(actual)), } } func determineSensitiveDoguConfigDiffs( - config SensitiveDoguConfig, - actualDoguConfig map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue, - doguAlreadyInstalled bool, + wantedConfig SensitiveDoguConfig, + actualConfig map[common.SimpleDoguName]config.DoguConfig, ) SensitiveDoguConfigDiffs { var doguConfigDiff []SensitiveDoguConfigEntryDiff // present entries - for key, expectedValue := range config.Present { - actualValue, actualExists := actualDoguConfig[key] - doguConfigDiff = append(doguConfigDiff, newSensitiveDoguConfigEntryDiff(key, actualValue, actualExists, expectedValue, true, doguAlreadyInstalled)) + for key, expectedValue := range wantedConfig.Present { + actualEntry, exists := actualConfig[key.DoguName].Get(key.Key) + doguConfigDiff = append(doguConfigDiff, newSensitiveDoguConfigEntryDiff(key, actualEntry, exists, expectedValue, true)) } // absent entries - for _, key := range config.Absent { - actualValue, actualExists := actualDoguConfig[key] - doguConfigDiff = append(doguConfigDiff, newSensitiveDoguConfigEntryDiff(key, actualValue, actualExists, "", false, doguAlreadyInstalled)) + for _, key := range wantedConfig.Absent { + actualEntry, exists := actualConfig[key.DoguName].Get(key.Key) + doguConfigDiff = append(doguConfigDiff, newSensitiveDoguConfigEntryDiff(key, actualEntry, exists, "", false)) } return doguConfigDiff } diff --git a/pkg/domainservice/adapterInterfaces.go b/pkg/domainservice/adapterInterfaces.go index 4d877a9..4742596 100644 --- a/pkg/domainservice/adapterInterfaces.go +++ b/pkg/domainservice/adapterInterfaces.go @@ -155,12 +155,14 @@ type GlobalConfigRepository interface { // DoguConfigRepository TODO: add go doc, especially for errors type DoguConfigRepository interface { Get(ctx context.Context, doguName common.SimpleDoguName) (config.DoguConfig, error) + GetAll(ctx context.Context, doguNames []common.SimpleDoguName) (map[common.SimpleDoguName]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) + GetAll(ctx context.Context, doguNames []common.SimpleDoguName) (map[common.SimpleDoguName]config.DoguConfig, error) Update(ctx context.Context, config config.DoguConfig) (config.DoguConfig, error) } diff --git a/pkg/domainservice/mock_DoguConfigRepository_test.go b/pkg/domainservice/mock_DoguConfigRepository_test.go index 654c696..854e7ce 100644 --- a/pkg/domainservice/mock_DoguConfigRepository_test.go +++ b/pkg/domainservice/mock_DoguConfigRepository_test.go @@ -80,6 +80,65 @@ func (_c *MockDoguConfigRepository_Get_Call) RunAndReturn(run func(context.Conte return _c } +// GetAll provides a mock function with given fields: ctx, doguNames +func (_m *MockDoguConfigRepository) GetAll(ctx context.Context, doguNames []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error) { + ret := _m.Called(ctx, doguNames) + + if len(ret) == 0 { + panic("no return value specified for GetAll") + } + + var r0 map[config.SimpleDoguName]config.DoguConfig + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)); ok { + return rf(ctx, doguNames) + } + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) map[config.SimpleDoguName]config.DoguConfig); ok { + r0 = rf(ctx, doguNames) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[config.SimpleDoguName]config.DoguConfig) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []config.SimpleDoguName) error); ok { + r1 = rf(ctx, doguNames) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDoguConfigRepository_GetAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAll' +type MockDoguConfigRepository_GetAll_Call struct { + *mock.Call +} + +// GetAll is a helper method to define mock.On call +// - ctx context.Context +// - doguNames []config.SimpleDoguName +func (_e *MockDoguConfigRepository_Expecter) GetAll(ctx interface{}, doguNames interface{}) *MockDoguConfigRepository_GetAll_Call { + return &MockDoguConfigRepository_GetAll_Call{Call: _e.mock.On("GetAll", ctx, doguNames)} +} + +func (_c *MockDoguConfigRepository_GetAll_Call) Run(run func(ctx context.Context, doguNames []config.SimpleDoguName)) *MockDoguConfigRepository_GetAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]config.SimpleDoguName)) + }) + return _c +} + +func (_c *MockDoguConfigRepository_GetAll_Call) Return(_a0 map[config.SimpleDoguName]config.DoguConfig, _a1 error) *MockDoguConfigRepository_GetAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDoguConfigRepository_GetAll_Call) RunAndReturn(run func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)) *MockDoguConfigRepository_GetAll_Call { + _c.Call.Return(run) + return _c +} + // Update provides a mock function with given fields: ctx, _a1 func (_m *MockDoguConfigRepository) Update(ctx context.Context, _a1 config.DoguConfig) (config.DoguConfig, error) { ret := _m.Called(ctx, _a1) diff --git a/pkg/domainservice/mock_SensitiveDoguConfigRepository_test.go b/pkg/domainservice/mock_SensitiveDoguConfigRepository_test.go index 82e3f7b..2d1b903 100644 --- a/pkg/domainservice/mock_SensitiveDoguConfigRepository_test.go +++ b/pkg/domainservice/mock_SensitiveDoguConfigRepository_test.go @@ -80,6 +80,65 @@ func (_c *MockSensitiveDoguConfigRepository_Get_Call) RunAndReturn(run func(cont return _c } +// GetAll provides a mock function with given fields: ctx, doguNames +func (_m *MockSensitiveDoguConfigRepository) GetAll(ctx context.Context, doguNames []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error) { + ret := _m.Called(ctx, doguNames) + + if len(ret) == 0 { + panic("no return value specified for GetAll") + } + + var r0 map[config.SimpleDoguName]config.DoguConfig + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)); ok { + return rf(ctx, doguNames) + } + if rf, ok := ret.Get(0).(func(context.Context, []config.SimpleDoguName) map[config.SimpleDoguName]config.DoguConfig); ok { + r0 = rf(ctx, doguNames) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[config.SimpleDoguName]config.DoguConfig) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []config.SimpleDoguName) error); ok { + r1 = rf(ctx, doguNames) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSensitiveDoguConfigRepository_GetAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAll' +type MockSensitiveDoguConfigRepository_GetAll_Call struct { + *mock.Call +} + +// GetAll is a helper method to define mock.On call +// - ctx context.Context +// - doguNames []config.SimpleDoguName +func (_e *MockSensitiveDoguConfigRepository_Expecter) GetAll(ctx interface{}, doguNames interface{}) *MockSensitiveDoguConfigRepository_GetAll_Call { + return &MockSensitiveDoguConfigRepository_GetAll_Call{Call: _e.mock.On("GetAll", ctx, doguNames)} +} + +func (_c *MockSensitiveDoguConfigRepository_GetAll_Call) Run(run func(ctx context.Context, doguNames []config.SimpleDoguName)) *MockSensitiveDoguConfigRepository_GetAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]config.SimpleDoguName)) + }) + return _c +} + +func (_c *MockSensitiveDoguConfigRepository_GetAll_Call) Return(_a0 map[config.SimpleDoguName]config.DoguConfig, _a1 error) *MockSensitiveDoguConfigRepository_GetAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSensitiveDoguConfigRepository_GetAll_Call) RunAndReturn(run func(context.Context, []config.SimpleDoguName) (map[config.SimpleDoguName]config.DoguConfig, error)) *MockSensitiveDoguConfigRepository_GetAll_Call { + _c.Call.Return(run) + return _c +} + // Update provides a mock function with given fields: ctx, _a1 func (_m *MockSensitiveDoguConfigRepository) Update(ctx context.Context, _a1 config.DoguConfig) (config.DoguConfig, error) { ret := _m.Called(ctx, _a1)