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(",", "-");
result = result.Trim('-');
if (result.Length > maxLength) result = result.Substring(0, maxLength);
result = result.Trim('-');
return result;
}

View File

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