Skip to content

Commit ffb5eb2

Browse files
committed
Fix kubernetes port name issue
1 parent 6a8c74e commit ffb5eb2

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

Framework/KubernetesWorkflow/K8sNameUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ private static string Format(string s, int maxLength)
2424
.Replace("]", "-")
2525
.Replace(",", "-");
2626

27-
result = result.Trim('-');
2827
if (result.Length > maxLength) result = result.Substring(0, maxLength);
28+
result = result.Trim('-');
2929

3030
return result;
3131
}

Framework/Utils/RandomUtils.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
public static class RandomUtils
44
{
55
private static readonly Random random = new Random();
6+
private static readonly object @lock = new object();
67

78
public static T PickOneRandom<T>(this List<T> remainingItems)
89
{
9-
var i = random.Next(0, remainingItems.Count);
10-
var result = remainingItems[i];
11-
remainingItems.RemoveAt(i);
12-
return result;
10+
lock (@lock)
11+
{
12+
var i = random.Next(0, remainingItems.Count);
13+
var result = remainingItems[i];
14+
remainingItems.RemoveAt(i);
15+
return result;
16+
}
1317
}
1418

1519
public static T[] Shuffled<T>(T[] items)
1620
{
17-
var result = new List<T>();
18-
var source = items.ToList();
19-
while (source.Any())
21+
lock (@lock)
2022
{
21-
result.Add(RandomUtils.PickOneRandom(source));
23+
var result = new List<T>();
24+
var source = items.ToList();
25+
while (source.Any())
26+
{
27+
result.Add(RandomUtils.PickOneRandom(source));
28+
}
29+
return result.ToArray();
2230
}
23-
return result.ToArray();
2431
}
2532
}
2633
}

0 commit comments

Comments
 (0)