Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/controller/machinepool/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"reflect"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -1075,19 +1076,27 @@ func (r *ReconcileMachinePool) updatePoolStatusForMachineSets(
// updateOwnedLabelsAndTaints updates OwnedLabels and OwnedTaints in the MachinePool.Status, by fetching the relevant entries sans duplicates from MachinePool.Spec.
func updateOwnedLabelsAndTaints(pool *hivev1.MachinePool) hivev1.MachinePoolStatus {
// Update our tracked labels...
pool.Status.OwnedLabels = make([]string, len(pool.Spec.Labels))
ownedLabels := make([]string, len(pool.Spec.Labels))
i := 0
for labelKey := range pool.Spec.Labels {
pool.Status.OwnedLabels[i] = labelKey
ownedLabels[i] = labelKey
i++
}
sort.Strings(ownedLabels)
pool.Status.OwnedLabels = ownedLabels

// ...and taints
uniqueTaints := *controllerutils.GetUniqueTaints(&pool.Spec.Taints)
pool.Status.OwnedTaints = make([]hivev1.TaintIdentifier, len(uniqueTaints))
ownedTaints := make([]hivev1.TaintIdentifier, len(uniqueTaints))
for i, taint := range uniqueTaints {
pool.Status.OwnedTaints[i] = controllerutils.IdentifierForTaint(&taint)
ownedTaints[i] = controllerutils.IdentifierForTaint(&taint)
}
sort.Slice(ownedTaints, func(i, j int) bool {
// It is not important that these be actually "sorted" -- just that they are
// ordered deterministically.
return fmt.Sprintf("%v", ownedTaints[i]) < fmt.Sprintf("%v", ownedTaints[j])
})
pool.Status.OwnedTaints = ownedTaints
return pool.Status
}

Expand Down
28 changes: 21 additions & 7 deletions pkg/controller/machinepool/machinepool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,21 +1392,35 @@ func TestUpdateOwnedLabelsTaints(t *testing.T) {
name: "Carry over labels from spec",
machinePool: testMachinePoolWithoutLabelsTaints(
testmp.WithLabels(map[string]string{
"test-label": "test-value",
"test-label": "test-value",
"a-smaller-sorting-label": "z-bigger-value",
}),
),
expectedOwnedLabels: []string{"test-label"},
expectedOwnedLabels: []string{"a-smaller-sorting-label", "test-label"},
},
{
name: "Carry over taints from spec",
machinePool: testMachinePoolWithoutLabelsTaints(
testmp.WithTaints(corev1.Taint{
Key: "test-taint",
Value: "test-value",
Effect: "NoSchedule",
}),
testmp.WithTaints(
corev1.Taint{
Key: "test-taint",
Value: "test-value",
Effect: "NoSchedule",
},
),
testmp.WithTaints(
corev1.Taint{
Key: "another-taint",
Value: "test-value",
Effect: "NoSchedule",
},
),
),
expectedOwnedTaints: []hivev1.TaintIdentifier{
{
Key: "another-taint",
Effect: "NoSchedule",
},
{
Key: "test-taint",
Effect: "NoSchedule",
Expand Down