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 e3b1a9a commit f65adc9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
5 changes: 4 additions & 1 deletion cmd/collector/cli/run.go
Original file line number Diff line number Diff line change
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("disable-redactions", cmd.Flags().Lookup("disable-redactions"))
},
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),
DisableRedactions: v.GetBool("disable-redactions"),
}
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("disable-redactions", false, "disable default redactions")

cmd.MarkFlagRequired("collector")

Expand Down
7 changes: 5 additions & 2 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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("disable-redactions", cmd.Flags().Lookup("disable-redactions"))
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
Expand Down Expand Up @@ -74,8 +75,9 @@ troubleshoot run --collectors application --wait
Name: collectorName,
Namespace: v.GetString("namespace"),
},
Image: v.GetString("image"),
ImagePullPolicy: v.GetString("pullpolicy"),
Image: v.GetString("image"),
ImagePullPolicy: v.GetString("pullpolicy"),
DisableRedactions: v.GetBool("disable-redactions"),
},
}
if _, err := troubleshootClient.CollectorJobs(v.GetString("namespace")).Create(&collectorJob); err != nil {
Expand Down Expand Up @@ -129,6 +131,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("disable-redactions", false, "disable default redactions")

viper.BindPFlags(cmd.Flags())

Expand Down
2 changes: 2 additions & 0 deletions config/crds/troubleshoot.replicated.com_collectorjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ spec:
required:
- name
type: object
disableRedactions:
type: boolean
image:
type: string
imagePullPolicy:
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/troubleshoot/v1beta1/collectorjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type CollectorRef struct {
type CollectorJobSpec struct {
Collector CollectorRef `json:"collector"`

Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
DisableRedactions bool `json:"disableRedactions,omitempty"`
}

// CollectorJobStatus defines the observed state of CollectorJob
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ClusterInfoOutput struct {
ClusterVersion []byte `json:"cluster-info/cluster_version.json,omitempty"`
}

func ClusterInfo() error {
func (c *Collector) ClusterInfo() error {
cfg, err := config.GetConfig()
if err != nil {
return err
Expand Down
12 changes: 7 additions & 5 deletions pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ClusterResourcesOutput struct {
CustomResourceDefinitions []byte `json:"cluster-resources/custom-resource-definitions.json,omitempty"`
}

func ClusterResources() error {
func (c *Collector) ClusterResources() 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 !c.DisableRedactions {
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
7 changes: 4 additions & 3 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

type Collector struct {
Spec string
Spec string
DisableRedactions bool
}

func (c *Collector) RunCollectorSync() error {
Expand All @@ -18,9 +19,9 @@ func (c *Collector) RunCollectorSync() error {
}

if collect.ClusterInfo != nil {
return ClusterInfo()
return c.ClusterInfo()
} else if collect.ClusterResources != nil {
return ClusterResources()
return c.ClusterResources()
}

return errors.New("no spec found to run")
Expand Down
15 changes: 10 additions & 5 deletions pkg/controller/collectorjob/collectorjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ func (r *ReconcileCollectorJob) createCollectorPod(instance *troubleshootv1beta1
imagePullPolicy = corev1.PullPolicy(instance.Spec.ImagePullPolicy)
}

args := []string{
"run",
"--collector",
"/troubleshoot/specs/collector.yaml",
}
if instance.Spec.DisableRedactions {
args = append(args, "--disable-redactions")
}

pod := corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -385,11 +394,7 @@ func (r *ReconcileCollectorJob) createCollectorPod(instance *troubleshootv1beta1
ImagePullPolicy: imagePullPolicy,
Name: idForCollector(collector),
Command: []string{"collector"},
Args: []string{
"run",
"--collector",
"/troubleshoot/specs/collector.yaml",
},
Args: args,
VolumeMounts: []corev1.VolumeMount{
{
Name: "collector",
Expand Down

0 comments on commit f65adc9

Please sign in to comment.