replicatedhq / troubleshoot

Preflight Checks and Support Bundles Framework for Kubernetes Applications
https://troubleshoot.sh
Apache License 2.0
539 stars 92 forks source link

bug: [sc-103753] Host analysers are not deduplicating during multiple spec merges #1485 #1542

Closed nvanthao closed 2 months ago

nvanthao commented 2 months ago

Description, Motivation and Context

Fixes: https://github.com/replicatedhq/troubleshoot/issues/1485

Given spec sb.yaml

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  name: sb
spec:
  analyzers:
  - clusterVersion: {}
  hostCollectors:
  - cpu: {}
  hostAnalyzers:
  - cpu: {}

and command

support-bundle --interactive=false sb.yaml sb.yaml --dry-run

Before

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  creationTimestamp: null
  name: merged-support-bundle-spec
spec:
  analyzers:
  - clusterVersion:
      outcomes: null
  - clusterVersion:
      outcomes: null
  hostAnalyzers:
  - cpu:
      outcomes: null
  - cpu:
      outcomes: null
  hostCollectors:
  - cpu: {}
  - cpu: {}
status: {}

After

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  creationTimestamp: null
  name: merged-support-bundle-spec
spec:
  analyzers:
  - clusterVersion:
      outcomes: null
  hostAnalyzers:
  - cpu:
      outcomes: null
  hostCollectors:
  - cpu: {}
status: {}

Checklist

Does this PR introduce a breaking change?

Duplicated specs with Analyzer, HostCollector and HostAnalayzer will now be merged by their stringified content

xavpaice commented 2 months ago

quick question - how does this interact if there's a url in one of the specs? Just want to confirm that the dedup happens after the url content replaced that particular spec.

nvanthao commented 2 months ago

the dedupe happens after loading URI spec here https://github.com/replicatedhq/troubleshoot/blob/f7ac39f1cb8eedae250e5cf3f81bdf86c0287172/cmd/troubleshoot/cli/run.go#L297