-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
auto_resolver.go
74 lines (66 loc) · 2.09 KB
/
auto_resolver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package ami
import (
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/kris-nova/logger"
"github.com/pkg/errors"
"github.com/weaveworks/eksctl/pkg/utils"
)
// ImageSearchPatterns is a map of image search patterns by
// image OS family and by class
var ImageSearchPatterns = map[string]map[string]map[int]string{
"1.10": {
ImageFamilyAmazonLinux2: {
ImageClassGeneral: "amazon-eks-node-1.10-v*",
ImageClassGPU: "amazon-eks-gpu-node-1.10-*",
},
ImageFamilyUbuntu1804: {
ImageClassGeneral: "ubuntu-eks/1.10.3/*",
},
},
"1.11": {
ImageFamilyAmazonLinux2: {
ImageClassGeneral: "amazon-eks-node-1.11-v*",
ImageClassGPU: "amazon-eks-gpu-node-1.11-*",
},
ImageFamilyUbuntu1804: {
ImageClassGeneral: "ubuntu-eks/1.11.5/*",
},
},
"1.12": {
ImageFamilyAmazonLinux2: {
ImageClassGeneral: "amazon-eks-node-1.12-v*",
ImageClassGPU: "amazon-eks-gpu-node-1.12-*",
},
ImageFamilyUbuntu1804: {
ImageClassGeneral: "ubuntu-eks/1.12.6/*",
},
},
}
// AutoResolver resolves the AMi to the defaults for the region
// by querying AWS EC2 API for the AMI to use
type AutoResolver struct {
api ec2iface.EC2API
}
// Resolve will return an AMI to use based on the default AMI for
// each region
func (r *AutoResolver) Resolve(region, version, instanceType, imageFamily string) (string, error) {
logger.Debug("resolving AMI using AutoResolver for region %s, instanceType %s and imageFamily %s", region, instanceType, imageFamily)
p := ImageSearchPatterns[version][imageFamily][ImageClassGeneral]
if utils.IsGPUInstanceType(instanceType) {
var ok bool
p, ok = ImageSearchPatterns[version][imageFamily][ImageClassGPU]
if !ok {
logger.Critical("image family %s doesn't support GPU image class", imageFamily)
return "", NewErrFailedResolution(region, version, instanceType, imageFamily)
}
}
id, err := FindImage(r.api, p, imageFamily)
if err != nil {
return "", errors.Wrap(err, "error getting AMI")
}
return id, nil
}
// NewAutoResolver creates a new AutoResolver
func NewAutoResolver(api ec2iface.EC2API) *AutoResolver {
return &AutoResolver{api: api}
}