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

Migrate to flatcar linux from coreos #1836

Merged
merged 2 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
49 changes: 0 additions & 49 deletions coreos/amiregistry/amiregistry.go

This file was deleted.

50 changes: 50 additions & 0 deletions flatcar/amiregistry/amiregistry.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion pkg/model/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/node_pool_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down