Skip to content
Snippets Groups Projects

Add Kubernetes pod label sanitization

Merged Theodor van Nahl requested to merge (removed):Adding_kubernetes_label_sanitation into main
1 unresolved thread
Compare and Show latest version
2 files
+ 19
20
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,6 +6,7 @@ import (
"io"
"net/http"
"regexp"
"strings"
"time"
"golang.org/x/net/context"
@@ -345,17 +346,16 @@ func buildCapabilities(enabled map[string]bool) *api.Capabilities {
return capabilities
}
// Sanitize labels to match Kubernetes restrictions from https://kubernetes.io/
// /docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
func sanitizeLabel(value string) string {
if len(value) > 63 {
value = value[:63]
}
if len(value) > 63 {
value = value[:63]
}
re := regexp.MustCompile(`[^A-Za-z0-9-._ ]`)
standardized := re.ReplaceAllLiteralString(value, "")
standardized := re.ReplaceAllLiteralString(value, "")
final := strings.Replace(standardized, " ", "-", -1)
return final
final := strings.ReplaceAll(standardized, " ", "-")
return final
}
Loading