in pkg/selector/eks.go [64:106]
func (e *EKS) getSupportedInstanceTypes(version string) ([]string, error) {
supportedInstanceTypes := []string{}
resp, err := http.Get(fmt.Sprintf("%s/archive/%s.zip", e.AMIRepoURL, version))
if err != nil {
return supportedInstanceTypes, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return supportedInstanceTypes, fmt.Errorf("Unable to retrieve EKS supported instance types, got non-200 status code: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return supportedInstanceTypes, err
}
zipReader, err := zip.NewReader(bytes.NewReader(body), int64(len(body)))
if err != nil {
return supportedInstanceTypes, err
}
// Read all the files from zip archive
for _, zipFile := range zipReader.File {
filePathParts := strings.Split(zipFile.Name, "/")
fileName := filePathParts[len(filePathParts)-1]
if fileName == eksInstanceTypesFile {
unzippedFileBytes, err := readZipFile(zipFile)
if err != nil {
log.Println(err)
continue
}
supportedInstanceTypesFileBody := string(unzippedFileBytes)
for _, line := range strings.Split(strings.Replace(supportedInstanceTypesFileBody, "\r\n", "\n", -1), "\n") {
if !strings.HasPrefix(line, "#") {
instanceType := strings.Split(line, " ")[0]
supportedInstanceTypes = append(supportedInstanceTypes, instanceType)
}
}
}
}
return supportedInstanceTypes, nil
}