Skip to content

Commit 0c63880

Browse files
fix: --redactors flag is dropped if no spec provided (#1611)
don't drop redactors when 0 positional arguments are provided
1 parent 7484b10 commit 0c63880

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

cmd/troubleshoot/cli/run.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,11 @@ func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.Troublesh
283283

284284
func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface) (*troubleshootv1beta2.SupportBundle, *troubleshootv1beta2.Redactor, error) {
285285
var (
286-
kinds = loader.NewTroubleshootKinds()
287-
vp = viper.GetViper()
288-
allArgs = append(args, vp.GetStringSlice("redactors")...)
289-
err error
286+
kinds = loader.NewTroubleshootKinds()
287+
vp = viper.GetViper()
288+
redactors = vp.GetStringSlice("redactors")
289+
allArgs = append(args, redactors...)
290+
err error
290291
)
291292

292293
if len(args) < 1 {
@@ -295,6 +296,13 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface)
295296
if err != nil {
296297
return nil, nil, errors.Wrap(err, "failed to load specs from cluster, and no specs were provided as arguments")
297298
}
299+
if len(redactors) > 0 {
300+
additionalKinds, err := specs.LoadFromCLIArgs(ctx, client, allArgs, vp)
301+
if err != nil {
302+
return nil, nil, errors.Wrap(err, "failed to load redactors from CLI args")
303+
}
304+
kinds.RedactorsV1Beta2 = append(kinds.RedactorsV1Beta2, additionalKinds.RedactorsV1Beta2...)
305+
}
298306
} else {
299307
kinds, err = specs.LoadFromCLIArgs(ctx, client, allArgs, vp)
300308
if err != nil {

test/validate-support-bundle-e2e.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ if ! grep "labelled-support-bundle-4 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_direct
155155
fi
156156
kubectl delete -f "$PRJ_ROOT/testdata/supportbundle/labelled-specs"
157157

158+
echo "======= Generating support bundle from k8s cluster using discovered cluster spec and redactor from the CLI ======"
159+
recreate_tmpdir
160+
kubectl apply -f "$PRJ_ROOT/testdata/supportbundle/labelled-bundle-unlabelled-redactor"
161+
./bin/support-bundle -v1 --interactive=false --output=$tmpdir/$bundle_archive_name --redactors=configmap/default/unlabelled-redactor-spec-1/redactor-spec
162+
if [ $? -ne 0 ]; then
163+
echo "support-bundle command failed"
164+
exit $?
165+
fi
166+
167+
if ! tar -xvzf $tmpdir/$bundle_archive_name --directory $tmpdir; then
168+
echo "A valid support bundle archive was not generated"
169+
exit 1
170+
fi
171+
172+
if ! grep "labelled-support-bundle-1 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_directory_name/echo-hi-1"; then
173+
echo "$(cat $tmpdir/$bundle_directory_name/echo-hi-1)"
174+
echo "Hidden content not found in redacted echo-hi-1 file"
175+
exit 1
176+
fi
177+
178+
kubectl delete -f "$PRJ_ROOT/testdata/supportbundle/labelled-bundle-unlabelled-redactor"
179+
158180
echo "======= Generating support bundle from k8s cluster using 0 arguments and no spec in the cluster ======"
159181
recreate_tmpdir
160182
set +e
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: unlabelled-redactor-spec-1
5+
data:
6+
redactor-spec: |
7+
apiVersion: troubleshoot.sh/v1beta2
8+
kind: Redactor
9+
metadata:
10+
name: unlabelled-redactor-spec-1
11+
spec:
12+
redactors:
13+
- name: redact-text-1
14+
removals:
15+
values:
16+
- REDACT FIRST TEXT PLEASE
17+
customer-redactor-spec: |
18+
apiVersion: troubleshoot.sh/v1beta2
19+
kind: Redactor
20+
metadata:
21+
name: unlabelled-redactor-spec-1
22+
spec:
23+
redactors:
24+
- name: redact-text-1
25+
removals:
26+
values:
27+
- REDACT FIRST TEXT PLEASE
28+
garbagge: MWdRRTlBRi9YNzB3eUE2VEgvWjdhRFVUR1UvRmU3TXdUR3Q4cnE4Nkti
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: labelled-support-bundle-1
5+
labels:
6+
troubleshoot.io/kind: support-bundle
7+
stringData:
8+
support-bundle-spec: |
9+
apiVersion: troubleshoot.sh/v1beta2
10+
kind: SupportBundle
11+
metadata:
12+
name: labelled-support-bundle-1
13+
spec:
14+
collectors:
15+
- data:
16+
name: echo-hi-1
17+
data: "I am labelled-support-bundle-1 REDACT FIRST TEXT PLEASE"
18+
custom-spec-key: |
19+
apiVersion: troubleshoot.sh/v1beta2
20+
kind: SupportBundle
21+
metadata:
22+
name: custom-spec-key
23+
spec:
24+
collectors:
25+
- data:
26+
name: echo-hi-3
27+
data: "I am custom-spec-key REDACT FIRST TEXT PLEASE"
28+
garbagge: MWdRRTlBRi9YNzB3eUE2VEgvWjdhRFVUR1UvRmU3TXdUR3Q4cnE4Nkti

0 commit comments

Comments
 (0)