11package cli
22
33import (
4- "errors"
5- "path/filepath"
6-
4+ "github.com/pkg/errors"
75 troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
86 "github.com/replicatedhq/troubleshoot/pkg/k8sutil"
97 "github.com/replicatedhq/troubleshoot/pkg/logger"
@@ -19,13 +17,11 @@ func Retrieve() *cobra.Command {
1917 Long : `...` ,
2018 PreRun : func (cmd * cobra.Command , args []string ) {
2119 viper .BindPFlag ("collectors" , cmd .Flags ().Lookup ("collectors" ))
22- viper .BindPFlag ("namespace" , cmd .Flags ().Lookup ("namespace" ))
23- viper .BindPFlag ("kubecontext" , cmd .Flags ().Lookup ("kubecontext" ))
2420 },
2521 RunE : func (cmd * cobra.Command , args []string ) error {
2622 v := viper .GetViper ()
2723
28- troubleshootClient , err := createTroubleshootK8sClient ()
24+ troubleshootClient , err := createTroubleshootK8sClient (KubernetesConfigFlags )
2925 if err != nil {
3026 return err
3127 }
@@ -53,7 +49,12 @@ func Retrieve() *cobra.Command {
5349
5450 logger .Printf ("connecting to collector job %s\n " , collectorJob .Name )
5551
56- stopChan , err := k8sutil .PortForward (v .GetString ("kubecontext" ), 8000 , 8000 , collectorJob .Status .ServerPodNamespace , collectorJob .Status .ServerPodName )
52+ config , err := KubernetesConfigFlags .ToRESTConfig ()
53+ if err != nil {
54+ return errors .Wrap (err , "failed to convert kube flags to rest config" )
55+ }
56+
57+ stopChan , err := k8sutil .PortForward (config , 8000 , 8000 , collectorJob .Status .ServerPodNamespace , collectorJob .Status .ServerPodName )
5758 if err != nil {
5859 return err
5960 }
@@ -70,9 +71,6 @@ func Retrieve() *cobra.Command {
7071 }
7172
7273 cmd .Flags ().String ("collectors" , "" , "name of the collectors to use" )
73- cmd .Flags ().String ("namespace" , "" , "namespace the collectors can be found in" )
74-
75- cmd .Flags ().String ("kubecontext" , filepath .Join (homeDir (), ".kube" , "config" ), "the kubecontext to use when connecting" )
7674
7775 viper .BindPFlags (cmd .Flags ())
7876
0 commit comments