From a7e77f61cc2e76224abc4627b77845056a906bbc Mon Sep 17 00:00:00 2001 From: Archit Sharma Date: Wed, 11 Oct 2023 16:02:18 +0530 Subject: [PATCH] refactor Signed-off-by: Archit Sharma --- pkg/collect/cluster_resources.go | 21 --------------------- pkg/collect/collect.go | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/collect/cluster_resources.go b/pkg/collect/cluster_resources.go index b7a60de83..460befcbe 100644 --- a/pkg/collect/cluster_resources.go +++ b/pkg/collect/cluster_resources.go @@ -14,7 +14,6 @@ import ( troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" "github.com/replicatedhq/troubleshoot/pkg/constants" "github.com/replicatedhq/troubleshoot/pkg/k8sutil" - "gopkg.in/yaml.v2" authorizationv1 "k8s.io/api/authorization/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -2111,23 +2110,3 @@ func configMaps(ctx context.Context, client kubernetes.Interface, namespaces []s return configmapByNamespace, errorsByNamespace } - -// storeCustomResource stores a custom resource as JSON and YAML -// We use both formats for backwards compatibility. This way we -// avoid breaking existing tools and analysers that already rely on -// the YAML format. -func storeCustomResource(name string, objects any, m map[string][]byte) error { - j, err := json.MarshalIndent(objects, "", " ") - if err != nil { - return err - } - - y, err := yaml.Marshal(objects) - if err != nil { - return err - } - - m[fmt.Sprintf("%s.json", name)] = j - m[fmt.Sprintf("%s.yaml", name)] = y - return nil -} diff --git a/pkg/collect/collect.go b/pkg/collect/collect.go index 2b35cfead..d7b448829 100644 --- a/pkg/collect/collect.go +++ b/pkg/collect/collect.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" + "gopkg.in/yaml.v2" "k8s.io/client-go/rest" ) @@ -211,3 +212,23 @@ func copyResult(srcResult CollectorResult, dstResult CollectorResult, bundlePath return nil } + +// storeCustomResource stores a custom resource as JSON and YAML +// We use both formats for backwards compatibility. This way we +// avoid breaking existing tools and analysers that already rely on +// the YAML format. +func storeCustomResource(name string, objects any, m map[string][]byte) error { + j, err := json.MarshalIndent(objects, "", " ") + if err != nil { + return err + } + + y, err := yaml.Marshal(objects) + if err != nil { + return err + } + + m[fmt.Sprintf("%s.json", name)] = j + m[fmt.Sprintf("%s.yaml", name)] = y + return nil +}