2
0
mirror of synced 2025-02-16 18:37:01 +00:00

Fix kubernetes port name issue

This commit is contained in:
Ben 2024-09-30 15:23:14 +02:00
parent 6a8c74e02a
commit ffb5eb294a
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
2 changed files with 17 additions and 10 deletions

View File

@ -24,8 +24,8 @@
.Replace("]", "-") .Replace("]", "-")
.Replace(",", "-"); .Replace(",", "-");
result = result.Trim('-');
if (result.Length > maxLength) result = result.Substring(0, maxLength); if (result.Length > maxLength) result = result.Substring(0, maxLength);
result = result.Trim('-');
return result; return result;
} }

View File

@ -3,24 +3,31 @@
public static class RandomUtils public static class RandomUtils
{ {
private static readonly Random random = new Random(); private static readonly Random random = new Random();
private static readonly object @lock = new object();
public static T PickOneRandom<T>(this List<T> remainingItems) public static T PickOneRandom<T>(this List<T> remainingItems)
{ {
var i = random.Next(0, remainingItems.Count); lock (@lock)
var result = remainingItems[i]; {
remainingItems.RemoveAt(i); var i = random.Next(0, remainingItems.Count);
return result; var result = remainingItems[i];
remainingItems.RemoveAt(i);
return result;
}
} }
public static T[] Shuffled<T>(T[] items) public static T[] Shuffled<T>(T[] items)
{ {
var result = new List<T>(); lock (@lock)
var source = items.ToList();
while (source.Any())
{ {
result.Add(RandomUtils.PickOneRandom(source)); var result = new List<T>();
var source = items.ToList();
while (source.Any())
{
result.Add(RandomUtils.PickOneRandom(source));
}
return result.ToArray();
} }
return result.ToArray();
} }
} }
} }