From caa26c4bb2bfda8635eb22f4189a57cb494c511d Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Thu, 26 Sep 2019 17:46:19 +0100 Subject: [PATCH] Change release storage name to use helm storage type as prefix (#6500) * Change release storage name to prefix helm storage type Signed-off-by: Martin Hickey * Add comments about the Kubernetes storage object type field content Signed-off-by: Martin Hickey --- pkg/storage/driver/memory.go | 6 ++++-- pkg/storage/driver/secrets.go | 14 ++++++++++++-- pkg/storage/storage.go | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pkg/storage/driver/memory.go b/pkg/storage/driver/memory.go index 1fd059655..5d91767a2 100644 --- a/pkg/storage/driver/memory.go +++ b/pkg/storage/driver/memory.go @@ -49,7 +49,8 @@ func (mem *Memory) Name() string { func (mem *Memory) Get(key string) (*rspb.Release, error) { defer unlock(mem.rlock()) - switch elems := strings.Split(key, ".v"); len(elems) { + keyWithoutPrefix := strings.TrimPrefix(key, "sh.helm.release.v1.") + switch elems := strings.Split(keyWithoutPrefix, ".v"); len(elems) { case 2: name, ver := elems[0], elems[1] if _, err := strconv.Atoi(ver); err != nil { @@ -138,7 +139,8 @@ func (mem *Memory) Update(key string, rls *rspb.Release) error { func (mem *Memory) Delete(key string) (*rspb.Release, error) { defer unlock(mem.wlock()) - elems := strings.Split(key, ".v") + keyWithoutPrefix := strings.TrimPrefix(key, "sh.helm.release.v1.") + elems := strings.Split(keyWithoutPrefix, ".v") if len(elems) != 2 { return nil, ErrInvalidKey diff --git a/pkg/storage/driver/secrets.go b/pkg/storage/driver/secrets.go index 65c995dbe..edd1cca0d 100644 --- a/pkg/storage/driver/secrets.go +++ b/pkg/storage/driver/secrets.go @@ -228,13 +228,23 @@ func newSecretsObject(key string, rls *rspb.Release, lbs labels) (*v1.Secret, er lbs.set("status", rls.Info.Status.String()) lbs.set("version", strconv.Itoa(rls.Version)) - // create and return secret object + // create and return secret object. + // Helm 3 introduced setting the 'Type' field + // in the Kubernetes storage object. + // Helm defines the field content as follows: + // /.v + // Type field for Helm 3: helm.sh/release.v1 + // Note: Version starts at 'v1' for Helm 3 and + // should be incremented if the release object + // metadata is modified. + // This would potentially be a breaking change + // and should only happen between major versions. return &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: key, Labels: lbs.toMap(), }, - Type: "helm.sh/release", + Type: "helm.sh/release.v1", Data: map[string][]byte{"release": []byte(s)}, }, nil } diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 7e2c1b6fc..e676ac474 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -27,6 +27,13 @@ import ( "helm.sh/helm/pkg/storage/driver" ) +// The type field of the Kubernetes storage object which stores the Helm release +// version. It is modified slightly replacing the '/': sh.helm/release.v1 +// Note: The version 'v1' is incremented if the release object metadata is +// modified between major releases. +// This constant is used as a prefix for the Kubernetes storage object name. +const HelmStorageType = "sh.helm.release.v1" + // Storage represents a storage engine for a Release. type Storage struct { driver.Driver @@ -205,11 +212,14 @@ func (s *Storage) Last(name string) (*rspb.Release, error) { return h[0], nil } -// makeKey concatenates a release name and version into -// a string with format ```#v```. +// makeKey concatenates the Kubernetes storage object type, a release name and version +// into a string with format:```..v```. +// The storage type is prepended to keep name uniqueness between different +// release storage types. An example of clash when not using the type: +// https://github.com/helm/helm/issues/6435. // This key is used to uniquely identify storage objects. func makeKey(rlsname string, version int) string { - return fmt.Sprintf("%s.v%d", rlsname, version) + return fmt.Sprintf("%s.%s.v%d", HelmStorageType, rlsname, version) } // Init initializes a new storage backend with the driver d.