Commit cafec120 authored by Matt Butcher's avatar Matt Butcher

feat(tiller): limit the max len of Release.Name

This limits the number of characters in a release name to 14. This
preserves 10 characters for customizing the `name:` field in charts.

Relates to #1071
parent 120256ec
......@@ -39,6 +39,13 @@ import (
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() {
srv = &releaseServer{
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,
// we re-grant it. Otherwise, an error is returned.
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 {
return start, nil
} 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++ {
namer := moniker.New()
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 {
return name, nil
}
......
......@@ -130,6 +130,7 @@ func TestUniqName(t *testing.T) {
{"angry-panda", "", false, true},
{"happy-panda", "", false, true},
{"happy-panda", "happy-panda", true, false},
{"hungry-hungry-hippos", "", true, true}, // Exceeds max name length
}
for _, tt := range tests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment