Merge pull request #1080 from technosophos/feat/1071-limit-rel-name-len

feat(tiller): limit the max len of Release.Name
pull/1088/head
Matt Butcher 8 years ago committed by GitHub
commit 77171c0136

@ -39,6 +39,13 @@ import (
var srv *releaseServer var srv *releaseServer
// releaseNameMaxLen is the maximum length of a release name.
//
// This is designed to accomodate the usage of release name in the 'name:'
// field of Kubernetes resources. Many of those fields are limited to 24
// characters in length. See https://github.com/kubernetes/helm/issues/1071
const releaseNameMaxLen = 14
func init() { func init() {
srv = &releaseServer{ srv = &releaseServer{
env: env, env: env,
@ -290,6 +297,11 @@ func (s *releaseServer) uniqName(start string, reuse bool) (string, error) {
// is granted. If reuse is true and a deleted release with that name exists, // is granted. If reuse is true and a deleted release with that name exists,
// we re-grant it. Otherwise, an error is returned. // we re-grant it. Otherwise, an error is returned.
if start != "" { if start != "" {
if len(start) > releaseNameMaxLen {
return "", fmt.Errorf("release name %q exceeds max length of %d", start, releaseNameMaxLen)
}
if rel, err := s.env.Releases.Get(start); err == driver.ErrReleaseNotFound { if rel, err := s.env.Releases.Get(start); err == driver.ErrReleaseNotFound {
return start, nil return start, nil
} else if st := rel.Info.Status.Code; reuse && (st == release.Status_DELETED || st == release.Status_FAILED) { } else if st := rel.Info.Status.Code; reuse && (st == release.Status_DELETED || st == release.Status_FAILED) {
@ -307,6 +319,10 @@ func (s *releaseServer) uniqName(start string, reuse bool) (string, error) {
for i := 0; i < maxTries; i++ { for i := 0; i < maxTries; i++ {
namer := moniker.New() namer := moniker.New()
name := namer.NameSep("-") name := namer.NameSep("-")
if len(name) > releaseNameMaxLen {
log.Printf("info: Candidate name %q exceeds maximum length %d. Skipping.", name, releaseNameMaxLen)
continue
}
if _, err := s.env.Releases.Get(name); err == driver.ErrReleaseNotFound { if _, err := s.env.Releases.Get(name); err == driver.ErrReleaseNotFound {
return name, nil return name, nil
} }

@ -130,6 +130,7 @@ func TestUniqName(t *testing.T) {
{"angry-panda", "", false, true}, {"angry-panda", "", false, true},
{"happy-panda", "", false, true}, {"happy-panda", "", false, true},
{"happy-panda", "happy-panda", true, false}, {"happy-panda", "happy-panda", true, false},
{"hungry-hungry-hippos", "", true, true}, // Exceeds max name length
} }
for _, tt := range tests { for _, tt := range tests {

Loading…
Cancel
Save