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

fix (supportbundle): Add default collectors when expected #1418

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

banjoh
Copy link
Member

@banjoh banjoh commented Jan 2, 2024

Description, Motivation and Context

Ensure default collectors (clusterInfo and clusterResources) are added by default whenever required when running support-bundle. Below are specs representing possible combinations

  • Defaults added
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  collectors: []
  • Defaults added
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  collectors:
  - logs: {}
  • Defaults added (similar to when spec: {} is present. spec is not mandatory. This depicts the minimum spec one can create)
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
  • Defaults NOT added
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}
  • Defaults NOT added in the resulting merged spec
apiVersion: troubleshoot.sh/v1beta2
kind: HostCollector
spec:
  collectors:
  - cpu: {}
  • Defaults added
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}
  collectors:
  - logs: {}
  • Defaults NOT added. collectors: [] is treated as if its absent
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}
  collectors: []

Fixes: #1417

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 January 2, 2024 19:47
@banjoh banjoh marked this pull request as draft January 2, 2024 19:47
@banjoh banjoh added type::bug Something isn't working bug::regression labels Jan 2, 2024
@banjoh banjoh marked this pull request as ready for review January 4, 2024 20:06
@chris-sanders
Copy link
Member

chris-sanders commented Jan 4, 2024

So this I expected

Defaults added:

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  collectors: []

But this one I'm surprised by:
Defaults NOT added:

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}
  collectors: []

Is that latter an intentional choice or a side effect of how the object is created. I would prefer these both add defaults, it looks like they would.

Wait this doesn't have defaults either?

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}

So is there an intentional rule, if hostCollectors are added don't add default collectors? Is that the logic?

@diamonwiggins
Copy link
Member

So is there an intentional rule, if hostCollectors are added don't add default collectors? Is that the logic?

I think this is what we did in the past to avoid any code paths that would try contacting a Kubernetes cluster if there were only host collectors/analyzers in the spec. As in we figured it was intentional that's the behavior you wanted it you didn't at least include an empty collector/analyzer property.

@DexterYan
Copy link
Member

According the test cases, I saw

  • Defaults added
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  analyzers: []

just to confirm it will not have Defaults as follow, right?

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}
  analyzers: []

@banjoh
Copy link
Member Author

banjoh commented Jan 5, 2024

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
hostCollectors:

  • cpu: {}
    analyzers: []

Correct. Defaults will not be added. analyzers: [] is also treated the same as being absent

@banjoh
Copy link
Member Author

banjoh commented Jan 5, 2024

But this one I'm surprised by: Defaults NOT added:

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
spec:
  hostCollectors:
  - cpu: {}
  collectors: []

Is that latter an intentional choice or a side effect of how the object is created.

Yes, its intentional. Its code that was added a while back as commented in #1418 (comment)

@banjoh
Copy link
Member Author

banjoh commented Jan 5, 2024

The logic in troubleshoot treats zero length lists the same as being absent for collectors, analyzers, and redactors

Copy link
Member

@xavpaice xavpaice left a comment

Choose a reason for hiding this comment

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

I read this as a bugfix, making things behave as we originally intended.

@banjoh banjoh merged commit e4363a1 into replicatedhq:main Jan 8, 2024
46 of 47 checks passed
@banjoh banjoh deleted the em/fix-zero-length-sb-collectors branch January 8, 2024 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug::regression type::bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misbehaviour when merging a support bundle spec with an empty or missing collectors list
5 participants