wwctl upgrade nodes --replace-overlays avoids applying overlays multiple times
- Closes: #1823 Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -15,3 +15,26 @@ func replaceSliceElement[T any](original []T, index int, replacement []T) []T {
|
||||
}
|
||||
return append(original[:index], append(replacement, original[index+1:]...)...)
|
||||
}
|
||||
|
||||
func replaceOverlay(originals []string, toReplace string, replacements []string) []string {
|
||||
if indexOf(originals, toReplace) == -1 {
|
||||
return originals
|
||||
}
|
||||
|
||||
lookup := make(map[string]bool)
|
||||
for _, v := range originals {
|
||||
lookup[v] = true
|
||||
}
|
||||
|
||||
var newReplacements []string
|
||||
for _, v := range replacements {
|
||||
if !lookup[v] || v == toReplace {
|
||||
newReplacements = append(newReplacements, v)
|
||||
}
|
||||
}
|
||||
|
||||
return replaceSliceElement(
|
||||
originals,
|
||||
indexOf(originals, toReplace),
|
||||
newReplacements)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user