Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit afcd99a

Browse files
Migrate to flatcar linux from coreos (#1836)
* Migrate to flatcar linux from coreos * Remove errors package references - stick with fmt.Errorf Reduce nesting in GetAMI function
1 parent 372f6e9 commit afcd99a

File tree

7 files changed

+53
-52
lines changed

7 files changed

+53
-52
lines changed

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
"github.com/kubernetes-incubator/kube-aws/builtin"
88
"github.com/kubernetes-incubator/kube-aws/core/root/config"
9-
"github.com/kubernetes-incubator/kube-aws/coreos/amiregistry"
109
"github.com/kubernetes-incubator/kube-aws/filegen"
10+
"github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry"
1111
"github.com/kubernetes-incubator/kube-aws/logger"
1212
"github.com/spf13/cobra"
1313
)

coreos/amiregistry/amiregistry.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

flatcar/amiregistry/amiregistry.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package amiregistry
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
)
7+
8+
func GetAMI(region, channel string) (string, error) {
9+
10+
amis, err := GetAMIData(channel)
11+
12+
if err != nil {
13+
return "", fmt.Errorf("uanble to fetch AMI for channel \"%s\": %v", channel, err)
14+
}
15+
16+
for _, v := range amis {
17+
if v["name"] != region {
18+
continue
19+
}
20+
if hvm, ok := v["hvm"]; ok {
21+
return hvm, nil
22+
} else {
23+
break
24+
}
25+
}
26+
27+
return "", fmt.Errorf("could not find \"hvm\" image for region \"%s\" in flatcar channel \"%s\"", region, channel)
28+
}
29+
30+
func GetAMIData(channel string) ([]map[string]string, error) {
31+
url := fmt.Sprintf("https://%s.release.flatcar-linux.net/amd64-usr/current/flatcar_production_ami_all.json", channel)
32+
r, err := newHttp().Get(url)
33+
if err != nil {
34+
return nil, fmt.Errorf("failed to get AMI data from url \"%s\": %v", channel, err)
35+
}
36+
37+
if r.StatusCode != 200 {
38+
return nil, fmt.Errorf("failed to get AMI data from url \"%s\": invalid status code: %d", url, r.StatusCode)
39+
}
40+
41+
output := map[string][]map[string]string{}
42+
43+
err = json.NewDecoder(r.Body).Decode(&output)
44+
if err != nil {
45+
return nil, fmt.Errorf("failed to parse AMI data from url \"%s\": %v", url, err)
46+
}
47+
r.Body.Close()
48+
49+
return output["amis"], nil
50+
}

pkg/model/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/kubernetes-incubator/kube-aws/coreos/amiregistry"
7+
"github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry"
88
"github.com/kubernetes-incubator/kube-aws/pkg/api"
99
"github.com/pkg/errors"
1010
)

pkg/model/node_pool_compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package model
33
import (
44
"fmt"
55

6-
"github.com/kubernetes-incubator/kube-aws/coreos/amiregistry"
6+
"github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry"
77
"github.com/kubernetes-incubator/kube-aws/logger"
88
"github.com/kubernetes-incubator/kube-aws/pkg/api"
99
"github.com/pkg/errors"

0 commit comments

Comments
 (0)