You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-07-12 22:21:40 +02:00
fix(backend/kubernetes): Ensure valid naming of name field (#1661)
- Kubernetes v1.26 on VKE causes error when creating persistent volume claim because of uppercase characters in name field This patch is trivial just in order to get it working - happy to implement differently. The error in question: ``` The PersistentVolumeClaim "wp-01G1131R63FWBSPMA4ZAZTKLE-0-clone-0" is invalid: metadata.name: Invalid value: "wp-01G1131R63FWBSPMA4ZAZTKLE-0-clone-0": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*') ```
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
@ -10,8 +12,19 @@ import (
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
func dnsName(i string) string {
|
||||
return strings.Replace(i, "_", "-", -1)
|
||||
var (
|
||||
dnsPattern = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)
|
||||
ErrDNSPatternInvalid = errors.New("name is not a valid kubernetes DNS name")
|
||||
)
|
||||
|
||||
func dnsName(i string) (string, error) {
|
||||
res := strings.Replace(i, "_", "-", -1)
|
||||
|
||||
if found := dnsPattern.FindStringIndex(res); found == nil {
|
||||
return "", ErrDNSPatternInvalid
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func isImagePullBackOffState(pod *v1.Pod) bool {
|
||||
|
Reference in New Issue
Block a user