Allows Secret & ConfigMap Keys to look like Environment Variables

This makes environment variable style keys (uppercase with underscores) valid
in Secrets and ConfigMap.
This commit is contained in:
Ed Robinson
2016-05-11 06:59:59 +01:00
parent 897d277095
commit d4969ff032
4 changed files with 22 additions and 10 deletions

View File

@@ -247,19 +247,26 @@ func IsHTTPHeaderName(value string) []string {
return nil
}
const configMapKeyFmt = "\\.?" + dns1123SubdomainFmt
const configMapKeyFmt = `[-._a-zA-Z0-9]+`
var configMapKeyRegexp = regexp.MustCompile("^" + configMapKeyFmt + "$")
// IsConfigMapKey tests for a string that conforms to the definition of a
// subdomain in DNS (RFC 1123), except that a leading dot is allowed
// IsConfigMapKey tests for a string that is a valid key for a ConfigMap or Secret
func IsConfigMapKey(value string) []string {
var errs []string
if len(value) > DNS1123SubdomainMaxLength {
errs = append(errs, MaxLenError(DNS1123SubdomainMaxLength))
}
if !configMapKeyRegexp.MatchString(value) {
errs = append(errs, RegexError(configMapKeyFmt, "key.name"))
errs = append(errs, RegexError(configMapKeyFmt, "key.name", "KEY_NAME", "key-name"))
}
if value == "." {
errs = append(errs, `must not be '.'`)
}
if value == ".." {
errs = append(errs, `must not be '..'`)
} else if strings.HasPrefix(value, "..") {
errs = append(errs, `must not start with '..'`)
}
return errs
}