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 <martin.hickey@ie.ibm.com>

* Add comments about the Kubernetes storage object type field content

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
pull/6516/head
Martin Hickey 5 years ago committed by GitHub
parent fef60966f6
commit caa26c4bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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:
// <helm_domain>/<helm_object>.v<helm_object_version>
// 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
}

@ -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 ```<release_name>#v<version>```.
// makeKey concatenates the Kubernetes storage object type, a release name and version
// into a string with format:```<helm_storage_type>.<release_name>.v<release_version>```.
// 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.

Loading…
Cancel
Save