From 56bab600a272521ee4156c98efff4791af9fa8b4 Mon Sep 17 00:00:00 2001 From: shipengqi Date: Fri, 15 Sep 2023 20:45:22 +0800 Subject: [PATCH] fix: release missing when run the 'list -A' command Signed-off-by: shipengqi --- pkg/action/lazyclient.go | 7 ++++++- pkg/storage/driver/multisecrets.go | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/action/lazyclient.go b/pkg/action/lazyclient.go index 19004498f..a766d55ab 100644 --- a/pkg/action/lazyclient.go +++ b/pkg/action/lazyclient.go @@ -20,6 +20,7 @@ import ( "context" "sync" + "helm.sh/helm/v3/pkg/storage/driver" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -93,7 +94,11 @@ func (s *multiSecretClient) Get(ctx context.Context, name string, opts metav1.Ge if err := s.init(); err != nil { return nil, err } - return s.client.CoreV1().Secrets(s.namespace).Get(ctx, name, opts) + namespace := s.namespace + if v, ok := driver.GetNamespaceFromContext(ctx); ok { + namespace = v + } + return s.client.CoreV1().Secrets(namespace).Get(ctx, name, opts) } func (s *multiSecretClient) List(ctx context.Context, opts metav1.ListOptions) (*v1.SecretList, error) { diff --git a/pkg/storage/driver/multisecrets.go b/pkg/storage/driver/multisecrets.go index 660c31963..3ed35a080 100644 --- a/pkg/storage/driver/multisecrets.go +++ b/pkg/storage/driver/multisecrets.go @@ -46,6 +46,21 @@ import ( rspb "helm.sh/helm/v3/pkg/release" ) +// multiSecretContextKey is defined instead of the built-in string type to avoid collisions. +type multiSecretContextKey string + +var multiSecretContextNamespace = multiSecretContextKey("namespace") + +// GetNamespaceFromContext gets the namespace value from the context. +func GetNamespaceFromContext(ctx context.Context) (string, bool) { + if v := ctx.Value(multiSecretContextNamespace); v != nil { + if namespace, ok := v.(string); ok { + return namespace, ok + } + } + return "", false +} + var _ Driver = (*MultiSecrets)(nil) // MultiSecretsDriverName is the string name of the driver. @@ -371,7 +386,8 @@ func loadRemainingChunks(obj *v1.Secret, multiSecretImpl *MultiSecrets) ([]byte, chunks, _ := strconv.Atoi(string(obj.Data["chunks"])) for chunk := 2; chunk <= chunks; chunk++ { key := fmt.Sprintf("%s.%d", obj.ObjectMeta.Name, chunk) - chunkobj, err := multiSecretImpl.impl.Get(context.Background(), key, metav1.GetOptions{}) + ctx := context.WithValue(context.Background(), multiSecretContextNamespace, obj.Namespace) + chunkobj, err := multiSecretImpl.impl.Get(ctx, key, metav1.GetOptions{}) if err != nil { if apierrors.IsNotFound(err) { return nil, ErrReleaseNotFound