Skip to content

Commit 0478a7a

Browse files
author
Dan Stough
committed
fix: cluster-res collector fixed to one namespace
1 parent 5b15738 commit 0478a7a

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

cmd/preflight/cli/run.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,8 @@ func collectInCluster(preflightSpec *troubleshootv1beta2.Preflight, progressCh c
220220
return nil, errors.Wrap(err, "failed to convert kube flags to rest config")
221221
}
222222

223-
namespace := v.GetString("namespace")
224-
if namespace == "" {
225-
kubeconfig := k8sutil.GetKubeconfig()
226-
namespace, _, _ = kubeconfig.Namespace()
227-
}
228-
229223
collectOpts := preflight.CollectOpts{
230-
Namespace: namespace,
224+
Namespace: v.GetString("namespace"),
231225
IgnorePermissionErrors: v.GetBool("collect-without-permissions"),
232226
ProgressChan: progressCh,
233227
KubernetesRestConfig: restConfig,

cmd/troubleshoot/cli/run.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
4747
return errors.Wrap(err, "failed to convert kube flags to rest config")
4848
}
4949

50-
namespace := v.GetString("namespace")
51-
if namespace == "" {
52-
kubeconfig := k8sutil.GetKubeconfig()
53-
namespace, _, _ = kubeconfig.Namespace()
54-
}
55-
5650
var sinceTime *time.Time
5751
if v.GetString("since-time") != "" || v.GetString("since") != "" {
5852
sinceTime, err = parseTimeFlags(v)
@@ -156,7 +150,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
156150
CollectorProgressCallback: collectorCB,
157151
CollectWithoutPermissions: v.GetBool("collect-without-permissions"),
158152
KubernetesRestConfig: restConfig,
159-
Namespace: namespace,
153+
Namespace: v.GetString("namespace"),
160154
ProgressChan: progressChan,
161155
SinceTime: sinceTime,
162156
}

pkg/collect/collector.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/pkg/errors"
99
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
10+
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
1011
"github.com/replicatedhq/troubleshoot/pkg/multitype"
1112
authorizationv1 "k8s.io/api/authorization/v1"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -218,7 +219,10 @@ func (c *Collector) RunCollectorSync(clientConfig *rest.Config, client kubernete
218219
result, err = Copy(c, c.Collect.Copy)
219220
} else if c.Collect.CopyFromHost != nil {
220221
namespace := c.Collect.CopyFromHost.Namespace
221-
if namespace == "" {
222+
if namespace == "" && c.Namespace == "" {
223+
kubeconfig := k8sutil.GetKubeconfig()
224+
namespace, _, _ = kubeconfig.Namespace()
225+
} else if namespace == "" {
222226
namespace = c.Namespace
223227
}
224228
result, err = CopyFromHost(ctx, namespace, clientConfig, client, c.Collect.CopyFromHost)
@@ -233,7 +237,10 @@ func (c *Collector) RunCollectorSync(clientConfig *rest.Config, client kubernete
233237
} else if c.Collect.Collectd != nil {
234238
// TODO: see if redaction breaks these
235239
namespace := c.Collect.Collectd.Namespace
236-
if namespace == "" {
240+
if namespace == "" && c.Namespace == "" {
241+
kubeconfig := k8sutil.GetKubeconfig()
242+
namespace, _, _ = kubeconfig.Namespace()
243+
} else if namespace == "" {
237244
namespace = c.Namespace
238245
}
239246
result, err = Collectd(ctx, namespace, clientConfig, client, c.Collect.Collectd)

0 commit comments

Comments
 (0)