2023-09-04 07:08:34 +00:00
|
|
|
|
namespace KubernetesWorkflow
|
2023-08-07 13:51:44 +00:00
|
|
|
|
{
|
|
|
|
|
public class PodLabels
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<string, string> labels = new Dictionary<string, string>();
|
|
|
|
|
|
2023-09-04 07:08:34 +00:00
|
|
|
|
public void Add(string key, string value)
|
2023-08-10 09:25:22 +00:00
|
|
|
|
{
|
2023-09-04 07:08:34 +00:00
|
|
|
|
labels.Add(key, Format(value));
|
2023-08-10 09:25:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 07:08:34 +00:00
|
|
|
|
public PodLabels Clone()
|
2023-08-10 09:25:22 +00:00
|
|
|
|
{
|
2023-09-04 07:08:34 +00:00
|
|
|
|
var result = new PodLabels();
|
|
|
|
|
foreach (var entry in labels) result.Add(entry.Key, entry.Value);
|
|
|
|
|
return result;
|
2023-08-10 09:25:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 07:08:34 +00:00
|
|
|
|
public void Clear()
|
2023-08-07 13:51:44 +00:00
|
|
|
|
{
|
2023-09-04 07:08:34 +00:00
|
|
|
|
labels.Clear();
|
2023-08-17 09:06:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string Format(string s)
|
|
|
|
|
{
|
|
|
|
|
var result = s.ToLowerInvariant()
|
|
|
|
|
.Replace(":", "-")
|
2023-08-10 09:47:34 +00:00
|
|
|
|
.Replace("/", "-")
|
|
|
|
|
.Replace("\\", "-")
|
2023-08-17 09:06:45 +00:00
|
|
|
|
.Replace("[", "-")
|
|
|
|
|
.Replace("]", "-")
|
|
|
|
|
.Replace(",", "-");
|
|
|
|
|
|
|
|
|
|
return result.Trim('-');
|
2023-08-07 13:51:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal Dictionary<string, string> GetLabels()
|
|
|
|
|
{
|
|
|
|
|
return labels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|