mirror of https://github.com/kubernetes/kops.git
Merge pull request #1486 from justinsb/split_out_distros
Split out distros into its own package
This commit is contained in:
commit
51b764468c
|
|
@ -16,6 +16,7 @@ k8s.io/kops/federation
|
|||
k8s.io/kops/federation/model
|
||||
k8s.io/kops/federation/targets/kubernetes
|
||||
k8s.io/kops/federation/tasks
|
||||
k8s.io/kops/nodeup/pkg/distros
|
||||
k8s.io/kops/nodeup/pkg/model
|
||||
k8s.io/kops/nodeup/pkg/model/resources
|
||||
k8s.io/kops/pkg/apis/kops
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package model
|
||||
package distros
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
|
|
@ -28,6 +28,7 @@ var (
|
|||
DistributionXenial Distribution = "xenial"
|
||||
DistributionRhel7 Distribution = "rhel7"
|
||||
DistributionCentos7 Distribution = "centos7"
|
||||
DistributionCoreOS Distribution = "coreos"
|
||||
)
|
||||
|
||||
func (d Distribution) BuildTags() []string {
|
||||
|
|
@ -42,6 +43,8 @@ func (d Distribution) BuildTags() []string {
|
|||
t = []string{"_centos7"}
|
||||
case DistributionRhel7:
|
||||
t = []string{"_rhel7"}
|
||||
case DistributionCoreOS:
|
||||
t = []string{"_coreos"}
|
||||
default:
|
||||
glog.Fatalf("unknown distribution: %s", d)
|
||||
return nil
|
||||
|
|
@ -64,7 +67,7 @@ func (d Distribution) IsDebianFamily() bool {
|
|||
switch d {
|
||||
case DistributionJessie, DistributionXenial:
|
||||
return true
|
||||
case DistributionCentos7, DistributionRhel7:
|
||||
case DistributionCentos7, DistributionRhel7, DistributionCoreOS:
|
||||
return false
|
||||
default:
|
||||
glog.Fatalf("unknown distribution: %s", d)
|
||||
|
|
@ -74,10 +77,10 @@ func (d Distribution) IsDebianFamily() bool {
|
|||
|
||||
func (d Distribution) IsRHELFamily() bool {
|
||||
switch d {
|
||||
case DistributionJessie, DistributionXenial:
|
||||
return false
|
||||
case DistributionCentos7, DistributionRhel7:
|
||||
return true
|
||||
case DistributionJessie, DistributionXenial, DistributionCoreOS:
|
||||
return false
|
||||
default:
|
||||
glog.Fatalf("unknown distribution: %s", d)
|
||||
return false
|
||||
|
|
@ -89,7 +92,9 @@ func (d Distribution) IsSystemd() bool {
|
|||
case DistributionJessie, DistributionXenial:
|
||||
return true
|
||||
case DistributionCentos7, DistributionRhel7:
|
||||
return false
|
||||
return true
|
||||
case DistributionCoreOS:
|
||||
return true
|
||||
default:
|
||||
glog.Fatalf("unknown distribution: %s", d)
|
||||
return false
|
||||
|
|
@ -14,13 +14,12 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package nodeup
|
||||
package distros
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/glog"
|
||||
"io/ioutil"
|
||||
"k8s.io/kops/nodeup/pkg/model"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
|
@ -28,14 +27,14 @@ import (
|
|||
|
||||
// FindDistribution identifies the distribution on which we are running
|
||||
// We will likely remove this when everything is containerized
|
||||
func FindDistribution(rootfs string) (model.Distribution, error) {
|
||||
func FindDistribution(rootfs string) (Distribution, error) {
|
||||
// Ubuntu has /etc/lsb-release (and /etc/debian_version)
|
||||
lsbRelease, err := ioutil.ReadFile(path.Join(rootfs, "etc/lsb-release"))
|
||||
if err == nil {
|
||||
for _, line := range strings.Split(string(lsbRelease), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "DISTRIB_CODENAME=xenial" {
|
||||
return model.DistributionXenial, nil
|
||||
return DistributionXenial, nil
|
||||
}
|
||||
}
|
||||
glog.Warningf("unhandled lsb-release info %q", string(lsbRelease))
|
||||
|
|
@ -48,7 +47,7 @@ func FindDistribution(rootfs string) (model.Distribution, error) {
|
|||
if err == nil {
|
||||
debianVersion := strings.TrimSpace(string(debianVersionBytes))
|
||||
if strings.HasPrefix(debianVersion, "8.") {
|
||||
return model.DistributionJessie, nil
|
||||
return DistributionJessie, nil
|
||||
} else {
|
||||
return "", fmt.Errorf("unhandled debian version %q", debianVersion)
|
||||
}
|
||||
|
|
@ -63,10 +62,10 @@ func FindDistribution(rootfs string) (model.Distribution, error) {
|
|||
for _, line := range strings.Split(string(redhatRelease), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "Red Hat Enterprise Linux Server release 7.") {
|
||||
return model.DistributionRhel7, nil
|
||||
return DistributionRhel7, nil
|
||||
}
|
||||
if strings.HasPrefix(line, "CentOS Linux release 7.") {
|
||||
return model.DistributionCentos7, nil
|
||||
return DistributionCentos7, nil
|
||||
}
|
||||
}
|
||||
glog.Warningf("unhandled redhat-release info %q", string(lsbRelease))
|
||||
|
|
@ -74,60 +73,19 @@ func FindDistribution(rootfs string) (model.Distribution, error) {
|
|||
glog.Warningf("error reading /etc/redhat-release: %v", err)
|
||||
}
|
||||
|
||||
// CoreOS uses /usr/lib/os-release
|
||||
osRelease, err := ioutil.ReadFile(path.Join(rootfs, "usr/lib/os-release"))
|
||||
if err == nil {
|
||||
for _, line := range strings.Split(string(osRelease), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "ID=coreos" {
|
||||
return DistributionCoreOS, nil
|
||||
}
|
||||
}
|
||||
glog.Warningf("unhandled os-release info %q", string(osRelease))
|
||||
} else if !os.IsNotExist(err) {
|
||||
glog.Warningf("error reading /usr/lib/os-release: %v", err)
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("cannot identify distro")
|
||||
}
|
||||
|
||||
//// FindCloudTags infers tags from the cloud environment
|
||||
//func FindCloudTags(rootfs string) ([]string, error) {
|
||||
// productVersionBytes, err := ioutil.ReadFile(path.Join(rootfs, "sys/class/dmi/id/product_version"))
|
||||
// if err == nil {
|
||||
// productVersion := strings.TrimSpace(string(productVersionBytes))
|
||||
// switch productVersion {
|
||||
// case "amazon":
|
||||
// return findCloudTagsAWS(rootfs)
|
||||
// default:
|
||||
// glog.V(2).Infof("Unknown /sys/class/dmi/id/product_version %q", productVersion)
|
||||
// }
|
||||
// } else if !os.IsNotExist(err) {
|
||||
// glog.Infof("error reading /sys/class/dmi/id/product_version: %v", err)
|
||||
// }
|
||||
// return nil, fmt.Errorf("cannot identify cloud")
|
||||
//}
|
||||
//
|
||||
//type awsIAMInfo struct {
|
||||
// Code string
|
||||
// LastUpdated string
|
||||
// InstanceProfileArn string
|
||||
// InstanceProfileId string
|
||||
//}
|
||||
//
|
||||
//// findAWSCloudTags infers cloud tags once we have determined we are on AWS
|
||||
//func findCloudTagsAWS(rootfs string) ([]string, error) {
|
||||
// tags := []string{"_aws"}
|
||||
//
|
||||
// // We can't get the tags, annoyingly
|
||||
//
|
||||
// iamInfoBytes, err := vfs.Context.ReadFile("http://169.254.169.254/2016-04-19/meta-data/iam/info")
|
||||
// if err != nil {
|
||||
// return nil, fmt.Errorf("error querying for iam info: %v", err)
|
||||
// }
|
||||
//
|
||||
// iamInfo := &awsIAMInfo{}
|
||||
// if err := json.Unmarshal(iamInfoBytes, iamInfo); err != nil {
|
||||
// glog.Infof("Invalid IAM info: %q", string(iamInfoBytes))
|
||||
// return nil, fmt.Errorf("error decoding iam info: %v", err)
|
||||
// }
|
||||
//
|
||||
// arn := iamInfo.InstanceProfileArn
|
||||
// if strings.HasSuffix(arn, "-masters") {
|
||||
// tags = append(tags, "_master")
|
||||
// } else if strings.HasSuffix(arn, "-nodes") {
|
||||
// tags = append(tags, "_master")
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected IAM role name %q", arn)
|
||||
// }
|
||||
//
|
||||
// return tags, nil
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
|
@ -16,10 +16,13 @@ limitations under the License.
|
|||
|
||||
package model
|
||||
|
||||
import "k8s.io/kops/pkg/apis/kops"
|
||||
import (
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
)
|
||||
|
||||
type NodeupModelContext struct {
|
||||
Cluster *kops.Cluster
|
||||
Architecture Architecture
|
||||
Distribution Distribution
|
||||
Distribution distros.Distribution
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/blang/semver"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/nodeup/pkg/model/resources"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
||||
|
|
@ -39,7 +40,7 @@ type dockerVersion struct {
|
|||
Hash string
|
||||
|
||||
DockerVersion string
|
||||
Distros []Distribution
|
||||
Distros []distros.Distribution
|
||||
Dependencies []string
|
||||
Architectures []Architecture
|
||||
}
|
||||
|
|
@ -51,7 +52,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.11.2",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionJessie},
|
||||
Distros: []distros.Distribution{distros.DistributionJessie},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.11.2-0~jessie",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.11.2-0~jessie_amd64.deb",
|
||||
|
|
@ -63,7 +64,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.11.2",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionXenial},
|
||||
Distros: []distros.Distribution{distros.DistributionXenial},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.11.2-0~xenial",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.11.2-0~xenial_amd64.deb",
|
||||
|
|
@ -75,7 +76,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.11.2",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionRhel7, DistributionCentos7},
|
||||
Distros: []distros.Distribution{distros.DistributionRhel7, distros.DistributionCentos7},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.11.2",
|
||||
Source: "https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-1.11.2-1.el7.centos.x86_64.rpm",
|
||||
|
|
@ -85,7 +86,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.11.2",
|
||||
Name: "docker-engine-selinux",
|
||||
Distros: []Distribution{DistributionRhel7, DistributionCentos7},
|
||||
Distros: []distros.Distribution{distros.DistributionRhel7, distros.DistributionCentos7},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.11.2",
|
||||
Source: "https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-selinux-1.11.2-1.el7.centos.noarch.rpm",
|
||||
|
|
@ -96,7 +97,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.1",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionJessie},
|
||||
Distros: []distros.Distribution{distros.DistributionJessie},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.1-0~jessie",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.1-0~jessie_amd64.deb",
|
||||
|
|
@ -108,7 +109,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.1",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionXenial},
|
||||
Distros: []distros.Distribution{distros.DistributionXenial},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.1-0~xenial",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.1-0~xenial_amd64.deb",
|
||||
|
|
@ -120,7 +121,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.1",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionRhel7, DistributionCentos7},
|
||||
Distros: []distros.Distribution{distros.DistributionRhel7, distros.DistributionCentos7},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.1",
|
||||
Source: "https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-1.12.1-1.el7.centos.x86_64.rpm",
|
||||
|
|
@ -130,7 +131,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.1",
|
||||
Name: "docker-engine-selinux",
|
||||
Distros: []Distribution{DistributionRhel7, DistributionCentos7},
|
||||
Distros: []distros.Distribution{distros.DistributionRhel7, distros.DistributionCentos7},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.1",
|
||||
Source: "https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm",
|
||||
|
|
@ -141,7 +142,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.3",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionJessie},
|
||||
Distros: []distros.Distribution{distros.DistributionJessie},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.3-0~jessie",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.3-0~jessie_amd64.deb",
|
||||
|
|
@ -155,7 +156,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.3",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionJessie},
|
||||
Distros: []distros.Distribution{distros.DistributionJessie},
|
||||
Architectures: []Architecture{ArchitectureArm},
|
||||
Version: "1.12.3-0~jessie",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.3-0~jessie_armhf.deb",
|
||||
|
|
@ -167,7 +168,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.3",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionXenial},
|
||||
Distros: []distros.Distribution{distros.DistributionXenial},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.3-0~xenial",
|
||||
Source: "http://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.3-0~xenial_amd64.deb",
|
||||
|
|
@ -179,7 +180,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.3",
|
||||
Name: "docker-engine",
|
||||
Distros: []Distribution{DistributionRhel7, DistributionCentos7},
|
||||
Distros: []distros.Distribution{distros.DistributionRhel7, distros.DistributionCentos7},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.3",
|
||||
Source: "https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-1.12.3-1.el7.centos.x86_64.rpm",
|
||||
|
|
@ -189,7 +190,7 @@ var dockerVersions = []dockerVersion{
|
|||
{
|
||||
DockerVersion: "1.12.3",
|
||||
Name: "docker-engine-selinux",
|
||||
Distros: []Distribution{DistributionRhel7, DistributionCentos7},
|
||||
Distros: []distros.Distribution{distros.DistributionRhel7, distros.DistributionCentos7},
|
||||
Architectures: []Architecture{ArchitectureAmd64},
|
||||
Version: "1.12.3",
|
||||
Source: "https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-selinux-1.12.3-1.el7.centos.noarch.rpm",
|
||||
|
|
@ -197,7 +198,7 @@ var dockerVersions = []dockerVersion{
|
|||
},
|
||||
}
|
||||
|
||||
func (d *dockerVersion) matches(arch Architecture, dockerVersion string, distro Distribution) bool {
|
||||
func (d *dockerVersion) matches(arch Architecture, dockerVersion string, distro distros.Distribution) bool {
|
||||
if d.DockerVersion != dockerVersion {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/nodeup/pkg/model"
|
||||
api "k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/apis/kops/registry"
|
||||
|
|
@ -173,7 +174,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
|||
// c.Config.Tags = append(c.Config.Tags, "_not_config_store")
|
||||
//}
|
||||
|
||||
distribution, err := FindDistribution(c.FSRoot)
|
||||
distribution, err := distros.FindDistribution(c.FSRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining OS distribution: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue