Skip to content

Commit

Permalink
save YAML spec of preflight
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanthao committed Dec 31, 2024
1 parent a029c9f commit 266678f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions pkg/preflight/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/replicatedhq/troubleshoot/pkg/constants"
"github.com/replicatedhq/troubleshoot/pkg/convert"
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
"github.com/replicatedhq/troubleshoot/pkg/loader"
"github.com/replicatedhq/troubleshoot/pkg/types"
"github.com/replicatedhq/troubleshoot/pkg/version"
"github.com/spf13/viper"
Expand Down Expand Up @@ -180,6 +181,13 @@ func RunPreflights(interactive bool, output string, format string, args []string
return errors.Wrap(err, "failed to save version file")
}

// save final preflight spec used to geneate the preflight checks
err = savePreflightSpecToBundle(specs, collectorResults, bundlePath)
if err != nil {
// still allow the preflight to be created
klog.Errorf("failed to save preflight YAML spec: %v", err)
}

analyzeResults, err := analyzer.AnalyzeLocal(ctx, bundlePath, analyzers, hostAnalyzers)
if err != nil {
return errors.Wrap(err, "failed to analyze support bundle")
Expand Down Expand Up @@ -469,3 +477,24 @@ func parseTimeFlags(v *viper.Viper, collectors []*troubleshootv1beta2.Collect) e
}
return nil
}

func savePreflightSpecToBundle(specs *loader.TroubleshootKinds, result collect.CollectorResult, bundlePath string) error {
yamlContent, err := specs.ToYaml()
if err != nil {
return errors.Wrap(err, "failed to convert preflight specs to yaml")
}
err = result.SaveResult(bundlePath, constants.SPEC_FILENAME, bytes.NewBuffer([]byte(yamlContent)))
if err != nil {
return errors.Wrap(err, "failed to write preflight spec to bundle")
}
// redact the final YAML spec
singleResult := map[string][]byte{
constants.SPEC_FILENAME: []byte(yamlContent),
}

err = collect.RedactResult(bundlePath, singleResult, nil)
if err != nil {
return errors.Wrap(err, "failed to redact final preflight yaml spec")
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/supportbundle/supportbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func saveAndRedactFinalSpec(spec *troubleshootv1beta2.SupportBundleSpec, result
return errors.Wrap(err, "failed to write final support bundle yaml spec")
}

// react the final YAML spec
// redact the final YAML spec
singleResult := map[string][]byte{
constants.SPEC_FILENAME: []byte(yamlContent),
}
Expand Down

0 comments on commit 266678f

Please sign in to comment.