From 40e616dfa50ef10485db928a078746e4990f3272 Mon Sep 17 00:00:00 2001 From: Jorge Arco Date: Fri, 15 May 2020 12:36:43 +0200 Subject: [PATCH 1/2] Flatcar migration --- builtin/files/cluster.yaml.tmpl | 8 +-- cmd/init.go | 2 +- coreos/amiregistry/amiregistry.go | 49 ------------------ flatcar/amiregistry/amiregistry.go | 50 +++++++++++++++++++ .../amiregistry/reliable_http.go | 0 .../amiregistry/reliable_http_test.go | 0 pkg/model/compiler.go | 2 +- pkg/model/node_pool_compile.go | 2 +- 8 files changed, 57 insertions(+), 56 deletions(-) delete mode 100644 coreos/amiregistry/amiregistry.go create mode 100644 flatcar/amiregistry/amiregistry.go rename {coreos => flatcar}/amiregistry/reliable_http.go (100%) rename {coreos => flatcar}/amiregistry/reliable_http_test.go (100%) 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..2919caa2b 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -6,7 +6,7 @@ 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/flatcar/amiregistry" "github.com/kubernetes-incubator/kube-aws/filegen" "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..e778f146d --- /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 +} \ No newline at end of file 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" From 7614e685ab02c07f87db89475fc53d7d0dd435fe Mon Sep 17 00:00:00 2001 From: Jorge Arco Date: Fri, 15 May 2020 13:25:55 +0200 Subject: [PATCH 2/2] CS --- cmd/init.go | 2 +- flatcar/amiregistry/amiregistry.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 2919caa2b..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/flatcar/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/flatcar/amiregistry/amiregistry.go b/flatcar/amiregistry/amiregistry.go index e778f146d..f5de60911 100644 --- a/flatcar/amiregistry/amiregistry.go +++ b/flatcar/amiregistry/amiregistry.go @@ -47,4 +47,4 @@ func GetAMIData(channel string) ([]map[string]string, error) { r.Body.Close() return output["amis"], nil -} \ No newline at end of file +}