2023-09-15 10:25:10 +00:00
|
|
|
|
namespace KubernetesWorkflow
|
|
|
|
|
{
|
|
|
|
|
public static class K8sNameUtils
|
|
|
|
|
{
|
|
|
|
|
public static string Format(string s)
|
2023-11-06 13:33:47 +00:00
|
|
|
|
{
|
|
|
|
|
return Format(s, 62);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string FormatPortName(string s)
|
|
|
|
|
{
|
|
|
|
|
return Format(s, 15);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string Format(string s, int maxLength)
|
2023-09-15 10:25:10 +00:00
|
|
|
|
{
|
|
|
|
|
var result = s.ToLowerInvariant()
|
2023-11-06 13:33:47 +00:00
|
|
|
|
.Replace("_", "-")
|
2023-09-15 10:25:10 +00:00
|
|
|
|
.Replace(" ", "-")
|
|
|
|
|
.Replace(":", "-")
|
|
|
|
|
.Replace("/", "-")
|
|
|
|
|
.Replace("\\", "-")
|
|
|
|
|
.Replace("[", "-")
|
|
|
|
|
.Replace("]", "-")
|
|
|
|
|
.Replace(",", "-");
|
|
|
|
|
|
2023-09-28 10:22:35 +00:00
|
|
|
|
result = result.Trim('-');
|
2023-11-06 13:33:47 +00:00
|
|
|
|
if (result.Length > maxLength) result = result.Substring(0, maxLength);
|
2023-09-28 10:22:35 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2023-09-15 10:25:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|