diff --git a/builtin/files/cluster.yaml.tmpl b/builtin/files/cluster.yaml.tmpl index 16849ba23..923807061 100644 --- a/builtin/files/cluster.yaml.tmpl +++ b/builtin/files/cluster.yaml.tmpl @@ -6,17 +6,17 @@ clusterName: {{.ClusterName}} # The URI of the S3 bucket for the cluster s3URI: {{.S3URI}} -# CoreOS release channel to use. Currently supported options: alpha, beta, stable +# Flatcar release channel to use. Currently supported options: alpha, beta, stable # See coreos.com/releases for more information #releaseChannel: stable -# The AMI ID of CoreOS. +# The AMI ID of Flatcar. # # To update this to the latest AMI run the following command with the appropriate region and channel then place the resulting ID here -# REGION=eu-west-1 && CHANNEL=stable && curl -s https://coreos.com/dist/aws/aws-$CHANNEL.json | jq -r ".\"$REGION\".hvm" +# REGION=eu-west-1 CHANNEL=stable curl -s https://$CHANNEL.release.flatcar-linux.net/amd64-usr/current/flatcar_production_ami_all.json | jq -r ".amis[] | select(.name==\"$REGION\") .hvm amiId: "{{.AmiId}}" -# Container Linux has automatic updates https://coreos.com/os/docs/latest/update-strategies.html. This can be a risk in certain situations and this is why is disabled by default and you can enable it by setting this param to false. +# Flatcar has automatic updates https://docs.flatcar-linux.org/os/update-strategies/#disable-automatic-updates-daemon. This can be a risk in certain situations and this is why is disabled by default and you can enable it by setting this param to false. disableContainerLinuxAutomaticUpdates: true # Customizes how kube-aws deals with CloudFormation diff --git a/cmd/init.go b/cmd/init.go index 47fa60ab7..47fb9344e 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -6,8 +6,8 @@ import ( "github.com/kubernetes-incubator/kube-aws/builtin" "github.com/kubernetes-incubator/kube-aws/core/root/config" - "github.com/kubernetes-incubator/kube-aws/coreos/amiregistry" "github.com/kubernetes-incubator/kube-aws/filegen" + "github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry" "github.com/kubernetes-incubator/kube-aws/logger" "github.com/spf13/cobra" ) diff --git a/coreos/amiregistry/amiregistry.go b/coreos/amiregistry/amiregistry.go deleted file mode 100644 index 805507908..000000000 --- a/coreos/amiregistry/amiregistry.go +++ /dev/null @@ -1,49 +0,0 @@ -package amiregistry - -import ( - "encoding/json" - "fmt" - "github.com/pkg/errors" -) - -func GetAMI(region, channel string) (string, error) { - - regions, err := GetAMIData(channel) - - if err != nil { - return "", errors.Wrapf(err, "uanble to fetch AMI for channel \"%s\": %v", channel, err) - } - - amis, ok := regions[region] - if !ok { - return "", errors.Errorf("could not find region \"%s\" for channel \"%s\"", region, channel) - } - - if ami, ok := amis["hvm"]; ok { - return ami, nil - } - - return "", errors.Errorf("could not find \"hvm\" image for region \"%s\" and channel \"%s\"", region, channel) -} - -func GetAMIData(channel string) (map[string]map[string]string, error) { - url := fmt.Sprintf("https://coreos.com/dist/aws/aws-%s.json", channel) - r, err := newHttp().Get(url) - if err != nil { - return nil, errors.Wrapf(err, "failed to get AMI data from url \"%s\": %v", channel, err) - } - - if r.StatusCode != 200 { - return nil, errors.Wrapf(err, "failed to get AMI data from url \"%s\": invalid status code: %d", url, r.StatusCode) - } - - output := map[string]map[string]string{} - - err = json.NewDecoder(r.Body).Decode(&output) - if err != nil { - return nil, errors.Wrapf(err, "failed to parse AMI data from url \"%s\": %v", url, err) - } - r.Body.Close() - - return output, nil -} diff --git a/flatcar/amiregistry/amiregistry.go b/flatcar/amiregistry/amiregistry.go new file mode 100644 index 000000000..f5de60911 --- /dev/null +++ b/flatcar/amiregistry/amiregistry.go @@ -0,0 +1,50 @@ +package amiregistry + +import ( + "encoding/json" + "fmt" +) + +func GetAMI(region, channel string) (string, error) { + + amis, err := GetAMIData(channel) + + if err != nil { + return "", fmt.Errorf("uanble to fetch AMI for channel \"%s\": %v", channel, err) + } + + for _, v := range amis { + if v["name"] != region { + continue + } + if hvm, ok := v["hvm"]; ok { + return hvm, nil + } else { + break + } + } + + return "", fmt.Errorf("could not find \"hvm\" image for region \"%s\" in flatcar channel \"%s\"", region, channel) +} + +func GetAMIData(channel string) ([]map[string]string, error) { + url := fmt.Sprintf("https://%s.release.flatcar-linux.net/amd64-usr/current/flatcar_production_ami_all.json", channel) + r, err := newHttp().Get(url) + if err != nil { + return nil, fmt.Errorf("failed to get AMI data from url \"%s\": %v", channel, err) + } + + if r.StatusCode != 200 { + return nil, fmt.Errorf("failed to get AMI data from url \"%s\": invalid status code: %d", url, r.StatusCode) + } + + output := map[string][]map[string]string{} + + err = json.NewDecoder(r.Body).Decode(&output) + if err != nil { + return nil, fmt.Errorf("failed to parse AMI data from url \"%s\": %v", url, err) + } + r.Body.Close() + + return output["amis"], nil +} diff --git a/coreos/amiregistry/reliable_http.go b/flatcar/amiregistry/reliable_http.go similarity index 100% rename from coreos/amiregistry/reliable_http.go rename to flatcar/amiregistry/reliable_http.go diff --git a/coreos/amiregistry/reliable_http_test.go b/flatcar/amiregistry/reliable_http_test.go similarity index 100% rename from coreos/amiregistry/reliable_http_test.go rename to flatcar/amiregistry/reliable_http_test.go diff --git a/pkg/model/compiler.go b/pkg/model/compiler.go index 3d9acbd3f..ef3795742 100644 --- a/pkg/model/compiler.go +++ b/pkg/model/compiler.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/kubernetes-incubator/kube-aws/coreos/amiregistry" + "github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry" "github.com/kubernetes-incubator/kube-aws/pkg/api" "github.com/pkg/errors" ) diff --git a/pkg/model/node_pool_compile.go b/pkg/model/node_pool_compile.go index cd3767051..68add265f 100644 --- a/pkg/model/node_pool_compile.go +++ b/pkg/model/node_pool_compile.go @@ -3,7 +3,7 @@ package model import ( "fmt" - "github.com/kubernetes-incubator/kube-aws/coreos/amiregistry" + "github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry" "github.com/kubernetes-incubator/kube-aws/logger" "github.com/kubernetes-incubator/kube-aws/pkg/api" "github.com/pkg/errors"