Skip to content

Commit

Permalink
#81 WIP remove CombinedDoguConfigDiffs
Browse files Browse the repository at this point in the history
deepcopy functions needed to be regenerated but
this does not work because of an interface type
in old code. I don't know that should have
worked before.
  • Loading branch information
alexander-dammeier committed Nov 1, 2024
1 parent 4f4ec23 commit e20c514
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 279 deletions.
89 changes: 12 additions & 77 deletions pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,18 @@ type DoguConfigEntryDiff struct {
NeededAction ConfigAction `json:"neededAction"`
}

type SensitiveDoguConfigDiff []SensitiveDoguConfigEntryDiff
type SensitiveDoguConfigEntryDiff struct {
Key string `json:"key"`
Actual DoguConfigValueState `json:"actual"`
Expected DoguConfigValueState `json:"expected"`
NeededAction ConfigAction `json:"neededAction"`
}
type SensitiveDoguConfigDiff = DoguConfigDiff
type SensitiveDoguConfigEntryDiff = DoguConfigEntryDiff

func convertToCombinedDoguConfigDiffDomain(doguName string, dto CombinedDoguConfigDiff) domain.CombinedDoguConfigDiffs {
func convertToDoguConfigDiffsDomain(doguName string, dto DoguConfigDiff) domain.DoguConfigDiffs {
var doguConfigDiff domain.DoguConfigDiffs
if len(dto.DoguConfigDiff) != 0 {
doguConfigDiff = make(domain.DoguConfigDiffs, len(dto.DoguConfigDiff))
for i, entryDiff := range dto.DoguConfigDiff {
if len(dto) != 0 {
doguConfigDiff = make(domain.DoguConfigDiffs, len(dto))
for i, entryDiff := range dto {
doguConfigDiff[i] = convertToDoguConfigEntryDiffDomain(doguName, entryDiff)
}
}

var sensitiveDoguConfigDiff domain.SensitiveDoguConfigDiffs
if len(dto.SensitiveDoguConfigDiff) != 0 {
sensitiveDoguConfigDiff = make(domain.SensitiveDoguConfigDiffs, len(dto.SensitiveDoguConfigDiff))
for i, entryDiff := range dto.SensitiveDoguConfigDiff {
sensitiveDoguConfigDiff[i] = convertToSensitiveDoguConfigEntryDiffDomain(doguName, entryDiff)
}
}

return domain.CombinedDoguConfigDiffs{
DoguConfigDiff: doguConfigDiff,
SensitiveDoguConfigDiff: sensitiveDoguConfigDiff,
}
return doguConfigDiff
}

func convertToDoguConfigEntryDiffDomain(doguName string, dto DoguConfigEntryDiff) domain.DoguConfigEntryDiff {
Expand All @@ -70,45 +53,12 @@ func convertToDoguConfigEntryDiffDomain(doguName string, dto DoguConfigEntryDiff
}
}

func convertToSensitiveDoguConfigEntryDiffDomain(doguName string, dto SensitiveDoguConfigEntryDiff) domain.SensitiveDoguConfigEntryDiff {
return domain.SensitiveDoguConfigEntryDiff{
Key: common.SensitiveDoguConfigKey{
DoguName: common.SimpleDoguName(doguName),
Key: config.Key(dto.Key),
},
Actual: domain.DoguConfigValueState{
Value: dto.Actual.Value,
Exists: dto.Actual.Exists,
},
Expected: domain.DoguConfigValueState{
Value: dto.Expected.Value,
Exists: dto.Expected.Exists,
},
NeededAction: domain.ConfigAction(dto.NeededAction),
}
}

func convertToCombinedDoguConfigDiffDTO(domainModel domain.CombinedDoguConfigDiffs) CombinedDoguConfigDiff {
var doguConfigDiff DoguConfigDiff
if len(domainModel.DoguConfigDiff) != 0 {
doguConfigDiff = make(DoguConfigDiff, len(domainModel.DoguConfigDiff))
for i, entryDiff := range domainModel.DoguConfigDiff {
doguConfigDiff[i] = convertToDoguConfigEntryDiffDTO(entryDiff)
}
}

var sensitiveDoguConfigDiff SensitiveDoguConfigDiff
if len(domainModel.SensitiveDoguConfigDiff) != 0 {
sensitiveDoguConfigDiff = make(SensitiveDoguConfigDiff, len(domainModel.SensitiveDoguConfigDiff))
for i, entryDiff := range domainModel.SensitiveDoguConfigDiff {
sensitiveDoguConfigDiff[i] = convertToSensitiveDoguConfigEntryDiffDTO(entryDiff)
}
}

return CombinedDoguConfigDiff{
DoguConfigDiff: doguConfigDiff,
SensitiveDoguConfigDiff: sensitiveDoguConfigDiff,
func convertToDoguConfigEntryDiffsDTO(domainDiffs domain.DoguConfigDiffs) []DoguConfigEntryDiff {
var dtoDiffs []DoguConfigEntryDiff
for _, domainDiff := range domainDiffs {
dtoDiffs = append(dtoDiffs, convertToDoguConfigEntryDiffDTO(domainDiff))
}
return dtoDiffs
}

func convertToDoguConfigEntryDiffDTO(domainModel domain.DoguConfigEntryDiff) DoguConfigEntryDiff {
Expand All @@ -125,18 +75,3 @@ func convertToDoguConfigEntryDiffDTO(domainModel domain.DoguConfigEntryDiff) Dog
NeededAction: ConfigAction(domainModel.NeededAction),
}
}

func convertToSensitiveDoguConfigEntryDiffDTO(domainModel domain.SensitiveDoguConfigEntryDiff) SensitiveDoguConfigEntryDiff {
return SensitiveDoguConfigEntryDiff{
Key: string(domainModel.Key.Key),
Actual: DoguConfigValueState{
Value: domainModel.Actual.Value,
Exists: domainModel.Actual.Exists,
},
Expected: DoguConfigValueState{
Value: domainModel.Expected.Value,
Exists: domainModel.Expected.Exists,
},
NeededAction: ConfigAction(domainModel.NeededAction),
}
}
45 changes: 34 additions & 11 deletions pkg/adapter/kubernetes/blueprintcr/v1/stateDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain"
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common"
"slices"
)

// StateDiff is the result of comparing the EffectiveBlueprint to the current cluster state.
Expand All @@ -31,18 +32,36 @@ func ConvertToStateDiffDTO(domainModel domain.StateDiff) StateDiff {
componentDiffsV1[string(componentDiff.Name)] = convertToComponentDiffDTO(componentDiff)
}

var doguConfigDiffs map[string]CombinedDoguConfigDiff
var dogus []common.SimpleDoguName
var combinedConfigDiffs map[string]CombinedDoguConfigDiff
var doguConfigDiffByDogu map[common.SimpleDoguName]DoguConfigDiff
var sensitiveDoguConfigDiff map[common.SimpleDoguName]SensitiveDoguConfigDiff

if len(domainModel.DoguConfigDiffs) != 0 {
doguConfigDiffs = make(map[string]CombinedDoguConfigDiff)
combinedConfigDiffs = make(map[string]CombinedDoguConfigDiff)
for doguName, doguConfigDiff := range domainModel.DoguConfigDiffs {
doguConfigDiffs[string(doguName)] = convertToCombinedDoguConfigDiffDTO(doguConfigDiff)
doguConfigDiffByDogu[doguName] = convertToDoguConfigEntryDiffsDTO(doguConfigDiff)
dogus = append(dogus, doguName)
}
for doguName, doguConfigDiff := range domainModel.SensitiveDoguConfigDiffs {
sensitiveDoguConfigDiff[doguName] = convertToDoguConfigEntryDiffsDTO(doguConfigDiff)
dogus = append(dogus, doguName)
}

//remove duplicates, so we have a complete list of all dogus with config
dogus = slices.Compact(dogus)
for _, doguName := range dogus {
combinedConfigDiffs[string(doguName)] = CombinedDoguConfigDiff{
DoguConfigDiff: doguConfigDiffByDogu[doguName],
SensitiveDoguConfigDiff: sensitiveDoguConfigDiff[doguName],
}
}
}

return StateDiff{
DoguDiffs: doguDiffs,
ComponentDiffs: componentDiffsV1,
DoguConfigDiffs: doguConfigDiffs,
DoguConfigDiffs: combinedConfigDiffs,
GlobalConfigDiff: convertToGlobalConfigDiffDTO(domainModel.GlobalConfigDiffs),
}
}
Expand All @@ -69,18 +88,22 @@ func ConvertToStateDiffDomain(dto StateDiff) (domain.StateDiff, error) {
return domain.StateDiff{}, fmt.Errorf("failed to convert state diff DTO to domain model: %w", err)
}

var doguConfigDiffs map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs
var doguConfigDiffs map[common.SimpleDoguName]domain.DoguConfigDiffs
var sensitiveDoguConfigDiffs map[common.SimpleDoguName]domain.SensitiveDoguConfigDiffs
if len(dto.DoguConfigDiffs) != 0 {
doguConfigDiffs = make(map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs)
doguConfigDiffs = map[common.SimpleDoguName]domain.DoguConfigDiffs{}
sensitiveDoguConfigDiffs = map[common.SimpleDoguName]domain.SensitiveDoguConfigDiffs{}
for doguName, doguConfigDiff := range dto.DoguConfigDiffs {
doguConfigDiffs[common.SimpleDoguName(doguName)] = convertToCombinedDoguConfigDiffDomain(doguName, doguConfigDiff)
doguConfigDiffs[common.SimpleDoguName(doguName)] = convertToDoguConfigDiffsDomain(doguName, doguConfigDiff.DoguConfigDiff)
sensitiveDoguConfigDiffs[common.SimpleDoguName(doguName)] = convertToDoguConfigDiffsDomain(doguName, doguConfigDiff.SensitiveDoguConfigDiff)
}
}

return domain.StateDiff{
DoguDiffs: doguDiffs,
ComponentDiffs: componentDiffs,
DoguConfigDiffs: doguConfigDiffs,
GlobalConfigDiffs: convertToGlobalConfigDiffDomain(dto.GlobalConfigDiff),
DoguDiffs: doguDiffs,
ComponentDiffs: componentDiffs,
DoguConfigDiffs: doguConfigDiffs,
SensitiveDoguConfigDiffs: sensitiveDoguConfigDiffs,
GlobalConfigDiffs: convertToGlobalConfigDiffDomain(dto.GlobalConfigDiff),
}, nil
}
Loading

0 comments on commit e20c514

Please sign in to comment.