Add support for placement preferences docker-compose v3.3+ (#1425)

This commit is contained in:
ichx
2021-11-04 08:28:45 +08:00
committed by GitHub
parent c921643705
commit 8cb1b0599e
12 changed files with 220 additions and 37 deletions
+17
View File
@@ -595,6 +595,11 @@ func TestCheckPlacementCustomLabels(t *testing.T) {
"node.labels.something == anything",
"node.labels.monitor != xxx",
},
Preferences: []types.PlacementPreferences{
{Spread: "node.labels.zone"},
{Spread: "foo"},
{Spread: "node.labels.ssd"},
},
}
output := loadV3Placement(placement)
@@ -605,10 +610,22 @@ func TestCheckPlacementCustomLabels(t *testing.T) {
NegativeConstraints: map[string]string{
"monitor": "xxx",
},
Preferences: []string{
"zone", "ssd",
},
}
checkConstraints(t, "positive", output.PositiveConstraints, expected.PositiveConstraints)
checkConstraints(t, "negative", output.NegativeConstraints, expected.NegativeConstraints)
if len(output.Preferences) != len(expected.Preferences) {
t.Errorf("preferences len is not equal, expected %d, got %d", len(expected.Preferences), len(output.Preferences))
}
for i := range output.Preferences {
if output.Preferences[i] != expected.Preferences[i] {
t.Errorf("preference is not equal, expected %s, got %s", expected.Preferences[i], output.Preferences[i])
}
}
}
func checkConstraints(t *testing.T, caseName string, output, expected map[string]string) {