Skip to content

Commit

Permalink
Redactions can be disabled with CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Jul 18, 2019
1 parent 9d5e80f commit 82ff465
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion cmd/collector/cli/run.go
Expand Up @@ -15,6 +15,7 @@ func Run() *cobra.Command {
Long: `...`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("collector", cmd.Flags().Lookup("collector"))
viper.BindPFlag("redact", cmd.Flags().Lookup("redact"))
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
Expand All @@ -25,7 +26,8 @@ func Run() *cobra.Command {
}

collector := collect.Collector{
Spec: string(specContents),
Spec: string(specContents),
Redact: v.GetBool("redact"),
}
if err := collector.RunCollectorSync(); err != nil {
return err
Expand All @@ -36,6 +38,7 @@ func Run() *cobra.Command {
}

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

cmd.MarkFlagRequired("collector")

Expand Down
2 changes: 2 additions & 0 deletions cmd/troubleshoot/cli/run.go
Expand Up @@ -24,6 +24,7 @@ troubleshoot run --collectors application --wait
viper.BindPFlag("kubecontext", cmd.Flags().Lookup("kubecontext"))
viper.BindPFlag("image", cmd.Flags().Lookup("image"))
viper.BindPFlag("pullpolicy", cmd.Flags().Lookup("pullpolicy"))
viper.BindPFlag("redact", cmd.Flags().Lookup("redact"))
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
Expand All @@ -43,6 +44,7 @@ troubleshoot run --collectors application --wait

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

viper.BindPFlags(cmd.Flags())

Expand Down
1 change: 1 addition & 0 deletions cmd/troubleshoot/cli/run_crd.go
Expand Up @@ -55,6 +55,7 @@ func runTroubleshootCRD(v *viper.Viper) error {
},
Image: v.GetString("image"),
ImagePullPolicy: v.GetString("pullpolicy"),
Redact: v.GetBool("redact"),
},
}
if _, err := troubleshootClient.CollectorJobs(v.GetString("namespace")).Create(&collectorJob); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions config/crds/troubleshoot.replicated.com_collectorjobs.yaml
Expand Up @@ -404,6 +404,8 @@ spec:
type: string
imagePullPolicy:
type: string
redact:
type: boolean
required:
- collector
type: object
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/troubleshoot/v1beta1/collectorjob_types.go
Expand Up @@ -31,6 +31,7 @@ type CollectorJobSpec struct {

Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
Redact bool `json:"redact,omitempty"`
}

// CollectorJobStatus defines the observed state of CollectorJob
Expand Down
12 changes: 7 additions & 5 deletions pkg/collect/cluster_resources.go
Expand Up @@ -22,7 +22,7 @@ type ClusterResourcesOutput struct {
CustomResourceDefinitions []byte `json:"cluster-resources/custom-resource-definitions.json,omitempty"`
}

func ClusterResources() error {
func ClusterResources(redact bool) error {
cfg, err := config.GetConfig()
if err != nil {
return err
Expand Down Expand Up @@ -92,12 +92,14 @@ func ClusterResources() error {
}
clusterResourcesOutput.CustomResourceDefinitions = customResourceDefinitions

redacted, err := clusterResourcesOutput.Redact()
if err != nil {
return err
if redact {
clusterResourcesOutput, err = clusterResourcesOutput.Redact()
if err != nil {
return err
}
}

b, err := json.MarshalIndent(redacted, "", " ")
b, err := json.MarshalIndent(clusterResourcesOutput, "", " ")
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/collect/collector.go
Expand Up @@ -8,7 +8,8 @@ import (
)

type Collector struct {
Spec string
Spec string
Redact bool
}

func (c *Collector) RunCollectorSync() error {
Expand All @@ -21,7 +22,7 @@ func (c *Collector) RunCollectorSync() error {
return ClusterInfo()
}
if collect.ClusterResources != nil {
return ClusterResources()
return ClusterResources(c.Redact)
}
if collect.Secret != nil {
return Secret(collect.Secret)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/collectorjob/collectorjob_controller.go
Expand Up @@ -387,6 +387,7 @@ func (r *ReconcileCollectorJob) createCollectorPod(instance *troubleshootv1beta1
Command: []string{"collector"},
Args: []string{
"run",
fmt.Sprintf("--redact=%t", instance.Spec.Redact),
"--collector",
"/troubleshoot/specs/collector.yaml",
},
Expand Down

0 comments on commit 82ff465

Please sign in to comment.