feat: [sc-106759] Troubleshoot: uri field only download when we're not downloading (#1567)

* remove uri: when url is provided
This commit is contained in:
Gerard Nguyen
2024-06-24 10:12:41 +10:00
committed by GitHub
parent edfa01c5c4
commit 191ebdb598
3 changed files with 68 additions and 4 deletions

View File

@@ -78,6 +78,7 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
ctx = context.Background()
}
var kindsFromURL *loader.TroubleshootKinds
rawSpecs := []string{}
for _, v := range args {
@@ -174,22 +175,35 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
if err != nil {
return nil, types.NewExitCodeError(constants.EXIT_CODE_SPEC_ISSUES, err)
}
var specFromURL string
if parsedURL.Host == "kots.io" {
// To download specs from kots.io, we need to set the User-Agent header
rawSpec, err := downloadFromHttpURL(ctx, v, map[string]string{
specFromURL, err = downloadFromHttpURL(ctx, v, map[string]string{
"User-Agent": "Replicated_Troubleshoot/v1beta1",
})
if err != nil {
return nil, err
}
rawSpecs = append(rawSpecs, rawSpec)
} else {
rawSpec, err := downloadFromHttpURL(ctx, v, nil)
specFromURL, err = downloadFromHttpURL(ctx, v, nil)
if err != nil {
return nil, err
}
rawSpecs = append(rawSpecs, rawSpec)
}
// load URL spec first to remove URI key from the spec
kindsFromURL, err = loader.LoadSpecs(ctx, loader.LoadOptions{
RawSpec: specFromURL,
})
if err != nil {
return nil, err
}
// remove URI key from the spec if any
for i := range kindsFromURL.SupportBundlesV1Beta2 {
kindsFromURL.SupportBundlesV1Beta2[i].Spec.Uri = ""
}
}
}
}
@@ -200,6 +214,9 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
if err != nil {
return nil, err
}
if kindsFromURL != nil {
kinds.Add(kindsFromURL)
}
if vp.GetBool("load-cluster-specs") {
clusterKinds, err := LoadFromCluster(ctx, client, vp.GetStringSlice("selector"), vp.GetString("namespace"))