1
- // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
1
+ // Licensed under the Apache License, Version 2.0 (the "License");
2
+ // you may not use this file except in compliance with the License.
3
+ // You may obtain a copy of the License at
2
4
//
3
- // Licensed under the Apache License, Version 2.0 (the "License"). You may
4
- // not use this file except in compliance with the License. A copy of the
5
- // License is located at
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
6
//
7
- // http://aws.amazon.com/apache2.0/
8
- //
9
- // or in the "license" file accompanying this file. This file is distributed
10
- // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11
- // express or implied. See the License for the specific language governing
12
- // permissions and limitations under the License.
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
13
12
14
13
package main
15
14
@@ -24,18 +23,19 @@ import (
24
23
"syscall"
25
24
"time"
26
25
27
- commandline "github.com/aws/amazon-ec2-instance-selector/v3/pkg/cli"
28
- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/env"
29
- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/instancetypes"
30
- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector"
31
- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector/outputs"
32
- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/sorter"
33
26
"github.com/aws/aws-sdk-go-v2/aws"
34
27
"github.com/aws/aws-sdk-go-v2/config"
35
28
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
36
29
tea "github.com/charmbracelet/bubbletea"
37
30
"github.com/spf13/cobra"
38
31
"go.uber.org/multierr"
32
+
33
+ commandline "github.com/aws/amazon-ec2-instance-selector/v3/pkg/cli"
34
+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/env"
35
+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/instancetypes"
36
+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector"
37
+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector/outputs"
38
+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/sorter"
39
39
)
40
40
41
41
const (
@@ -45,19 +45,19 @@ const (
45
45
defaultProfile = "default"
46
46
awsConfigFile = "~/.aws/config"
47
47
// 0 means the last price
48
- // increasing this results in a lot more API calls to EC2 which can slow things down
48
+ // increasing this results in a lot more API calls to EC2 which can slow things down.
49
49
spotPricingDaysBack = 0
50
50
51
51
tableOutput = "table"
52
52
tableWideOutput = "table-wide"
53
53
oneLine = "one-line"
54
54
bubbleTeaOutput = "interactive"
55
55
56
- // Sort filter default
56
+ // Sort filter default.
57
57
instanceNamePath = ".InstanceType"
58
58
)
59
59
60
- // Filter Flag Constants
60
+ // Filter Flag Constants.
61
61
const (
62
62
vcpus = "vcpus"
63
63
memory = "memory"
@@ -106,14 +106,14 @@ const (
106
106
generation = "generation"
107
107
)
108
108
109
- // Aggregate Filter Flags
109
+ // Aggregate Filter Flags.
110
110
const (
111
111
instanceTypeBase = "base-instance-type"
112
112
flexible = "flexible"
113
113
service = "service"
114
114
)
115
115
116
- // Configuration Flag Constants
116
+ // Configuration Flag Constants.
117
117
const (
118
118
maxResults = "max-results"
119
119
profile = "profile"
@@ -128,13 +128,10 @@ const (
128
128
sortBy = "sort-by"
129
129
)
130
130
131
- var (
132
- // versionID is overridden at compilation with the version based on the git tag
133
- versionID = "dev"
134
- )
131
+ // versionID is overridden at compilation with the version based on the git tag
132
+ var versionID = "dev"
135
133
136
134
func main () {
137
-
138
135
log .SetOutput (os .Stderr )
139
136
log .SetPrefix ("NOTE: " )
140
137
log .SetFlags (log .Flags () &^ (log .Ldate | log .Ltime ))
@@ -276,7 +273,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
276
273
cacheTTLDuration := time .Hour * time .Duration (* cli .IntMe (flags [cacheTTL ]))
277
274
instanceSelector , err := selector .NewWithCache (ctx , cfg , cacheTTLDuration , * cli .StringMe (flags [cacheDir ]))
278
275
if err != nil {
279
- fmt .Printf ("An error occurred when initialising the ec2 selector: %v" , err )
276
+ fmt .Printf ("An error occurred when initializing the ec2 selector: %v" , err )
280
277
os .Exit (1 )
281
278
}
282
279
if flags [debug ] != nil {
@@ -477,7 +474,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
477
474
var instanceTypes []string
478
475
if outputFlag != nil && * outputFlag == bubbleTeaOutput {
479
476
p := tea .NewProgram (outputs .NewBubbleTeaModel (instanceTypesDetails ), tea .WithMouseCellMotion ())
480
- if err := p .Start (); err != nil {
477
+ if _ , err := p .Run (); err != nil {
481
478
fmt .Printf ("An error occurred when starting bubble tea: %v" , err )
482
479
os .Exit (1 )
483
480
}
@@ -516,7 +513,7 @@ func hydrateCaches(ctx context.Context, instanceSelector selector.Selector) (err
516
513
defer waitGroup .Done ()
517
514
if instanceSelector .EC2Pricing .OnDemandCacheCount () == 0 {
518
515
if err := instanceSelector .EC2Pricing .RefreshOnDemandCache (ctx ); err != nil {
519
- return multierr .Append (errs , fmt .Errorf ("There was a problem refreshing the on-demand pricing cache: %w" , err ))
516
+ return multierr .Append (errs , fmt .Errorf ("there was a problem refreshing the on-demand pricing cache: %w" , err ))
520
517
}
521
518
}
522
519
return nil
@@ -525,7 +522,7 @@ func hydrateCaches(ctx context.Context, instanceSelector selector.Selector) (err
525
522
defer waitGroup .Done ()
526
523
if instanceSelector .EC2Pricing .SpotCacheCount () == 0 {
527
524
if err := instanceSelector .EC2Pricing .RefreshSpotCache (ctx , spotPricingDaysBack ); err != nil {
528
- return multierr .Append (errs , fmt .Errorf ("There was a problem refreshing the spot pricing cache: %w" , err ))
525
+ return multierr .Append (errs , fmt .Errorf ("there was a problem refreshing the spot pricing cache: %w" , err ))
529
526
}
530
527
}
531
528
return nil
@@ -534,15 +531,19 @@ func hydrateCaches(ctx context.Context, instanceSelector selector.Selector) (err
534
531
defer waitGroup .Done ()
535
532
if instanceSelector .InstanceTypesProvider .CacheCount () == 0 {
536
533
if _ , err := instanceSelector .InstanceTypesProvider .Get (ctx , nil ); err != nil {
537
- return multierr .Append (errs , fmt .Errorf ("There was a problem refreshing the instance types cache: %w" , err ))
534
+ return multierr .Append (errs , fmt .Errorf ("there was a problem refreshing the instance types cache: %w" , err ))
538
535
}
539
536
}
540
537
return nil
541
538
},
542
539
}
543
540
wg .Add (len (hydrateTasks ))
544
541
for _ , task := range hydrateTasks {
545
- go task (wg )
542
+ go func () {
543
+ if err := task (wg ); err != nil {
544
+ log .Printf ("Hydrate task error: %v" , err )
545
+ }
546
+ }()
546
547
}
547
548
wg .Wait ()
548
549
return errs
0 commit comments