Skip to content

Commit

Permalink
Merge pull request #411 from replicatedhq/dans-fix-missing-cluster-re…
Browse files Browse the repository at this point in the history
…s-namespaces

fix: cluster-res collector fixed to one namespace
  • Loading branch information
Dan Stough committed Sep 3, 2021
2 parents 5b15738 + 0478a7a commit 558f92c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
8 changes: 1 addition & 7 deletions cmd/preflight/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,8 @@ func collectInCluster(preflightSpec *troubleshootv1beta2.Preflight, progressCh c
return nil, errors.Wrap(err, "failed to convert kube flags to rest config")
}

namespace := v.GetString("namespace")
if namespace == "" {
kubeconfig := k8sutil.GetKubeconfig()
namespace, _, _ = kubeconfig.Namespace()
}

collectOpts := preflight.CollectOpts{
Namespace: namespace,
Namespace: v.GetString("namespace"),
IgnorePermissionErrors: v.GetBool("collect-without-permissions"),
ProgressChan: progressCh,
KubernetesRestConfig: restConfig,
Expand Down
8 changes: 1 addition & 7 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
return errors.Wrap(err, "failed to convert kube flags to rest config")
}

namespace := v.GetString("namespace")
if namespace == "" {
kubeconfig := k8sutil.GetKubeconfig()
namespace, _, _ = kubeconfig.Namespace()
}

var sinceTime *time.Time
if v.GetString("since-time") != "" || v.GetString("since") != "" {
sinceTime, err = parseTimeFlags(v)
Expand Down Expand Up @@ -156,7 +150,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
CollectorProgressCallback: collectorCB,
CollectWithoutPermissions: v.GetBool("collect-without-permissions"),
KubernetesRestConfig: restConfig,
Namespace: namespace,
Namespace: v.GetString("namespace"),
ProgressChan: progressChan,
SinceTime: sinceTime,
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
"github.com/replicatedhq/troubleshoot/pkg/multitype"
authorizationv1 "k8s.io/api/authorization/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -218,7 +219,10 @@ func (c *Collector) RunCollectorSync(clientConfig *rest.Config, client kubernete
result, err = Copy(c, c.Collect.Copy)
} else if c.Collect.CopyFromHost != nil {
namespace := c.Collect.CopyFromHost.Namespace
if namespace == "" {
if namespace == "" && c.Namespace == "" {
kubeconfig := k8sutil.GetKubeconfig()
namespace, _, _ = kubeconfig.Namespace()
} else if namespace == "" {
namespace = c.Namespace
}
result, err = CopyFromHost(ctx, namespace, clientConfig, client, c.Collect.CopyFromHost)
Expand All @@ -233,7 +237,10 @@ func (c *Collector) RunCollectorSync(clientConfig *rest.Config, client kubernete
} else if c.Collect.Collectd != nil {
// TODO: see if redaction breaks these
namespace := c.Collect.Collectd.Namespace
if namespace == "" {
if namespace == "" && c.Namespace == "" {
kubeconfig := k8sutil.GetKubeconfig()
namespace, _, _ = kubeconfig.Namespace()
} else if namespace == "" {
namespace = c.Namespace
}
result, err = Collectd(ctx, namespace, clientConfig, client, c.Collect.Collectd)
Expand Down

0 comments on commit 558f92c

Please sign in to comment.