diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index f1ee69c42..837475255 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -283,10 +283,11 @@ func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.Troublesh func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface) (*troubleshootv1beta2.SupportBundle, *troubleshootv1beta2.Redactor, error) { var ( - kinds = loader.NewTroubleshootKinds() - vp = viper.GetViper() - allArgs = append(args, vp.GetStringSlice("redactors")...) - err error + kinds = loader.NewTroubleshootKinds() + vp = viper.GetViper() + redactors = vp.GetStringSlice("redactors") + allArgs = append(args, redactors...) + err error ) if len(args) < 1 { @@ -295,6 +296,13 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface) if err != nil { return nil, nil, errors.Wrap(err, "failed to load specs from cluster, and no specs were provided as arguments") } + if len(redactors) > 0 { + additionalKinds, err := specs.LoadFromCLIArgs(ctx, client, allArgs, vp) + if err != nil { + return nil, nil, errors.Wrap(err, "failed to load redactors from CLI args") + } + kinds.RedactorsV1Beta2 = append(kinds.RedactorsV1Beta2, additionalKinds.RedactorsV1Beta2...) + } } else { kinds, err = specs.LoadFromCLIArgs(ctx, client, allArgs, vp) if err != nil { diff --git a/test/validate-support-bundle-e2e.sh b/test/validate-support-bundle-e2e.sh index a54764e57..51f7bfcb0 100755 --- a/test/validate-support-bundle-e2e.sh +++ b/test/validate-support-bundle-e2e.sh @@ -155,6 +155,28 @@ if ! grep "labelled-support-bundle-4 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_direct fi kubectl delete -f "$PRJ_ROOT/testdata/supportbundle/labelled-specs" +echo "======= Generating support bundle from k8s cluster using discovered cluster spec and redactor from the CLI ======" +recreate_tmpdir +kubectl apply -f "$PRJ_ROOT/testdata/supportbundle/labelled-bundle-unlabelled-redactor" +./bin/support-bundle -v1 --interactive=false --output=$tmpdir/$bundle_archive_name --redactors=configmap/default/unlabelled-redactor-spec-1/redactor-spec +if [ $? -ne 0 ]; then + echo "support-bundle command failed" + exit $? +fi + +if ! tar -xvzf $tmpdir/$bundle_archive_name --directory $tmpdir; then + echo "A valid support bundle archive was not generated" + exit 1 +fi + +if ! grep "labelled-support-bundle-1 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_directory_name/echo-hi-1"; then + echo "$(cat $tmpdir/$bundle_directory_name/echo-hi-1)" + echo "Hidden content not found in redacted echo-hi-1 file" + exit 1 +fi + +kubectl delete -f "$PRJ_ROOT/testdata/supportbundle/labelled-bundle-unlabelled-redactor" + echo "======= Generating support bundle from k8s cluster using 0 arguments and no spec in the cluster ======" recreate_tmpdir set +e diff --git a/testdata/supportbundle/labelled-bundle-unlabelled-redactor/redact-spec-1.yaml b/testdata/supportbundle/labelled-bundle-unlabelled-redactor/redact-spec-1.yaml new file mode 100644 index 000000000..fd6e9e54a --- /dev/null +++ b/testdata/supportbundle/labelled-bundle-unlabelled-redactor/redact-spec-1.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: unlabelled-redactor-spec-1 +data: + redactor-spec: | + apiVersion: troubleshoot.sh/v1beta2 + kind: Redactor + metadata: + name: unlabelled-redactor-spec-1 + spec: + redactors: + - name: redact-text-1 + removals: + values: + - REDACT FIRST TEXT PLEASE + customer-redactor-spec: | + apiVersion: troubleshoot.sh/v1beta2 + kind: Redactor + metadata: + name: unlabelled-redactor-spec-1 + spec: + redactors: + - name: redact-text-1 + removals: + values: + - REDACT FIRST TEXT PLEASE + garbagge: MWdRRTlBRi9YNzB3eUE2VEgvWjdhRFVUR1UvRmU3TXdUR3Q4cnE4Nkti diff --git a/testdata/supportbundle/labelled-bundle-unlabelled-redactor/sb-spec-1.yaml b/testdata/supportbundle/labelled-bundle-unlabelled-redactor/sb-spec-1.yaml new file mode 100644 index 000000000..978ae667d --- /dev/null +++ b/testdata/supportbundle/labelled-bundle-unlabelled-redactor/sb-spec-1.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 +kind: Secret +metadata: + name: labelled-support-bundle-1 + labels: + troubleshoot.io/kind: support-bundle +stringData: + support-bundle-spec: | + apiVersion: troubleshoot.sh/v1beta2 + kind: SupportBundle + metadata: + name: labelled-support-bundle-1 + spec: + collectors: + - data: + name: echo-hi-1 + data: "I am labelled-support-bundle-1 REDACT FIRST TEXT PLEASE" + custom-spec-key: | + apiVersion: troubleshoot.sh/v1beta2 + kind: SupportBundle + metadata: + name: custom-spec-key + spec: + collectors: + - data: + name: echo-hi-3 + data: "I am custom-spec-key REDACT FIRST TEXT PLEASE" + garbagge: MWdRRTlBRi9YNzB3eUE2VEgvWjdhRFVUR1UvRmU3TXdUR3Q4cnE4Nkti