cs-codex-dist-tests/Framework/KubernetesWorkflow/K8sNameUtils.cs

34 lines
857 B
C#
Raw Permalink Normal View History

2023-09-15 10:25:10 +00:00
namespace KubernetesWorkflow
{
public static class K8sNameUtils
{
public static string Format(string s)
{
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()
.Replace("_", "-")
2023-09-15 10:25:10 +00:00
.Replace(" ", "-")
.Replace(":", "-")
.Replace("/", "-")
.Replace("\\", "-")
.Replace("[", "-")
.Replace("]", "-")
.Replace(",", "-");
if (result.Length > maxLength) result = result.Substring(0, maxLength);
2024-09-30 13:23:14 +00:00
result = result.Trim('-');
return result;
2023-09-15 10:25:10 +00:00
}
}
}