Skip to content

Commit 56a68a4

Browse files
authored
Issue #695 - Add --no-uri flag to support-bundle to ignore the uri field and revert back to the default spec… (#717)
Add --follow-uri flag to support-bundle to ignore the uri field when set in a spec Implement the new CLI flag in `root.go` so we can pass it if we need to ignore the `uri` field in a spec. This also serves as a minimal documentation effort when running `support-bundle --help`. Fixes: #695
1 parent b3e662c commit 56a68a4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cmd/troubleshoot/cli/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
5858
cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results")
5959
cmd.Flags().MarkHidden("allow-insecure-connections")
6060

61+
// `no-uri` references the `followURI` functionality where we can use an upstream spec when creating a support bundle
62+
// This flag makes sure we can also disable this and fall back to the default spec.
63+
cmd.Flags().Bool("no-uri", false, "When this flag is used, Troubleshoot does not attempt to retrieve the bundle referenced by the uri: field in the spec.`")
64+
6165
viper.BindPFlags(cmd.Flags())
6266

6367
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

cmd/troubleshoot/cli/run.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,21 @@ func runTroubleshoot(v *viper.Viper, arg []string) error {
8383

8484
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
8585
additionalRedactors := &troubleshootv1beta2.Redactor{}
86-
for i, v := range arg {
8786

88-
collectorContent, err := supportbundle.LoadSupportBundleSpec(v)
87+
// Defining `v` below will render using `v` in reference to Viper unusable.
88+
// Therefore refactoring `v` to `val` will make sure we can still use it.
89+
for i, val := range arg {
90+
91+
collectorContent, err := supportbundle.LoadSupportBundleSpec(val)
8992
if err != nil {
9093
return errors.Wrap(err, "failed to load support bundle spec")
9194
}
9295
multidocs := strings.Split(string(collectorContent), "\n---\n")
93-
supportBundle, err := supportbundle.ParseSupportBundleFromDoc([]byte(multidocs[0]))
96+
// Referencing `ParseSupportBundle with a secondary arg of `no-uri`
97+
// Will make sure we can enable or disable the use of the `Spec.uri` field for an upstream spec.
98+
// This change will not have an impact on KOTS' usage of `ParseSupportBundle`
99+
// As Kots uses `load.go` directly.
100+
supportBundle, err := supportbundle.ParseSupportBundle([]byte(multidocs[0]), !v.GetBool("no-uri"))
94101
if err != nil {
95102
return errors.Wrap(err, "failed to parse support bundle spec")
96103
}

0 commit comments

Comments
 (0)