fix: --redactors flag is dropped if no spec provided (#1611)

don't drop redactors when 0 positional arguments are provided
This commit is contained in:
Diamon Wiggins
2024-09-11 17:01:44 -04:00
committed by GitHub
parent 7484b10914
commit 0c63880528
4 changed files with 90 additions and 4 deletions

View File

@@ -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) { func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface) (*troubleshootv1beta2.SupportBundle, *troubleshootv1beta2.Redactor, error) {
var ( var (
kinds = loader.NewTroubleshootKinds() kinds = loader.NewTroubleshootKinds()
vp = viper.GetViper() vp = viper.GetViper()
allArgs = append(args, vp.GetStringSlice("redactors")...) redactors = vp.GetStringSlice("redactors")
err error allArgs = append(args, redactors...)
err error
) )
if len(args) < 1 { if len(args) < 1 {
@@ -295,6 +296,13 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface)
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "failed to load specs from cluster, and no specs were provided as arguments") 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 { } else {
kinds, err = specs.LoadFromCLIArgs(ctx, client, allArgs, vp) kinds, err = specs.LoadFromCLIArgs(ctx, client, allArgs, vp)
if err != nil { if err != nil {

View File

@@ -155,6 +155,28 @@ if ! grep "labelled-support-bundle-4 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_direct
fi fi
kubectl delete -f "$PRJ_ROOT/testdata/supportbundle/labelled-specs" 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 ======" echo "======= Generating support bundle from k8s cluster using 0 arguments and no spec in the cluster ======"
recreate_tmpdir recreate_tmpdir
set +e set +e

View File

@@ -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

View File

@@ -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