mirror of https://github.com/k3s-io/k3s
Merge pull request #67745 from feiskyer/choose-zones
Automatic merge from submit-queue (batch tested with PRs 67745, 67432, 67569, 67825, 67943). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md. Fix panic when choosing zone or zones for volume **What this PR does / why we need it**: Fix panic when choosing zone or zones for volume, so that zoneSlice won't divide by zero now. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ``` cc @ddebroy @andyzhangxpull/8/head
commit
720781e6af
|
@ -585,6 +585,11 @@ func GetPath(mounter volume.Mounter) (string, error) {
|
||||||
// This means that a StatefulSet's volumes (`claimname-statefulsetname-id`) will spread across available zones,
|
// This means that a StatefulSet's volumes (`claimname-statefulsetname-id`) will spread across available zones,
|
||||||
// assuming the id values are consecutive.
|
// assuming the id values are consecutive.
|
||||||
func ChooseZoneForVolume(zones sets.String, pvcName string) string {
|
func ChooseZoneForVolume(zones sets.String, pvcName string) string {
|
||||||
|
// No zones available, return empty string.
|
||||||
|
if zones.Len() == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// We create the volume in a zone determined by the name
|
// We create the volume in a zone determined by the name
|
||||||
// Eventually the scheduler will coordinate placement into an available zone
|
// Eventually the scheduler will coordinate placement into an available zone
|
||||||
hash, index := getPVCNameHashAndIndexOffset(pvcName)
|
hash, index := getPVCNameHashAndIndexOffset(pvcName)
|
||||||
|
@ -633,6 +638,12 @@ func chooseZonesForVolumeIncludingZone(zones sets.String, pvcName, zoneToInclude
|
||||||
|
|
||||||
// ChooseZonesForVolume is identical to ChooseZoneForVolume, but selects a multiple zones, for multi-zone disks.
|
// ChooseZonesForVolume is identical to ChooseZoneForVolume, but selects a multiple zones, for multi-zone disks.
|
||||||
func ChooseZonesForVolume(zones sets.String, pvcName string, numZones uint32) sets.String {
|
func ChooseZonesForVolume(zones sets.String, pvcName string, numZones uint32) sets.String {
|
||||||
|
// No zones available, return empty set.
|
||||||
|
replicaZones := sets.NewString()
|
||||||
|
if zones.Len() == 0 {
|
||||||
|
return replicaZones
|
||||||
|
}
|
||||||
|
|
||||||
// We create the volume in a zone determined by the name
|
// We create the volume in a zone determined by the name
|
||||||
// Eventually the scheduler will coordinate placement into an available zone
|
// Eventually the scheduler will coordinate placement into an available zone
|
||||||
hash, index := getPVCNameHashAndIndexOffset(pvcName)
|
hash, index := getPVCNameHashAndIndexOffset(pvcName)
|
||||||
|
@ -646,7 +657,6 @@ func ChooseZonesForVolume(zones sets.String, pvcName string, numZones uint32) se
|
||||||
// PVC placement (which could also e.g. avoid putting volumes in overloaded or
|
// PVC placement (which could also e.g. avoid putting volumes in overloaded or
|
||||||
// unhealthy zones)
|
// unhealthy zones)
|
||||||
zoneSlice := zones.List()
|
zoneSlice := zones.List()
|
||||||
replicaZones := sets.NewString()
|
|
||||||
|
|
||||||
startingIndex := index * numZones
|
startingIndex := index * numZones
|
||||||
for index = startingIndex; index < startingIndex+numZones; index++ {
|
for index = startingIndex; index < startingIndex+numZones; index++ {
|
||||||
|
|
|
@ -647,6 +647,17 @@ func TestChooseZoneForVolume(t *testing.T) {
|
||||||
VolumeName: "medium-henley--4",
|
VolumeName: "medium-henley--4",
|
||||||
Expected: "c", // hash("") + 4 == 2 mod 3
|
Expected: "c", // hash("") + 4 == 2 mod 3
|
||||||
},
|
},
|
||||||
|
// Test for no zones
|
||||||
|
{
|
||||||
|
Zones: sets.NewString(),
|
||||||
|
VolumeName: "medium-henley--1",
|
||||||
|
Expected: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Zones: nil,
|
||||||
|
VolumeName: "medium-henley--2",
|
||||||
|
Expected: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -992,6 +1003,17 @@ func TestChooseZonesForVolume(t *testing.T) {
|
||||||
NumZones: 3,
|
NumZones: 3,
|
||||||
Expected: sets.NewString("a" /* hash("henley") == 0 + 3 + 6(startingIndex) */, "b", "c"),
|
Expected: sets.NewString("a" /* hash("henley") == 0 + 3 + 6(startingIndex) */, "b", "c"),
|
||||||
},
|
},
|
||||||
|
// Test for no zones
|
||||||
|
{
|
||||||
|
Zones: sets.NewString(),
|
||||||
|
VolumeName: "henley-1",
|
||||||
|
Expected: sets.NewString(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Zones: nil,
|
||||||
|
VolumeName: "henley-2",
|
||||||
|
Expected: sets.NewString(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue