diff --git a/cmd/collector/cli/run.go b/cmd/collector/cli/run.go index 2b241fce0..03623147f 100644 --- a/cmd/collector/cli/run.go +++ b/cmd/collector/cli/run.go @@ -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() @@ -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 @@ -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") diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index 059ddf5df..195bc0330 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -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() @@ -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 { @@ -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()) diff --git a/config/crds/troubleshoot.replicated.com_collectorjobs.yaml b/config/crds/troubleshoot.replicated.com_collectorjobs.yaml index 6bb6d9cb9..596b36d48 100644 --- a/config/crds/troubleshoot.replicated.com_collectorjobs.yaml +++ b/config/crds/troubleshoot.replicated.com_collectorjobs.yaml @@ -400,6 +400,8 @@ spec: required: - name type: object + disableRedactions: + type: boolean image: type: string imagePullPolicy: diff --git a/pkg/apis/troubleshoot/v1beta1/collectorjob_types.go b/pkg/apis/troubleshoot/v1beta1/collectorjob_types.go index 2c9329c17..ff48755e2 100644 --- a/pkg/apis/troubleshoot/v1beta1/collectorjob_types.go +++ b/pkg/apis/troubleshoot/v1beta1/collectorjob_types.go @@ -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 diff --git a/pkg/collect/cluster_info.go b/pkg/collect/cluster_info.go index 17ac155f6..c77c83031 100644 --- a/pkg/collect/cluster_info.go +++ b/pkg/collect/cluster_info.go @@ -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 diff --git a/pkg/collect/cluster_resources.go b/pkg/collect/cluster_resources.go index 3fbd18263..5500ee1d0 100644 --- a/pkg/collect/cluster_resources.go +++ b/pkg/collect/cluster_resources.go @@ -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 @@ -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 } diff --git a/pkg/collect/collector.go b/pkg/collect/collector.go index 6cae8c6da..5faa5f218 100644 --- a/pkg/collect/collector.go +++ b/pkg/collect/collector.go @@ -8,7 +8,8 @@ import ( ) type Collector struct { - Spec string + Spec string + DisableRedactions bool } func (c *Collector) RunCollectorSync() error { @@ -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") diff --git a/pkg/controller/collectorjob/collectorjob_controller.go b/pkg/controller/collectorjob/collectorjob_controller.go index 4a0b6bb3c..885ed3f19 100644 --- a/pkg/controller/collectorjob/collectorjob_controller.go +++ b/pkg/controller/collectorjob/collectorjob_controller.go @@ -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, @@ -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",