Skip to content

Commit

Permalink
de-comment some plain parts, remove unused action lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Oct 11, 2023
1 parent ae20d4c commit 1131dfe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
4 changes: 4 additions & 0 deletions nomad/structs/actions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

// Actions are executable commands that can be run on an allocation within
// the context of a task. They are left open-ended enough to be applied to
// other Nomad concepts like Nodes in the future.

package structs

import "slices"
Expand Down
22 changes: 0 additions & 22 deletions nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,23 +579,6 @@ func (t *Task) Diff(other *Task, contextual bool) (*TaskDiff, error) {
return diff, nil
}

func findActionMatch(action *Action, newActions []*Action, newActionMatches []int) int {
indexMatch := -1

for i, newAction := range newActions {
if newActionMatches[i] >= 0 {
continue
}

if action.Name == newAction.Name {
indexMatch = i
break
}
}

return indexMatch
}

func actionDiff(old, new *Action, contextual bool) *ObjectDiff {
diff := &ObjectDiff{Type: DiffTypeNone, Name: "Action"}
var oldPrimitiveFlat, newPrimitiveFlat map[string]string
Expand Down Expand Up @@ -630,10 +613,8 @@ func actionDiff(old, new *Action, contextual bool) *ObjectDiff {
// actionDiffs diffs a set of actions. If contextual diff is enabled, unchanged
// fields within objects nested in the actions will be returned.
func actionDiffs(old, new []*Action, contextual bool) []*ObjectDiff {
// Initialize diffs array
var diffs []*ObjectDiff

// Start by matching actions by their index
for i := 0; i < len(old) && i < len(new); i++ {
oldAction := old[i]
newAction := new[i]
Expand All @@ -643,21 +624,18 @@ func actionDiffs(old, new []*Action, contextual bool) []*ObjectDiff {
}
}

// Handle remaining old actions (which have been deleted)
for i := len(new); i < len(old); i++ {
if diff := actionDiff(old[i], nil, contextual); diff != nil {
diffs = append(diffs, diff)
}
}

// Handle remaining new actions (which have been added)
for i := len(old); i < len(new); i++ {
if diff := actionDiff(nil, new[i], contextual); diff != nil {
diffs = append(diffs, diff)
}
}

// Optionally, sort the diffs for more predictable output
sort.Sort(ObjectDiffs(diffs))

return diffs
Expand Down

0 comments on commit 1131dfe

Please sign in to comment.