Skip to content

Commit

Permalink
Don't use pointer as map key.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Oct 9, 2023
1 parent 6098a9b commit b0a2489
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions cmd/metal-api/internal/issues/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type (
// MachineIssues is map of a machine response to a list of machine issues
MachineIssues []*MachineWithIssues

MachineIssuesMap map[*metal.Machine]Issues
MachineIssuesMap map[string]*MachineWithIssues

issue interface {
// Evaluate decides whether a given machine has the machine issue.
Expand Down Expand Up @@ -166,21 +166,23 @@ func (c *Config) includeIssue(t Type) bool {
}

func (mim MachineIssuesMap) add(m metal.Machine, issue Issue) {
issues, ok := mim[&m]
machineWithIssues, ok := mim[m.ID]
if !ok {
issues = Issues{}
machineWithIssues = &MachineWithIssues{
Machine: &m,
}
}
issues = append(issues, issue)
mim[&m] = issues
machineWithIssues.Issues = append(machineWithIssues.Issues, issue)
mim[m.ID] = machineWithIssues
}

func (mim MachineIssuesMap) ToList() MachineIssues {
var res MachineIssues

for m, issues := range mim {
for _, machineWithIssues := range mim {
res = append(res, &MachineWithIssues{
Machine: m,
Issues: issues,
Machine: machineWithIssues.Machine,
Issues: machineWithIssues.Issues,
})
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque
continue
}

if _, ok := machinesWithIssues[&m]; ok {
if _, ok := machinesWithIssues[m.ID]; ok {
cap.Faulty++
cap.FaultyMachines = append(cap.FaultyMachines, m.ID)
continue
Expand Down

0 comments on commit b0a2489

Please sign in to comment.