Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dry run flag to print support bundle specs to std out #1337

Merged
merged 21 commits into from
Oct 10, 2023

Conversation

banjoh
Copy link
Member

@banjoh banjoh commented Sep 12, 2023

Description, Motivation and Context

Introduce support-bundle --dry-run flag used to print specs to stdout. The functional change is minor but I took the liberty of refactoring how we load specs from the CLI. This is where the majority of the changes lie

Fixes #1024

List of changes made

  • Add a new support-bundle --dry-run cli flag
  • Have the support-bundle binary load specs using LoadFromCLIArgs API, similar to the preflight binary
  • Mark a number of APIs as deprecated
  • Make improvements to the OCI pull implementation to handle some edge cases
  • Document a few APIs

Test results

  • OCI dry run
[evans] $ support-bundle --dry-run oci://registry.replicated.com/thanos-reloaded/unstable
WARN[0002] unknown type: application/vnd.unknown.config.v1+json
WARN[0003] unknown type: application/vnd.unknown.config.v1+json
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  creationTimestamp: null
  name: merged-support-bundle-spec
spec:
  collectors:
  - clusterInfo: {}
  - clusterResources: {}
  - logs:
      namespace: '{{repl Namespace }}'
      selector:
      - app=nginx
status: {}
  • Local path (includes support bundle and redactor)
[evans] $ support-bundle --dry-run sample-troubleshoot.yaml
apiVersion: troubleshoot.sh/v1beta2
kind: Redactor
metadata:
  creationTimestamp: null
  name: merged-redactors-spec
spec:
  redactors:
  - fileSelector:
      file: data/my-password-dump
    name: replace password
    removals:
      values:
      - abc123
  - fileSelector: {}
    name: all files
    removals:
      regex:
      - redactor: (another)(?P<mask>.*)(here)
      - redactor: '("value": ").*(")'
        selector: S3_ENDPOINT
      yamlPath:
      - abc.xyz.*
status: {}
---
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  creationTimestamp: null
  name: merged-support-bundle-spec
spec:
  collectors:
  - clusterInfo:
      collectorName: my-cluster-info
  - clusterResources:
      collectorName: my-cluster-resources
  - http:
....
  • From url
[evans] $ support-bundle --dry-run https://raw.githubusercontent.com/replicatedhq/troubleshoot/main/sample-troubleshoot.yaml
apiVersion: troubleshoot.sh/v1beta2
kind: Redactor
metadata:
  creationTimestamp: null
  name: merged-redactors-spec
spec:
  redactors:
  - fileSelector:
      file: data/my-password-dump
    name: replace password
...
  • From stdin
[evans] $ cat sample-troubleshoot.yaml | support-bundle --dry-run -
apiVersion: troubleshoot.sh/v1beta2
kind: Redactor
metadata:
  creationTimestamp: null
  name: merged-redactors-spec
spec:
  redactors:
  - fileSelector:
      file: data/my-password-dump
    name: replace password
....

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated. For changes to https://troubleshoot.sh/ create a PR here

Does this PR introduce a breaking change?

  • Yes
  • No

@banjoh banjoh requested a review from a team as a code owner September 12, 2023 14:07
@banjoh banjoh marked this pull request as draft September 12, 2023 14:07
@banjoh banjoh marked this pull request as ready for review September 22, 2023 16:29
@CpuID
Copy link
Contributor

CpuID commented Sep 22, 2023

I've started review this (on my phone) but need to finish on a computer - found a few things I want to verify

Copy link
Contributor

@CpuID CpuID left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM at a glance but there's a failing test. once the tests are passing I'll approve 👍

}

// Check if we have any collectors to run in the support bundle specs
if len(mainBundle.Spec.Collectors) == 0 && len(mainBundle.Spec.HostCollectors) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default, we have ClusterInfo and ClusterResources even without any collectors, I think maybe we don't need this check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I moved that check to a different place.

support-bundle should error of there is no spec at all. Providing an empty spec should automatically add the ClusterInfo and ClusterResources collectors.

@banjoh banjoh force-pushed the em/dry-run-support-bundle branch from 4390e14 to 2b04694 Compare September 25, 2023 11:22
@banjoh
Copy link
Member Author

banjoh commented Sep 26, 2023

LGTM at a glance but there's a failing test. once the tests are passing I'll approve 👍

Changes causing tests to fail have been made.

@banjoh banjoh mentioned this pull request Oct 2, 2023
6 tasks
@arcolife arcolife self-requested a review October 3, 2023 05:30
@banjoh banjoh merged commit 15a4802 into replicatedhq:main Oct 10, 2023
22 checks passed
@banjoh banjoh deleted the em/dry-run-support-bundle branch October 10, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose rendered spec after merging via an API and the cli
3 participants