From 3844a3dbd36d76f0176910cce3099fc50b06e6da Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 6 Apr 2020 17:44:57 -0400 Subject: [PATCH] don't override namespace --- pkg/collect/secret.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/collect/secret.go b/pkg/collect/secret.go index f4043a71..49c65aec 100644 --- a/pkg/collect/secret.go +++ b/pkg/collect/secret.go @@ -34,10 +34,6 @@ func Secret(ctx *Context, secretCollector *troubleshootv1beta1.Secret) ([]byte, Errors: make(map[string][]byte), } - if secretCollector.Namespace == "" { - secretCollector.Namespace = "default" - } - path, encoded, err := secret(client, secretCollector) if err != nil { errorBytes, err := marshalNonNil([]string{err.Error()}) @@ -65,9 +61,13 @@ func Secret(ctx *Context, secretCollector *troubleshootv1beta1.Secret) ([]byte, } func secret(client *kubernetes.Clientset, secretCollector *troubleshootv1beta1.Secret) (string, []byte, error) { - path := fmt.Sprintf("%s/%s.json", secretCollector.Namespace, secretCollector.SecretName) + ns := secretCollector.Namespace + if ns == "" { + ns = "current-namespace" + } + path := fmt.Sprintf("%s/%s.json", ns, secretCollector.SecretName) if secretCollector.Key != "" { - path = fmt.Sprintf("%s/%s/%s.json", secretCollector.Namespace, secretCollector.SecretName, secretCollector.Key) + path = fmt.Sprintf("%s/%s/%s.json", ns, secretCollector.SecretName, secretCollector.Key) } found, err := client.CoreV1().Secrets(secretCollector.Namespace).Get(secretCollector.SecretName, metav1.GetOptions{}) @@ -86,6 +86,13 @@ func secret(client *kubernetes.Clientset, secretCollector *troubleshootv1beta1.S return path, b, err } + ns = found.Namespace + if secretCollector.Key != "" { + path = fmt.Sprintf("%s/%s/%s.json", ns, secretCollector.SecretName, secretCollector.Key) + } else { + path = fmt.Sprintf("%s/%s.json", ns, secretCollector.SecretName) + } + keyExists := false keyData := "" if secretCollector.Key != "" {