@@ -11,6 +11,7 @@ import (
11
11
"strings"
12
12
"time"
13
13
14
+ "github.com/fatih/color"
14
15
"github.com/pkg/errors"
15
16
"github.com/replicatedhq/troubleshoot/internal/util"
16
17
"github.com/replicatedhq/troubleshoot/pkg/constants"
@@ -78,7 +79,7 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
78
79
ctx = context .Background ()
79
80
}
80
81
81
- var kindsFromURL * loader.TroubleshootKinds
82
+ allURLSpecs := loader .NewTroubleshootKinds ()
82
83
rawSpecs := []string {}
83
84
84
85
for _ , v := range args {
@@ -176,34 +177,33 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
176
177
return nil , types .NewExitCodeError (constants .EXIT_CODE_SPEC_ISSUES , err )
177
178
}
178
179
179
- var specFromURL string
180
+ var rawURLSpec string
181
+ headers := map [string ]string {}
182
+
180
183
if parsedURL .Host == "kots.io" {
181
- // To download specs from kots.io, we need to set the User-Agent header
182
- specFromURL , err = downloadFromHttpURL (ctx , v , map [string ]string {
183
- "User-Agent" : "Replicated_Troubleshoot/v1beta1" ,
184
- })
185
- if err != nil {
186
- return nil , err
187
- }
188
- } else {
189
- specFromURL , err = downloadFromHttpURL (ctx , v , nil )
190
- if err != nil {
191
- return nil , err
192
- }
184
+ headers ["User-Agent" ] = "Replicated_Troubleshoot/v1beta1"
185
+ }
186
+ rawURLSpec , err = downloadFromHttpURL (ctx , v , headers )
187
+ if err != nil {
188
+ fmt .Println (color .YellowString ("failed to download spec from URI %q: %v\n " , v , err ))
189
+ continue
193
190
}
194
191
195
192
// load URL spec first to remove URI key from the spec
196
- kindsFromURL , err = loader .LoadSpecs (ctx , loader.LoadOptions {
197
- RawSpec : specFromURL ,
193
+ urlSpec , err : = loader .LoadSpecs (ctx , loader.LoadOptions {
194
+ RawSpec : rawURLSpec ,
198
195
})
199
196
if err != nil {
200
- return nil , err
197
+ fmt .Println (color .YellowString ("failed to load spec from URI %q: %v\n " , v , err ))
198
+ continue
201
199
}
202
200
// remove URI key from the spec if any
203
- for i := range kindsFromURL .SupportBundlesV1Beta2 {
204
- kindsFromURL .SupportBundlesV1Beta2 [i ].Spec .Uri = ""
201
+ for i := range urlSpec .SupportBundlesV1Beta2 {
202
+ urlSpec .SupportBundlesV1Beta2 [i ].Spec .Uri = ""
205
203
}
206
204
205
+ allURLSpecs .Add (urlSpec )
206
+
207
207
}
208
208
}
209
209
}
@@ -214,8 +214,8 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
214
214
if err != nil {
215
215
return nil , err
216
216
}
217
- if kindsFromURL != nil {
218
- kinds .Add (kindsFromURL )
217
+ if allURLSpecs . Len () > 0 {
218
+ kinds .Add (allURLSpecs )
219
219
}
220
220
221
221
if vp .GetBool ("load-cluster-specs" ) {
@@ -224,8 +224,7 @@ func LoadFromCLIArgs(ctx context.Context, client kubernetes.Interface, args []st
224
224
if kinds .IsEmpty () {
225
225
return nil , types .NewExitCodeError (constants .EXIT_CODE_SPEC_ISSUES , err )
226
226
}
227
- // TODO: Consider colour coding and graceful failures when loading specs
228
- fmt .Printf ("failed to load specs from the cluster: %v\n " , err )
227
+ fmt .Println (color .YellowString ("failed to load specs from cluster: %v\n " , err ))
229
228
} else {
230
229
kinds .Add (clusterKinds )
231
230
}
0 commit comments