1
0
mirror of https://codeberg.org/crowci/crow.git synced 2025-08-09 07:42:52 +03:00

Sanitize pod's step label (#3275)

Closes #3272
This commit is contained in:
Thomas Anderson
2024-01-26 15:42:21 +03:00
committed by GitHub
parent 4df88c602e
commit e5c83190c7
4 changed files with 63 additions and 15 deletions

View File

@@ -31,7 +31,8 @@ var (
`([-a-z0-9]*[a-z0-9])?` + // inside can als contain -
`(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`, // allow the same pattern as before with dots in between but only one dot
)
ErrDNSPatternInvalid = errors.New("name is not a valid kubernetes DNS name")
dnsDisallowedCharacters = regexp.MustCompile(`[^-^.a-z0-9]+`)
ErrDNSPatternInvalid = errors.New("name is not a valid kubernetes DNS name")
)
func dnsName(i string) (string, error) {
@@ -44,6 +45,14 @@ func dnsName(i string) (string, error) {
return res, nil
}
func toDNSName(in string) (string, error) {
lower := strings.ToLower(in)
withoutUnderscores := strings.ReplaceAll(lower, "_", "-")
withoutSpaces := strings.ReplaceAll(withoutUnderscores, " ", "-")
almostDNS := dnsDisallowedCharacters.ReplaceAllString(withoutSpaces, "")
return dnsName(almostDNS)
}
func isImagePullBackOffState(pod *v1.Pod) bool {
for _, containerState := range pod.Status.ContainerStatuses {
if containerState.State.Waiting != nil {