Skip to content

Commit 58d088b

Browse files
authored
Merge pull request #10 from replicatedhq/redactor-cmd
Redactions can be disabled with CLI
2 parents 9d5e80f + 82ff465 commit 58d088b

File tree

8 files changed

+21
-8
lines changed

8 files changed

+21
-8
lines changed

cmd/collector/cli/run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func Run() *cobra.Command {
1515
Long: `...`,
1616
PreRun: func(cmd *cobra.Command, args []string) {
1717
viper.BindPFlag("collector", cmd.Flags().Lookup("collector"))
18+
viper.BindPFlag("redact", cmd.Flags().Lookup("redact"))
1819
},
1920
RunE: func(cmd *cobra.Command, args []string) error {
2021
v := viper.GetViper()
@@ -25,7 +26,8 @@ func Run() *cobra.Command {
2526
}
2627

2728
collector := collect.Collector{
28-
Spec: string(specContents),
29+
Spec: string(specContents),
30+
Redact: v.GetBool("redact"),
2931
}
3032
if err := collector.RunCollectorSync(); err != nil {
3133
return err
@@ -36,6 +38,7 @@ func Run() *cobra.Command {
3638
}
3739

3840
cmd.Flags().String("collector", "", "path to a single collector spec to collect")
41+
cmd.Flags().Bool("redact", true, "enable/disable default redactions")
3942

4043
cmd.MarkFlagRequired("collector")
4144

cmd/troubleshoot/cli/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ troubleshoot run --collectors application --wait
2424
viper.BindPFlag("kubecontext", cmd.Flags().Lookup("kubecontext"))
2525
viper.BindPFlag("image", cmd.Flags().Lookup("image"))
2626
viper.BindPFlag("pullpolicy", cmd.Flags().Lookup("pullpolicy"))
27+
viper.BindPFlag("redact", cmd.Flags().Lookup("redact"))
2728
},
2829
RunE: func(cmd *cobra.Command, args []string) error {
2930
v := viper.GetViper()
@@ -43,6 +44,7 @@ troubleshoot run --collectors application --wait
4344

4445
cmd.Flags().String("image", "", "the full name of the collector image to use")
4546
cmd.Flags().String("pullpolicy", "", "the pull policy of the collector image")
47+
cmd.Flags().Bool("redact", true, "enable/disable default redactions")
4648

4749
viper.BindPFlags(cmd.Flags())
4850

cmd/troubleshoot/cli/run_crd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func runTroubleshootCRD(v *viper.Viper) error {
5555
},
5656
Image: v.GetString("image"),
5757
ImagePullPolicy: v.GetString("pullpolicy"),
58+
Redact: v.GetBool("redact"),
5859
},
5960
}
6061
if _, err := troubleshootClient.CollectorJobs(v.GetString("namespace")).Create(&collectorJob); err != nil {

config/crds/troubleshoot.replicated.com_collectorjobs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ spec:
404404
type: string
405405
imagePullPolicy:
406406
type: string
407+
redact:
408+
type: boolean
407409
required:
408410
- collector
409411
type: object

pkg/apis/troubleshoot/v1beta1/collectorjob_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type CollectorJobSpec struct {
3131

3232
Image string `json:"image,omitempty"`
3333
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
34+
Redact bool `json:"redact,omitempty"`
3435
}
3536

3637
// CollectorJobStatus defines the observed state of CollectorJob

pkg/collect/cluster_resources.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ClusterResourcesOutput struct {
2222
CustomResourceDefinitions []byte `json:"cluster-resources/custom-resource-definitions.json,omitempty"`
2323
}
2424

25-
func ClusterResources() error {
25+
func ClusterResources(redact bool) error {
2626
cfg, err := config.GetConfig()
2727
if err != nil {
2828
return err
@@ -92,12 +92,14 @@ func ClusterResources() error {
9292
}
9393
clusterResourcesOutput.CustomResourceDefinitions = customResourceDefinitions
9494

95-
redacted, err := clusterResourcesOutput.Redact()
96-
if err != nil {
97-
return err
95+
if redact {
96+
clusterResourcesOutput, err = clusterResourcesOutput.Redact()
97+
if err != nil {
98+
return err
99+
}
98100
}
99101

100-
b, err := json.MarshalIndent(redacted, "", " ")
102+
b, err := json.MarshalIndent(clusterResourcesOutput, "", " ")
101103
if err != nil {
102104
return err
103105
}

pkg/collect/collector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
)
99

1010
type Collector struct {
11-
Spec string
11+
Spec string
12+
Redact bool
1213
}
1314

1415
func (c *Collector) RunCollectorSync() error {
@@ -21,7 +22,7 @@ func (c *Collector) RunCollectorSync() error {
2122
return ClusterInfo()
2223
}
2324
if collect.ClusterResources != nil {
24-
return ClusterResources()
25+
return ClusterResources(c.Redact)
2526
}
2627
if collect.Secret != nil {
2728
return Secret(collect.Secret)

pkg/controller/collectorjob/collectorjob_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ func (r *ReconcileCollectorJob) createCollectorPod(instance *troubleshootv1beta1
387387
Command: []string{"collector"},
388388
Args: []string{
389389
"run",
390+
fmt.Sprintf("--redact=%t", instance.Spec.Redact),
390391
"--collector",
391392
"/troubleshoot/specs/collector.yaml",
392393
},

0 commit comments

Comments
 (0)