Skip to content

Commit

Permalink
fix: --redactors flag is dropped if no spec provided (#1611)
Browse files Browse the repository at this point in the history
don't drop redactors when 0 positional arguments are provided
  • Loading branch information
diamonwiggins authored Sep 11, 2024
1 parent 7484b10 commit 0c63880
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions test/validate-support-bundle-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0c63880

Please sign in to comment.