@@ -31,11 +31,12 @@ import (
3131 "github.com/replicatedhq/troubleshoot/pkg/collect"
3232 "github.com/replicatedhq/troubleshoot/pkg/convert"
3333 "github.com/replicatedhq/troubleshoot/pkg/docrewrite"
34+ "github.com/replicatedhq/troubleshoot/pkg/k8sutil"
3435 "github.com/replicatedhq/troubleshoot/pkg/redact"
36+ "github.com/replicatedhq/troubleshoot/pkg/specs"
3537 "github.com/spf13/viper"
3638 spin "github.com/tj/go-spin"
3739 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38- "k8s.io/client-go/kubernetes"
3940)
4041
4142var (
@@ -255,7 +256,7 @@ func loadSpec(v *viper.Viper, arg string) ([]byte, error) {
255256 return nil , errors .Errorf ("path %s must have 3 components" , arg )
256257 }
257258
258- spec , err := loadSpecFromSecret (pathParts [1 ], pathParts [2 ])
259+ spec , err := specs . LoadFromSecret (pathParts [1 ], pathParts [2 ], "support-bundle-spec" )
259260 if err != nil {
260261 return nil , errors .Wrap (err , "failed to get spec from secret" )
261262 }
@@ -281,30 +282,6 @@ func loadSpec(v *viper.Viper, arg string) ([]byte, error) {
281282 return spec , nil
282283}
283284
284- func loadSpecFromSecret (namespace string , secretName string ) ([]byte , error ) {
285- config , err := KubernetesConfigFlags .ToRESTConfig ()
286- if err != nil {
287- return nil , errors .Wrap (err , "failed to convert kube flags to rest config" )
288- }
289-
290- client , err := kubernetes .NewForConfig (config )
291- if err != nil {
292- return nil , errors .Wrap (err , "failed to convert create k8s client" )
293- }
294-
295- foundSecret , err := client .CoreV1 ().Secrets (namespace ).Get (context .TODO (), secretName , metav1.GetOptions {})
296- if err != nil {
297- return nil , errors .Wrap (err , "failed to get secret" )
298- }
299-
300- spec , ok := foundSecret .Data ["support-bundle-spec" ]
301- if ! ok {
302- return nil , errors .Errorf ("spec not found in secret %s" , secretName )
303- }
304-
305- return spec , nil
306- }
307-
308285func loadSpecFromURL (v * viper.Viper , arg string ) ([]byte , error ) {
309286 for {
310287 req , err := http .NewRequest ("GET" , arg , nil )
@@ -407,7 +384,7 @@ func runCollectors(v *viper.Viper, collectors []*troubleshootv1beta2.Collect, ad
407384 collectSpecs = ensureCollectorInList (collectSpecs , troubleshootv1beta2.Collect {ClusterInfo : & troubleshootv1beta2.ClusterInfo {}})
408385 collectSpecs = ensureCollectorInList (collectSpecs , troubleshootv1beta2.Collect {ClusterResources : & troubleshootv1beta2.ClusterResources {}})
409386
410- config , err := KubernetesConfigFlags . ToRESTConfig ()
387+ config , err := k8sutil . GetRESTConfig ()
411388 if err != nil {
412389 return "" , errors .Wrap (err , "failed to convert kube flags to rest config" )
413390 }
0 commit comments