When checking for "name reuse", consider SUPERSEDED deploys as valid.

Relates to #3134, but does not fix the underlying cause of releases
ended up stuck in SUPERSEDED.

Also cleans up the boolean logic and fixes an ignored error returned
from env.Releases.History().
pull/4015/head
Alexander Staubo 8 years ago
parent 0deb58ffdf
commit bc4b6b0f60

@ -168,32 +168,35 @@ func (s *ReleaseServer) reuseValues(req *services.UpdateReleaseRequest, current
} }
func (s *ReleaseServer) uniqName(start string, reuse bool) (string, error) { func (s *ReleaseServer) uniqName(start string, reuse bool) (string, error) {
// If a name is supplied, we check to see if that name is taken. If not, it // If a name is supplied, we check to see if that name is taken. If not, it
// 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 { if len(start) > releaseNameMaxLen {
return "", fmt.Errorf("release name %q exceeds max length of %d", start, releaseNameMaxLen) return "", fmt.Errorf("release name %q exceeds max length of %d", start, releaseNameMaxLen)
} }
h, err := s.env.Releases.History(start) h, err := s.env.Releases.History(start)
if err != nil || len(h) < 1 { if err != nil || len(h) < 1 {
return start, nil return start, err
} }
relutil.Reverse(h, relutil.SortByRevision) relutil.Reverse(h, relutil.SortByRevision)
rel := h[0] rel := h[0]
if st := rel.Info.Status.Code; reuse && (st == release.Status_DELETED || st == release.Status_FAILED) { if !reuse {
// Allowe re-use of names if the previous release is marked deleted. return "", fmt.Errorf("a release named %s already exists.\nRun: helm ls --all %s; to check the status of the release\nOr run: helm del --purge %s; to delete it", start, start, start)
}
switch rel.Info.Status.Code {
case release.Status_DELETED, release.Status_FAILED, release.Status_SUPERSEDED:
// Allow re-use of names if the previous release is marked deleted.
// Note that the latest release should never be SUPERSEDED, but this
// can happen on certain failures (issue #3134).
s.Log("name %s exists but is not in use, reusing name", start) s.Log("name %s exists but is not in use, reusing name", start)
return start, nil return start, nil
} else if reuse { default:
return "", errors.New("cannot re-use a name that is still in use") return "", errors.New("cannot re-use a name that is still in use")
} }
return "", fmt.Errorf("a release named %s already exists.\nRun: helm ls --all %s; to check the status of the release\nOr run: helm del --purge %s; to delete it", start, start, start)
} }
maxTries := 5 maxTries := 5

Loading…
Cancel
Save