1
0
mirror of https://github.com/rancher/os.git synced 2025-06-26 15:01:34 +00:00

Fix golint errors

This commit is contained in:
Josh Curl 2016-11-28 00:06:00 -08:00
parent fa1dc760f2
commit a7c34b9855
No known key found for this signature in database
GPG Key ID: 82B504B9BCCFA677
35 changed files with 205 additions and 212 deletions

View File

@ -31,15 +31,15 @@ const (
userdataPath = apiVersion + "instance/attributes/user-data" userdataPath = apiVersion + "instance/attributes/user-data"
) )
type metadataService struct { type MetadataService struct {
metadata.MetadataService metadata.MetadataService
} }
func NewDatasource(root string) *metadataService { func NewDatasource(root string) *MetadataService {
return &metadataService{metadata.NewDatasource(root, apiVersion, userdataPath, metadataPath, http.Header{"Metadata-Flavor": {"Google"}})} return &MetadataService{metadata.NewDatasource(root, apiVersion, userdataPath, metadataPath, http.Header{"Metadata-Flavor": {"Google"}})}
} }
func (ms metadataService) FetchMetadata() (datasource.Metadata, error) { func (ms MetadataService) FetchMetadata() (datasource.Metadata, error) {
public, err := ms.fetchIP("instance/network-interfaces/0/access-configs/0/external-ip") public, err := ms.fetchIP("instance/network-interfaces/0/access-configs/0/external-ip")
if err != nil { if err != nil {
return datasource.Metadata{}, err return datasource.Metadata{}, err
@ -53,16 +53,16 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {
return datasource.Metadata{}, err return datasource.Metadata{}, err
} }
projectSshKeys, err := ms.fetchString("project/attributes/sshKeys") projectSSHKeys, err := ms.fetchString("project/attributes/sshKeys")
if err != nil { if err != nil {
return datasource.Metadata{}, err return datasource.Metadata{}, err
} }
instanceSshKeys, err := ms.fetchString("instance/attributes/sshKeys") instanceSSHKeys, err := ms.fetchString("instance/attributes/sshKeys")
if err != nil { if err != nil {
return datasource.Metadata{}, err return datasource.Metadata{}, err
} }
keyStrings := strings.Split(projectSshKeys+"\n"+instanceSshKeys, "\n") keyStrings := strings.Split(projectSSHKeys+"\n"+instanceSSHKeys, "\n")
sshPublicKeys := map[string]string{} sshPublicKeys := map[string]string{}
i := 0 i := 0
@ -85,11 +85,11 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {
}, nil }, nil
} }
func (ms metadataService) Type() string { func (ms MetadataService) Type() string {
return "gce-metadata-service" return "gce-metadata-service"
} }
func (ms metadataService) fetchString(key string) (string, error) { func (ms MetadataService) fetchString(key string) (string, error) {
data, err := ms.FetchData(ms.MetadataUrl() + key) data, err := ms.FetchData(ms.MetadataUrl() + key)
if err != nil { if err != nil {
return "", err return "", err
@ -98,7 +98,7 @@ func (ms metadataService) fetchString(key string) (string, error) {
return string(data), nil return string(data), nil
} }
func (ms metadataService) fetchIP(key string) (net.IP, error) { func (ms MetadataService) fetchIP(key string) (net.IP, error) {
str, err := ms.fetchString(key) str, err := ms.fetchString(key)
if err != nil { if err != nil {
return nil, err return nil, err
@ -110,12 +110,11 @@ func (ms metadataService) fetchIP(key string) (net.IP, error) {
if ip := net.ParseIP(str); ip != nil { if ip := net.ParseIP(str); ip != nil {
return ip, nil return ip, nil
} else { }
return nil, fmt.Errorf("couldn't parse %q as IP address", str) return nil, fmt.Errorf("couldn't parse %q as IP address", str)
} }
}
func (ms metadataService) FetchUserdata() ([]byte, error) { func (ms MetadataService) FetchUserdata() ([]byte, error) {
data, err := ms.FetchData(ms.UserdataUrl()) data, err := ms.FetchData(ms.UserdataUrl())
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -14,7 +14,7 @@ func Main() {
app.Name = os.Args[0] app.Name = os.Args[0]
app.Usage = "Control and configure RancherOS" app.Usage = "Control and configure RancherOS"
app.Version = config.VERSION app.Version = config.Version
app.Author = "Rancher Labs, Inc." app.Author = "Rancher Labs, Inc."
app.EnableBashCompletion = true app.EnableBashCompletion = true
app.Before = func(c *cli.Context) error { app.Before = func(c *cli.Context) error {

View File

@ -104,7 +104,7 @@ func imagesFromConfig(cfg *config.CloudConfig) []string {
i := 0 i := 0
for image := range imagesMap { for image := range imagesMap {
images[i] = image images[i] = image
i += 1 i++
} }
sort.Strings(images) sort.Strings(images)
return images return images

View File

@ -79,9 +79,9 @@ func consoleSwitch(c *cli.Context) error {
Privileged: true, Privileged: true,
Net: "host", Net: "host",
Pid: "host", Pid: "host",
Image: config.OS_BASE, Image: config.OsBase,
Labels: map[string]string{ Labels: map[string]string{
config.SCOPE: config.SYSTEM, config.ScopeLabel: config.System,
}, },
Command: []string{"/usr/bin/ros", "switch-console", newConsole}, Command: []string{"/usr/bin/ros", "switch-console", newConsole},
VolumesFrom: []string{"all-volumes"}, VolumesFrom: []string{"all-volumes"},

View File

@ -219,8 +219,8 @@ func setupSSH(cfg *config.CloudConfig) error {
continue continue
} }
saved, savedExists := cfg.Rancher.Ssh.Keys[keyType] saved, savedExists := cfg.Rancher.SSH.Keys[keyType]
pub, pubExists := cfg.Rancher.Ssh.Keys[keyType+"-pub"] pub, pubExists := cfg.Rancher.SSH.Keys[keyType+"-pub"]
if savedExists && pubExists { if savedExists && pubExists {
// TODO check permissions // TODO check permissions

View File

@ -60,7 +60,7 @@ func entrypointAction(c *cli.Context) error {
} }
func writeFiles(cfg *config.CloudConfig) error { func writeFiles(cfg *config.CloudConfig) error {
id, err := util.GetCurrentContainerId() id, err := util.GetCurrentContainerID()
if err != nil { if err != nil {
return err return err
} }
@ -92,10 +92,10 @@ func setupPowerOperations() {
} }
for _, link := range []symlink{ for _, link := range []symlink{
{config.ROS_BIN, "/sbin/poweroff"}, {config.RosBin, "/sbin/poweroff"},
{config.ROS_BIN, "/sbin/reboot"}, {config.RosBin, "/sbin/reboot"},
{config.ROS_BIN, "/sbin/halt"}, {config.RosBin, "/sbin/halt"},
{config.ROS_BIN, "/sbin/shutdown"}, {config.RosBin, "/sbin/shutdown"},
} { } {
if err := os.Symlink(link.oldname, link.newname); err != nil { if err := os.Symlink(link.oldname, link.newname); err != nil {
log.Error(err) log.Error(err)

View File

@ -66,7 +66,7 @@ func installAction(c *cli.Context) error {
image := c.String("image") image := c.String("image")
cfg := config.LoadConfig() cfg := config.LoadConfig()
if image == "" { if image == "" {
image = cfg.Rancher.Upgrade.Image + ":" + config.VERSION + config.SUFFIX image = cfg.Rancher.Upgrade.Image + ":" + config.Version + config.Suffix
} }
installType := c.String("install-type") installType := c.String("install-type")

View File

@ -80,30 +80,30 @@ func osSubcommands() []cli.Command {
// TODO: this and the getLatestImage should probably move to utils/network and be suitably cached. // TODO: this and the getLatestImage should probably move to utils/network and be suitably cached.
func getImages() (*Images, error) { func getImages() (*Images, error) {
upgradeUrl, err := getUpgradeUrl() upgradeURL, err := getUpgradeURL()
if err != nil { if err != nil {
return nil, err return nil, err
} }
var body []byte var body []byte
if strings.HasPrefix(upgradeUrl, "/") { if strings.HasPrefix(upgradeURL, "/") {
body, err = ioutil.ReadFile(upgradeUrl) body, err = ioutil.ReadFile(upgradeURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else { } else {
u, err := url.Parse(upgradeUrl) u, err := url.Parse(upgradeURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
q := u.Query() q := u.Query()
q.Set("current", config.VERSION) q.Set("current", config.Version)
u.RawQuery = q.Encode() u.RawQuery = q.Encode()
upgradeUrl = u.String() upgradeURL = u.String()
resp, err := http.Get(upgradeUrl) resp, err := http.Get(upgradeURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -129,7 +129,7 @@ func osMetaDataGet(c *cli.Context) error {
} }
cfg := config.LoadConfig() cfg := config.LoadConfig()
runningName := cfg.Rancher.Upgrade.Image + ":" + config.VERSION runningName := cfg.Rancher.Upgrade.Image + ":" + config.Version
foundRunning := false foundRunning := false
for i := len(images.Available) - 1; i >= 0; i-- { for i := len(images.Available) - 1; i >= 0; i-- {
@ -151,7 +151,7 @@ func osMetaDataGet(c *cli.Context) error {
fmt.Println(image, local, available, running) fmt.Println(image, local, available, running)
} }
if !foundRunning { if !foundRunning {
fmt.Println(config.VERSION, "running") fmt.Println(config.Version, "running")
} }
return nil return nil
@ -190,14 +190,14 @@ func osUpgrade(c *cli.Context) error {
} }
func osVersion(c *cli.Context) error { func osVersion(c *cli.Context) error {
fmt.Println(config.VERSION) fmt.Println(config.Version)
return nil return nil
} }
func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgradeConsole bool, kernelArgs string) error { func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgradeConsole bool, kernelArgs string) error {
command := []string{ command := []string{
"-t", "rancher-upgrade", "-t", "rancher-upgrade",
"-r", config.VERSION, "-r", config.Version,
} }
if kexec { if kexec {
@ -218,7 +218,7 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra
fmt.Printf("Upgrading to %s\n", image) fmt.Printf("Upgrading to %s\n", image)
confirmation := "Continue" confirmation := "Continue"
imageSplit := strings.Split(image, ":") imageSplit := strings.Split(image, ":")
if len(imageSplit) > 1 && imageSplit[1] == config.VERSION+config.SUFFIX { if len(imageSplit) > 1 && imageSplit[1] == config.Version+config.Suffix {
confirmation = fmt.Sprintf("Already at version %s. Continue anyway", imageSplit[1]) confirmation = fmt.Sprintf("Already at version %s. Continue anyway", imageSplit[1])
} }
if !force && !yes(confirmation) { if !force && !yes(confirmation) {
@ -232,7 +232,7 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra
Pid: "host", Pid: "host",
Image: image, Image: image,
Labels: map[string]string{ Labels: map[string]string{
config.SCOPE: config.SYSTEM, config.ScopeLabel: config.System,
}, },
Command: command, Command: command,
}) })
@ -290,7 +290,7 @@ func parseBody(body []byte) (*Images, error) {
return update, nil return update, nil
} }
func getUpgradeUrl() (string, error) { func getUpgradeURL() (string, error) {
cfg := config.LoadConfig() cfg := config.LoadConfig()
return cfg.Rancher.Upgrade.Url, nil return cfg.Rancher.Upgrade.URL, nil
} }

View File

@ -50,7 +50,7 @@ func selinuxCommand() cli.Command {
"-v", "/etc/selinux:/etc/selinux", "-v", "/etc/selinux:/etc/selinux",
"-v", "/var/lib/selinux:/var/lib/selinux", "-v", "/var/lib/selinux:/var/lib/selinux",
"-v", "/usr/share/selinux:/usr/share/selinux", "-v", "/usr/share/selinux:/usr/share/selinux",
fmt.Sprintf("%s/os-selinuxtools:%s%s", config.OS_REPO, config.VERSION, config.SUFFIX), "bash"} fmt.Sprintf("%s/os-selinuxtools:%s%s", config.OsRepo, config.Version, config.Suffix), "bash"}
syscall.Exec("/bin/system-docker", argv, []string{}) syscall.Exec("/bin/system-docker", argv, []string{})
return nil return nil
} }

View File

@ -16,8 +16,8 @@ import (
const ( const (
NAME string = "rancher" NAME string = "rancher"
BITS int = 2048 BITS int = 2048
ServerTlsPath string = "/etc/docker/tls" ServerTLSPath string = "/etc/docker/tls"
ClientTlsPath string = "/home/rancher/.docker" ClientTLSPath string = "/home/rancher/.docker"
Cert string = "cert.pem" Cert string = "cert.pem"
Key string = "key.pem" Key string = "key.pem"
ServerCert string = "server-cert.pem" ServerCert string = "server-cert.pem"
@ -141,9 +141,9 @@ func generate(c *cli.Context) error {
func Generate(generateServer bool, outDir string, hostnames []string) error { func Generate(generateServer bool, outDir string, hostnames []string) error {
if outDir == "" { if outDir == "" {
if generateServer { if generateServer {
outDir = ServerTlsPath outDir = ServerTLSPath
} else { } else {
outDir = ClientTlsPath outDir = ClientTLSPath
} }
log.Infof("Out directory (-d, --dir) not specified, using default: %s", outDir) log.Infof("Out directory (-d, --dir) not specified, using default: %s", outDir)
} }

View File

@ -23,15 +23,15 @@ import (
) )
const ( const (
DEFAULT_STORAGE_CONTEXT = "console" defaultStorageContext = "console"
DOCKER_PID_FILE = "/var/run/docker.pid" dockerPidFile = "/var/run/docker.pid"
userDocker = "user-docker" userDocker = "user-docker"
sourceDirectory = "/engine" sourceDirectory = "/engine"
destDirectory = "/var/lib/rancher/engine" destDirectory = "/var/lib/rancher/engine"
) )
var ( var (
DOCKER_COMMAND = []string{ dockerCommand = []string{
"ros", "ros",
"docker-init", "docker-init",
} }
@ -105,7 +105,7 @@ func copyBinaries(source, dest string) error {
} }
func writeConfigCerts(cfg *config.CloudConfig) error { func writeConfigCerts(cfg *config.CloudConfig) error {
outDir := ServerTlsPath outDir := ServerTLSPath
if err := os.MkdirAll(outDir, 0700); err != nil { if err := os.MkdirAll(outDir, 0700); err != nil {
return err return err
} }
@ -137,7 +137,7 @@ func writeConfigCerts(cfg *config.CloudConfig) error {
func startDocker(cfg *config.CloudConfig) error { func startDocker(cfg *config.CloudConfig) error {
storageContext := cfg.Rancher.Docker.StorageContext storageContext := cfg.Rancher.Docker.StorageContext
if storageContext == "" { if storageContext == "" {
storageContext = DEFAULT_STORAGE_CONTEXT storageContext = defaultStorageContext
} }
log.Infof("Starting Docker in context: %s", storageContext) log.Infof("Starting Docker in context: %s", storageContext)
@ -179,7 +179,7 @@ func startDocker(cfg *config.CloudConfig) error {
cmd := []string{"docker-runc", "exec", "--", info.ID, "env"} cmd := []string{"docker-runc", "exec", "--", info.ID, "env"}
log.Info(dockerCfg.AppendEnv()) log.Info(dockerCfg.AppendEnv())
cmd = append(cmd, dockerCfg.AppendEnv()...) cmd = append(cmd, dockerCfg.AppendEnv()...)
cmd = append(cmd, DOCKER_COMMAND...) cmd = append(cmd, dockerCommand...)
cmd = append(cmd, args...) cmd = append(cmd, args...)
log.Infof("Running %v", cmd) log.Infof("Running %v", cmd)
@ -214,7 +214,7 @@ func getPid(service string, project *project.Project) (int, error) {
} }
client, err := composeClient.Create(composeClient.Options{ client, err := composeClient.Create(composeClient.Options{
Host: config.DOCKER_SYSTEM_HOST, Host: config.SystemDockerHost,
}) })
if err != nil { if err != nil {
return 0, err return 0, err

View File

@ -19,12 +19,12 @@ func Main() {
} }
func ApplyNetworkConfig(cfg *config.CloudConfig) { func ApplyNetworkConfig(cfg *config.CloudConfig) {
nameservers := cfg.Rancher.Network.Dns.Nameservers nameservers := cfg.Rancher.Network.DNS.Nameservers
search := cfg.Rancher.Network.Dns.Search search := cfg.Rancher.Network.DNS.Search
userSetDns := len(nameservers) > 0 || len(search) > 0 userSetDNS := len(nameservers) > 0 || len(search) > 0
if !userSetDns { if !userSetDNS {
nameservers = cfg.Rancher.Defaults.Network.Dns.Nameservers nameservers = cfg.Rancher.Defaults.Network.DNS.Nameservers
search = cfg.Rancher.Defaults.Network.Dns.Search search = cfg.Rancher.Defaults.Network.DNS.Search
} }
if _, err := resolvconf.Build("/etc/resolv.conf", nameservers, search, nil); err != nil { if _, err := resolvconf.Build("/etc/resolv.conf", nameservers, search, nil); err != nil {
@ -40,7 +40,7 @@ func ApplyNetworkConfig(cfg *config.CloudConfig) {
} }
userSetHostname := cfg.Hostname != "" userSetHostname := cfg.Hostname != ""
if err := netconf.RunDhcp(&cfg.Rancher.Network, !userSetHostname, !userSetDns); err != nil { if err := netconf.RunDhcp(&cfg.Rancher.Network, !userSetHostname, !userSetDNS); err != nil {
log.Error(err) log.Error(err)
} }

View File

@ -47,12 +47,12 @@ func runDocker(name string) error {
} }
} }
currentContainerId, err := util.GetCurrentContainerId() currentContainerID, err := util.GetCurrentContainerID()
if err != nil { if err != nil {
return err return err
} }
currentContainer, err := client.ContainerInspect(context.Background(), currentContainerId) currentContainer, err := client.ContainerInspect(context.Background(), currentContainerID)
if err != nil { if err != nil {
return err return err
} }
@ -110,7 +110,7 @@ func common(name string) {
} }
} }
func PowerOff() { func Off() {
common("poweroff") common("poweroff")
reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF) reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
} }
@ -181,7 +181,7 @@ func shutDownContainers() error {
return err return err
} }
currentContainerId, err := util.GetCurrentContainerId() currentContainerID, err := util.GetCurrentContainerID()
if err != nil { if err != nil {
return err return err
} }
@ -189,7 +189,7 @@ func shutDownContainers() error {
var stopErrorStrings []string var stopErrorStrings []string
for _, container := range containers { for _, container := range containers {
if container.ID == currentContainerId { if container.ID == currentContainerID {
continue continue
} }
@ -203,7 +203,7 @@ func shutDownContainers() error {
var waitErrorStrings []string var waitErrorStrings []string
for _, container := range containers { for _, container := range containers {
if container.ID == currentContainerId { if container.ID == currentContainerID {
continue continue
} }
_, waitErr := client.ContainerWait(context.Background(), container.ID) _, waitErr := client.ContainerWait(context.Background(), container.ID)

View File

@ -12,7 +12,7 @@ func Main() {
app.Name = os.Args[0] app.Name = os.Args[0]
app.Usage = "Control and configure RancherOS" app.Usage = "Control and configure RancherOS"
app.Version = config.VERSION app.Version = config.Version
app.Author = "Rancher Labs, Inc." app.Author = "Rancher Labs, Inc."
app.Email = "sid@rancher.com" app.Email = "sid@rancher.com"
app.EnableBashCompletion = true app.EnableBashCompletion = true
@ -39,7 +39,7 @@ func shutdown(c *cli.Context) error {
if reboot == "now" { if reboot == "now" {
Reboot() Reboot()
} else if poweroff == "now" { } else if poweroff == "now" {
PowerOff() Off()
} }
return nil return nil

View File

@ -17,8 +17,8 @@ import (
) )
var ( var (
running bool = true running = true
processes map[int]*os.Process = map[int]*os.Process{} processes = map[int]*os.Process{}
processLock = sync.Mutex{} processLock = sync.Mutex{}
) )

View File

@ -14,7 +14,7 @@ func Main() {
} }
if os.Getenv("DOCKER_HOST") == "" { if os.Getenv("DOCKER_HOST") == "" {
os.Setenv("DOCKER_HOST", config.DOCKER_SYSTEM_HOST) os.Setenv("DOCKER_HOST", config.SystemDockerHost)
} }
docker.Main() docker.Main()

View File

@ -9,7 +9,7 @@ import (
) )
func Main() { func Main() {
_, err := docker.NewClient(config.DOCKER_HOST) _, err := docker.NewClient(config.DockerHost)
if err != nil { if err != nil {
logrus.Errorf("Failed to connect to Docker") logrus.Errorf("Failed to connect to Docker")
os.Exit(1) os.Exit(1)

View File

@ -12,30 +12,29 @@ import (
const ( const (
OEM = "/usr/share/ros/oem" OEM = "/usr/share/ros/oem"
DOCKER_BIN = "/usr/bin/docker" DockerBin = "/usr/bin/docker"
DOCKER_DIST_BIN = "/usr/bin/docker.dist" DockerDistBin = "/usr/bin/docker.dist"
ROS_BIN = "/usr/bin/ros" RosBin = "/usr/bin/ros"
SYSINIT_BIN = "/usr/bin/ros-sysinit" SysInitBin = "/usr/bin/ros-sysinit"
DOCKER_SYSTEM_HOME = "/var/lib/system-docker" SystemDockerHome = "/var/lib/system-docker"
DOCKER_SYSTEM_HOST = "unix:///var/run/system-docker.sock" SystemDockerHost = "unix:///var/run/system-docker.sock"
DOCKER_HOST = "unix:///var/run/docker.sock" DockerHost = "unix:///var/run/docker.sock"
IMAGES_PATH = "/usr/share/ros" ImagesPath = "/usr/share/ros"
IMAGES_PATTERN = "images*.tar" ImagesPattern = "images*.tar"
MODULES_ARCHIVE = "/modules.tar" ModulesArchive = "/modules.tar"
DEBUG = false Debug = false
SYSTEM_DOCKER_LOG = "/var/log/system-docker.log" SystemDockerLog = "/var/log/system-docker.log"
SYSTEM_DOCKER_BIN = "/usr/bin/system-docker" SystemDockerBin = "/usr/bin/system-docker"
LABEL = "label" HashLabel = "io.rancher.os.hash"
HASH = "io.rancher.os.hash" IDLabel = "io.rancher.os.id"
ID = "io.rancher.os.id" DetachLabel = "io.rancher.os.detach"
DETACH = "io.rancher.os.detach" CreateOnlyLabel = "io.rancher.os.createonly"
CREATE_ONLY = "io.rancher.os.createonly" ReloadConfigLabel = "io.rancher.os.reloadconfig"
RELOAD_CONFIG = "io.rancher.os.reloadconfig" ConsoleLabel = "io.rancher.os.console"
CONSOLE = "io.rancher.os.console" ScopeLabel = "io.rancher.os.scope"
SCOPE = "io.rancher.os.scope" RebuildLabel = "io.docker.compose.rebuild"
REBUILD = "io.docker.compose.rebuild" System = "system"
SYSTEM = "system"
OsConfigFile = "/usr/share/ros/os-config.yml" OsConfigFile = "/usr/share/ros/os-config.yml"
CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d" CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
@ -48,11 +47,11 @@ const (
var ( var (
OemConfigFile = OEM + "/oem-config.yml" OemConfigFile = OEM + "/oem-config.yml"
VERSION string Version string
ARCH string Arch string
SUFFIX string Suffix string
OS_REPO string OsRepo string
OS_BASE string OsBase string
PrivateKeys = []string{ PrivateKeys = []string{
"rancher.ssh", "rancher.ssh",
"rancher.docker.ca_key", "rancher.docker.ca_key",
@ -63,22 +62,22 @@ var (
) )
func init() { func init() {
if VERSION == "" { if Version == "" {
VERSION = "v0.0.0-dev" Version = "v0.0.0-dev"
} }
if ARCH == "" { if Arch == "" {
ARCH = runtime.GOARCH Arch = runtime.GOARCH
} }
if SUFFIX == "" && ARCH != "amd64" { if Suffix == "" && Arch != "amd64" {
SUFFIX = "_" + ARCH Suffix = "_" + Arch
} }
if OS_BASE == "" { if OsBase == "" {
OS_BASE = fmt.Sprintf("%s/os-base:%s%s", OS_REPO, VERSION, SUFFIX) OsBase = fmt.Sprintf("%s/os-base:%s%s", OsRepo, Version, Suffix)
} }
} }
type Repository struct { type Repository struct {
Url string `yaml:"url,omitempty"` URL string `yaml:"url,omitempty"`
} }
type Repositories map[string]Repository type Repositories map[string]Repository
@ -117,7 +116,7 @@ type RancherConfig struct {
Network NetworkConfig `yaml:"network,omitempty"` Network NetworkConfig `yaml:"network,omitempty"`
DefaultNetwork NetworkConfig `yaml:"default_network,omitempty"` DefaultNetwork NetworkConfig `yaml:"default_network,omitempty"`
Repositories Repositories `yaml:"repositories,omitempty"` Repositories Repositories `yaml:"repositories,omitempty"`
Ssh SshConfig `yaml:"ssh,omitempty"` SSH SSHConfig `yaml:"ssh,omitempty"`
State StateConfig `yaml:"state,omitempty"` State StateConfig `yaml:"state,omitempty"`
SystemDocker DockerConfig `yaml:"system_docker,omitempty"` SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
Upgrade UpgradeConfig `yaml:"upgrade,omitempty"` Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
@ -130,7 +129,7 @@ type RancherConfig struct {
} }
type UpgradeConfig struct { type UpgradeConfig struct {
Url string `yaml:"url,omitempty"` URL string `yaml:"url,omitempty"`
Image string `yaml:"image,omitempty"` Image string `yaml:"image,omitempty"`
Rollback string `yaml:"rollback,omitempty"` Rollback string `yaml:"rollback,omitempty"`
} }
@ -173,11 +172,11 @@ type DockerConfig struct {
type NetworkConfig struct { type NetworkConfig struct {
PreCmds []string `yaml:"pre_cmds,omitempty"` PreCmds []string `yaml:"pre_cmds,omitempty"`
Dns DnsConfig `yaml:"dns,omitempty"` DNS DNSConfig `yaml:"dns,omitempty"`
Interfaces map[string]InterfaceConfig `yaml:"interfaces,omitempty"` Interfaces map[string]InterfaceConfig `yaml:"interfaces,omitempty"`
PostCmds []string `yaml:"post_cmds,omitempty"` PostCmds []string `yaml:"post_cmds,omitempty"`
HttpProxy string `yaml:"http_proxy,omitempty"` HTTPProxy string `yaml:"http_proxy,omitempty"`
HttpsProxy string `yaml:"https_proxy,omitempty"` HTTPSProxy string `yaml:"https_proxy,omitempty"`
NoProxy string `yaml:"no_proxy,omitempty"` NoProxy string `yaml:"no_proxy,omitempty"`
} }
@ -199,12 +198,12 @@ type InterfaceConfig struct {
Vlans string `yaml:"vlans,omitempty"` Vlans string `yaml:"vlans,omitempty"`
} }
type DnsConfig struct { type DNSConfig struct {
Nameservers []string `yaml:"nameservers,flow,omitempty"` Nameservers []string `yaml:"nameservers,flow,omitempty"`
Search []string `yaml:"search,flow,omitempty"` Search []string `yaml:"search,flow,omitempty"`
} }
type SshConfig struct { type SSHConfig struct {
Keys map[string]string `yaml:"keys,omitempty"` Keys map[string]string `yaml:"keys,omitempty"`
} }
@ -234,8 +233,8 @@ type Defaults struct {
func (r Repositories) ToArray() []string { func (r Repositories) ToArray() []string {
result := make([]string, 0, len(r)) result := make([]string, 0, len(r))
for _, repo := range r { for _, repo := range r {
if repo.Url != "" { if repo.URL != "" {
result = append(result, repo.Url) result = append(result, repo.URL)
} }
} }

View File

@ -46,7 +46,7 @@ type Config struct {
Fork bool Fork bool
PidOne bool PidOne bool
CommandName string CommandName string
DnsConfig config.DnsConfig DNSConfig config.DNSConfig
BridgeName string BridgeName string
BridgeAddress string BridgeAddress string
BridgeMtu int BridgeMtu int
@ -209,10 +209,9 @@ func execDocker(config *Config, docker, cmd string, args []string) (*exec.Cmd, e
PidOne() PidOne()
} }
return cmd, err return cmd, err
} else {
err := syscall.Exec(expand(docker), append([]string{cmd}, args...), env)
return nil, err
} }
return nil, syscall.Exec(expand(docker), append([]string{cmd}, args...), env)
} }
func copyDefault(folder, name string) error { func copyDefault(folder, name string) error {
@ -352,8 +351,8 @@ ff02::2 ip6-allrouters
127.0.1.1 `+hostname) 127.0.1.1 `+hostname)
if len(cfg.DnsConfig.Nameservers) != 0 { if len(cfg.DNSConfig.Nameservers) != 0 {
if _, err := resolvconf.Build("/etc/resolv.conf", cfg.DnsConfig.Nameservers, cfg.DnsConfig.Search, nil); err != nil { if _, err := resolvconf.Build("/etc/resolv.conf", cfg.DNSConfig.Nameservers, cfg.DNSConfig.Search, nil); err != nil {
return err return err
} }
} }
@ -382,13 +381,11 @@ func GetValue(index int, args []string) string {
if len(parts) == 1 { if len(parts) == 1 {
if len(args) > index+1 { if len(args) > index+1 {
return args[index+1] return args[index+1]
} else { }
return "" return ""
} }
} else {
return parts[1] return parts[1]
} }
}
func ParseConfig(config *Config, args ...string) []string { func ParseConfig(config *Config, args ...string) []string {
for i, arg := range args { for i, arg := range args {

View File

@ -7,11 +7,11 @@ import (
) )
func NewSystemClient() (dockerClient.APIClient, error) { func NewSystemClient() (dockerClient.APIClient, error) {
return NewClient(config.DOCKER_SYSTEM_HOST) return NewClient(config.SystemDockerHost)
} }
func NewDefaultClient() (dockerClient.APIClient, error) { func NewDefaultClient() (dockerClient.APIClient, error) {
return NewClient(config.DOCKER_HOST) return NewClient(config.DockerHost)
} }
func NewClient(endpoint string) (dockerClient.APIClient, error) { func NewClient(endpoint string) (dockerClient.APIClient, error) {

View File

@ -25,8 +25,8 @@ func NewClientFactory(opts composeClient.Options) (project.ClientFactory, error)
userOpts := opts userOpts := opts
systemOpts := opts systemOpts := opts
userOpts.Host = config.DOCKER_HOST userOpts.Host = config.DockerHost
systemOpts.Host = config.DOCKER_SYSTEM_HOST systemOpts.Host = config.SystemDockerHost
userClient, err := composeClient.Create(userOpts) userClient, err := composeClient.Create(userOpts)
if err != nil { if err != nil {
@ -46,11 +46,11 @@ func NewClientFactory(opts composeClient.Options) (project.ClientFactory, error)
func (c *ClientFactory) Create(service project.Service) dockerclient.APIClient { func (c *ClientFactory) Create(service project.Service) dockerclient.APIClient {
if IsSystemContainer(service.Config()) { if IsSystemContainer(service.Config()) {
waitFor(&c.systemOnce, c.systemClient, config.DOCKER_SYSTEM_HOST) waitFor(&c.systemOnce, c.systemClient, config.SystemDockerHost)
return c.systemClient return c.systemClient
} }
waitFor(&c.userOnce, c.userClient, config.DOCKER_HOST) waitFor(&c.userOnce, c.userClient, config.DockerHost)
return c.userClient return c.userClient
} }

View File

@ -29,13 +29,13 @@ func appendEnv(array []string, key, value string) []string {
func environmentFromCloudConfig(cfg *config.CloudConfig) map[string]string { func environmentFromCloudConfig(cfg *config.CloudConfig) map[string]string {
environment := cfg.Rancher.Environment environment := cfg.Rancher.Environment
if cfg.Rancher.Network.HttpProxy != "" { if cfg.Rancher.Network.HTTPProxy != "" {
environment["http_proxy"] = cfg.Rancher.Network.HttpProxy environment["http_proxy"] = cfg.Rancher.Network.HTTPProxy
environment["HTTP_PROXY"] = cfg.Rancher.Network.HttpProxy environment["HTTP_PROXY"] = cfg.Rancher.Network.HTTPProxy
} }
if cfg.Rancher.Network.HttpsProxy != "" { if cfg.Rancher.Network.HTTPSProxy != "" {
environment["https_proxy"] = cfg.Rancher.Network.HttpsProxy environment["https_proxy"] = cfg.Rancher.Network.HTTPSProxy
environment["HTTPS_PROXY"] = cfg.Rancher.Network.HttpsProxy environment["HTTPS_PROXY"] = cfg.Rancher.Network.HTTPSProxy
} }
if cfg.Rancher.Network.NoProxy != "" { if cfg.Rancher.Network.NoProxy != "" {
environment["no_proxy"] = cfg.Rancher.Network.NoProxy environment["no_proxy"] = cfg.Rancher.Network.NoProxy

View File

@ -63,7 +63,7 @@ func (s *Service) requiresSyslog() bool {
} }
func (s *Service) requiresUserDocker() bool { func (s *Service) requiresUserDocker() bool {
return s.Config().Labels[config.SCOPE] != config.SYSTEM return s.Config().Labels[config.ScopeLabel] != config.System
} }
func appendLink(deps []project.ServiceRelationship, name string, optional bool, p *project.Project) []project.ServiceRelationship { func appendLink(deps []project.ServiceRelationship, name string, optional bool, p *project.Project) []project.ServiceRelationship {
@ -93,8 +93,8 @@ func (s *Service) shouldRebuild(ctx context.Context) (bool, error) {
} }
name := containerInfo.Name[1:] name := containerInfo.Name[1:]
origRebuildLabel := containerInfo.Config.Labels[config.REBUILD] origRebuildLabel := containerInfo.Config.Labels[config.RebuildLabel]
newRebuildLabel := s.Config().Labels[config.REBUILD] newRebuildLabel := s.Config().Labels[config.RebuildLabel]
rebuildLabelChanged := newRebuildLabel != origRebuildLabel rebuildLabelChanged := newRebuildLabel != origRebuildLabel
logrus.WithFields(logrus.Fields{ logrus.WithFields(logrus.Fields{
"origRebuildLabel": origRebuildLabel, "origRebuildLabel": origRebuildLabel,
@ -113,8 +113,8 @@ func (s *Service) shouldRebuild(ctx context.Context) (bool, error) {
} }
if outOfSync { if outOfSync {
if s.Name() == "console" { if s.Name() == "console" {
origConsoleLabel := containerInfo.Config.Labels[config.CONSOLE] origConsoleLabel := containerInfo.Config.Labels[config.ConsoleLabel]
newConsoleLabel := s.Config().Labels[config.CONSOLE] newConsoleLabel := s.Config().Labels[config.ConsoleLabel]
if newConsoleLabel != origConsoleLabel { if newConsoleLabel != origConsoleLabel {
return true, nil return true, nil
} }
@ -154,13 +154,13 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
return err return err
} }
} }
if labels[config.CREATE_ONLY] == "true" { if labels[config.CreateOnlyLabel] == "true" {
return s.checkReload(labels) return s.checkReload(labels)
} }
if err := s.Service.Up(ctx, options); err != nil { if err := s.Service.Up(ctx, options); err != nil {
return err return err
} }
if labels[config.DETACH] == "false" { if labels[config.DetachLabel] == "false" {
if err := s.wait(ctx); err != nil { if err := s.wait(ctx); err != nil {
return err return err
} }
@ -170,7 +170,7 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
} }
func (s *Service) checkReload(labels map[string]string) error { func (s *Service) checkReload(labels map[string]string) error {
if labels[config.RELOAD_CONFIG] == "true" { if labels[config.ReloadConfigLabel] == "true" {
return project.ErrRestart return project.ErrRestart
} }
return nil return nil
@ -223,7 +223,6 @@ func (s *Service) rename(ctx context.Context) error {
if len(info.Name) > 0 && info.Name[1:] != s.Name() { if len(info.Name) > 0 && info.Name[1:] != s.Name() {
logrus.Debugf("Renaming container %s => %s", info.Name[1:], s.Name()) logrus.Debugf("Renaming container %s => %s", info.Name[1:], s.Name())
return client.ContainerRename(context.Background(), info.ID, s.Name()) return client.ContainerRename(context.Background(), info.ID, s.Name())
} else { }
return nil return nil
} }
}

View File

@ -6,6 +6,5 @@ import (
) )
func IsSystemContainer(serviceConfig *composeConfig.ServiceConfig) bool { func IsSystemContainer(serviceConfig *composeConfig.ServiceConfig) bool {
return serviceConfig.Labels[config.SCOPE] == config.SYSTEM return serviceConfig.Labels[config.ScopeLabel] == config.System
} }

View File

@ -31,7 +31,7 @@ func startDocker(cfg *config.CloudConfig) (chan interface{}, error) {
launchConfig.LogFile = "" launchConfig.LogFile = ""
launchConfig.NoLog = true launchConfig.NoLog = true
cmd, err := dfs.LaunchDocker(launchConfig, config.SYSTEM_DOCKER_BIN, args...) cmd, err := dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -21,11 +21,11 @@ import (
) )
const ( const (
STATE string = "/state" state string = "/state"
BOOT2DOCKER_MAGIC string = "boot2docker, please format-me" boot2DockerMagic string = "boot2docker, please format-me"
TMPFS_MAGIC int64 = 0x01021994 tmpfsMagic int64 = 0x01021994
RAMFS_MAGIC int64 = 0x858458f6 ramfsMagic int64 = 0x858458f6
) )
var ( var (
@ -68,10 +68,10 @@ func loadModules(cfg *config.CloudConfig) (*config.CloudConfig, error) {
} }
func sysInit(c *config.CloudConfig) (*config.CloudConfig, error) { func sysInit(c *config.CloudConfig) (*config.CloudConfig, error) {
args := append([]string{config.SYSINIT_BIN}, os.Args[1:]...) args := append([]string{config.SysInitBin}, os.Args[1:]...)
cmd := &exec.Cmd{ cmd := &exec.Cmd{
Path: config.ROS_BIN, Path: config.RosBin,
Args: args, Args: args,
} }
@ -117,7 +117,7 @@ func mountConfigured(display, dev, fsType, target string) error {
} }
func mountState(cfg *config.CloudConfig) error { func mountState(cfg *config.CloudConfig) error {
return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, STATE) return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, state)
} }
func mountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) { func mountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) {
@ -164,12 +164,12 @@ func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*
args := dfs.ParseConfig(&launchConfig, dockerCfg.FullArgs()...) args := dfs.ParseConfig(&launchConfig, dockerCfg.FullArgs()...)
launchConfig.DnsConfig.Nameservers = cfg.Rancher.Defaults.Network.Dns.Nameservers launchConfig.DNSConfig.Nameservers = cfg.Rancher.Defaults.Network.DNS.Nameservers
launchConfig.DnsConfig.Search = cfg.Rancher.Defaults.Network.Dns.Search launchConfig.DNSConfig.Search = cfg.Rancher.Defaults.Network.DNS.Search
launchConfig.Environment = dockerCfg.Environment launchConfig.Environment = dockerCfg.Environment
if !cfg.Rancher.Debug { if !cfg.Rancher.Debug {
launchConfig.LogFile = config.SYSTEM_DOCKER_LOG launchConfig.LogFile = config.SystemDockerLog
} }
return &launchConfig, args return &launchConfig, args
@ -178,7 +178,7 @@ func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*
func isInitrd() bool { func isInitrd() bool {
var stat syscall.Statfs_t var stat syscall.Statfs_t
syscall.Statfs("/", &stat) syscall.Statfs("/", &stat)
return int64(stat.Type) == TMPFS_MAGIC || int64(stat.Type) == RAMFS_MAGIC return int64(stat.Type) == tmpfsMagic || int64(stat.Type) == ramfsMagic
} }
func setupSharedRoot(c *config.CloudConfig) (*config.CloudConfig, error) { func setupSharedRoot(c *config.CloudConfig) (*config.CloudConfig, error) {
@ -246,7 +246,7 @@ func RunInit() error {
} }
devices := []string{"/dev/sda", "/dev/vda"} devices := []string{"/dev/sda", "/dev/vda"}
data := make([]byte, len(BOOT2DOCKER_MAGIC)) data := make([]byte, len(boot2DockerMagic))
for _, device := range devices { for _, device := range devices {
f, err := os.Open(device) f, err := os.Open(device)
@ -254,7 +254,7 @@ func RunInit() error {
defer f.Close() defer f.Close()
_, err = f.Read(data) _, err = f.Read(data)
if err == nil && string(data) == BOOT2DOCKER_MAGIC { if err == nil && string(data) == boot2DockerMagic {
boot2DockerEnvironment = true boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE" cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
cfg.Rancher.State.Autoformat = []string{device} cfg.Rancher.State.Autoformat = []string{device}
@ -278,7 +278,7 @@ func RunInit() error {
log.Error(err) log.Error(err)
} }
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(STATE).Rancher.CloudInit.Datasources cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil { if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil {
log.Error(err) log.Error(err)
} }
@ -324,8 +324,8 @@ func RunInit() error {
if !shouldSwitchRoot { if !shouldSwitchRoot {
return cfg, nil return cfg, nil
} }
log.Debugf("Switching to new root at %s %s", STATE, cfg.Rancher.State.Directory) log.Debugf("Switching to new root at %s %s", state, cfg.Rancher.State.Directory)
if err := switchRoot(STATE, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil { if err := switchRoot(state, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil {
return cfg, err return cfg, err
} }
return cfg, nil return cfg, nil
@ -377,7 +377,7 @@ func RunInit() error {
launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec
log.Info("Launching System Docker") log.Info("Launching System Docker")
_, err = dfs.LaunchDocker(launchConfig, config.SYSTEM_DOCKER_BIN, args...) _, err = dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil { if err != nil {
return err return err
} }

View File

@ -39,7 +39,7 @@ func cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir string) (bool, error)
} }
func copyMoveRoot(rootfs string, rmUsr bool) error { func copyMoveRoot(rootfs string, rmUsr bool) error {
usrVer := fmt.Sprintf("usr-%s", config.VERSION) usrVer := fmt.Sprintf("usr-%s", config.Version)
usr := path.Join(rootfs, usrVer) usr := path.Join(rootfs, usrVer)
targetUsr := path.Join(rootfs, "usr") targetUsr := path.Join(rootfs, "usr")
tmpDir := path.Join(rootfs, "tmp") tmpDir := path.Join(rootfs, "tmp")

View File

@ -20,7 +20,7 @@ const (
) )
func hasImage(name string) bool { func hasImage(name string) bool {
stamp := path.Join(STATE, name) stamp := path.Join(state, name)
if _, err := os.Stat(stamp); os.IsNotExist(err) { if _, err := os.Stat(stamp); os.IsNotExist(err) {
return false return false
} }
@ -28,13 +28,13 @@ func hasImage(name string) bool {
} }
func findImages(cfg *config.CloudConfig) ([]string, error) { func findImages(cfg *config.CloudConfig) ([]string, error) {
log.Debugf("Looking for images at %s", config.IMAGES_PATH) log.Debugf("Looking for images at %s", config.ImagesPath)
result := []string{} result := []string{}
dir, err := os.Open(config.IMAGES_PATH) dir, err := os.Open(config.ImagesPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Debugf("Not loading images, %s does not exist", config.IMAGES_PATH) log.Debugf("Not loading images, %s does not exist", config.ImagesPath)
return result, nil return result, nil
} }
if err != nil { if err != nil {
@ -49,7 +49,7 @@ func findImages(cfg *config.CloudConfig) ([]string, error) {
} }
for _, fileName := range files { for _, fileName := range files {
if ok, _ := path.Match(config.IMAGES_PATTERN, fileName); ok { if ok, _ := path.Match(config.ImagesPattern, fileName); ok {
log.Debugf("Found %s", fileName) log.Debugf("Found %s", fileName)
result = append(result, fileName) result = append(result, fileName)
} }
@ -74,7 +74,7 @@ func loadImages(cfg *config.CloudConfig) (*config.CloudConfig, error) {
continue continue
} }
inputFileName := path.Join(config.IMAGES_PATH, image) inputFileName := path.Join(config.ImagesPath, image)
input, err := os.Open(inputFileName) input, err := os.Open(inputFileName)
if err != nil { if err != nil {
return cfg, err return cfg, err
@ -119,7 +119,7 @@ func SysInit() error {
return cfg, nil return cfg, nil
}, },
func(cfg *config.CloudConfig) (*config.CloudConfig, error) { func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
log.Infof("RancherOS %s started", config.VERSION) log.Infof("RancherOS %s started", config.Version)
return cfg, nil return cfg, nil
}) })
return err return err

View File

@ -27,7 +27,7 @@ var entrypoints = map[string]func(){
"halt": power.Halt, "halt": power.Halt,
"init": osInit.MainInit, "init": osInit.MainInit,
"netconf": network.Main, "netconf": network.Main,
"poweroff": power.PowerOff, "poweroff": power.Off,
"reboot": power.Reboot, "reboot": power.Reboot,
"respawn": respawn.Main, "respawn": respawn.Main,
"ros-sysinit": sysinit.Main, "ros-sysinit": sysinit.Main,

View File

@ -119,10 +119,10 @@ func (b *Bonding) Opt(key, value string) error {
if err := ioutil.WriteFile(p, []byte(value), 0644); err != nil { if err := ioutil.WriteFile(p, []byte(value), 0644); err != nil {
logrus.Errorf("Failed to set %s=%s on %s: %v", key, value, b.name, err) logrus.Errorf("Failed to set %s=%s on %s: %v", key, value, b.name, err)
return err return err
} else {
logrus.Infof("Set %s=%s on %s", key, value, b.name)
} }
logrus.Infof("Set %s=%s on %s", key, value, b.name)
return nil return nil
} }

View File

@ -85,8 +85,8 @@ func createSlaveInterfaces(netCfg *config.NetworkConfig) {
} }
for _, vlanDef := range vlanDefs { for _, vlanDef := range vlanDefs {
if _, err = NewVlan(link, vlanDef.Name, vlanDef.Id); err != nil { if _, err = NewVlan(link, vlanDef.Name, vlanDef.ID); err != nil {
log.Errorf("Failed to create vlans on device %s, id %d: %v", link.Attrs().Name, vlanDef.Id, err) log.Errorf("Failed to create vlans on device %s, id %d: %v", link.Attrs().Name, vlanDef.ID, err)
} }
} }
} }
@ -183,7 +183,7 @@ func ApplyNetworkConfigs(netCfg *config.NetworkConfig) error {
return err return err
} }
func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDns bool) error { func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDNS bool) error {
populateDefault(netCfg) populateDefault(netCfg)
links, err := netlink.LinkList() links, err := netlink.LinkList()
@ -203,7 +203,7 @@ func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDns bool) error {
for iface, args := range dhcpLinks { for iface, args := range dhcpLinks {
wg.Add(1) wg.Add(1)
go func(iface, args string) { go func(iface, args string) {
runDhcp(netCfg, iface, args, setHostname, setDns) runDhcp(netCfg, iface, args, setHostname, setDNS)
wg.Done() wg.Done()
}(iface, args) }(iface, args)
} }
@ -212,7 +212,7 @@ func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDns bool) error {
return err return err
} }
func runDhcp(netCfg *config.NetworkConfig, iface string, argstr string, setHostname, setDns bool) { func runDhcp(netCfg *config.NetworkConfig, iface string, argstr string, setHostname, setDNS bool) {
log.Infof("Running DHCP on %s", iface) log.Infof("Running DHCP on %s", iface)
args := []string{} args := []string{}
if argstr != "" { if argstr != "" {
@ -230,7 +230,7 @@ func runDhcp(netCfg *config.NetworkConfig, iface string, argstr string, setHostn
args = append(args, "-e", "force_hostname=true") args = append(args, "-e", "force_hostname=true")
} }
if !setDns { if !setDNS {
args = append(args, "--nohook", "resolv.conf") args = append(args, "--nohook", "resolv.conf")
} }
@ -273,14 +273,14 @@ func setGateway(gateway string) error {
return nil return nil
} }
gatewayIp := net.ParseIP(gateway) gatewayIP := net.ParseIP(gateway)
if gatewayIp == nil { if gatewayIP == nil {
return errors.New("Invalid gateway address " + gateway) return errors.New("Invalid gateway address " + gateway)
} }
route := netlink.Route{ route := netlink.Route{
Scope: netlink.SCOPE_UNIVERSE, Scope: netlink.SCOPE_UNIVERSE,
Gw: gatewayIp, Gw: gatewayIP,
} }
if err := netlink.RouteAdd(&route); err == syscall.EEXIST { if err := netlink.RouteAdd(&route); err == syscall.EEXIST {

View File

@ -9,7 +9,7 @@ import (
) )
type VlanDefinition struct { type VlanDefinition struct {
Id int ID int
Name string Name string
} }
@ -65,7 +65,7 @@ func ParseVlanDefinitions(vlans string) ([]VlanDefinition, error) {
} }
def := VlanDefinition{ def := VlanDefinition{
Id: id, ID: id,
} }
if len(idName) > 1 { if len(idName) > 1 {

View File

@ -15,5 +15,5 @@ fi
OUTPUT=${OUTPUT:-bin/ros} OUTPUT=${OUTPUT:-bin/ros}
echo Building $OUTPUT echo Building $OUTPUT
CONST="-X github.com/docker/docker/dockerversion.GitCommit=${COMMIT} -X github.com/docker/docker/dockerversion.Version=${DOCKER_PATCH_VERSION} -X github.com/docker/docker/dockerversion.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -X github.com/docker/docker/dockerversion.IAmStatic=true -X github.com/rancher/os/config.VERSION=${VERSION} -X github.com/rancher/os/config.OS_REPO=${OS_REPO}" CONST="-X github.com/docker/docker/dockerversion.GitCommit=${COMMIT} -X github.com/docker/docker/dockerversion.Version=${DOCKER_PATCH_VERSION} -X github.com/docker/docker/dockerversion.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -X github.com/docker/docker/dockerversion.IAmStatic=true -X github.com/rancher/os/config.Version=${VERSION} -X github.com/rancher/os/config.OsRepo=${OS_REPO}"
go build -tags "selinux cgo daemon netgo dnspatch" -installsuffix netgo -ldflags "$CONST -linkmode external -extldflags -static -s -w" -o ${OUTPUT} go build -tags "selinux cgo daemon netgo dnspatch" -installsuffix netgo -ldflags "$CONST -linkmode external -extldflags -static -s -w" -o ${OUTPUT}

View File

@ -36,17 +36,17 @@ func getServices(urls []string, key string) ([]string, error) {
result := []string{} result := []string{}
for _, url := range urls { for _, url := range urls {
indexUrl := fmt.Sprintf("%s/index.yml", url) indexURL := fmt.Sprintf("%s/index.yml", url)
content, err := LoadResource(indexUrl, true) content, err := LoadResource(indexURL, true)
if err != nil { if err != nil {
log.Errorf("Failed to load %s: %v", indexUrl, err) log.Errorf("Failed to load %s: %v", indexURL, err)
continue continue
} }
services := make(map[string][]string) services := make(map[string][]string)
err = yaml.Unmarshal(content, &services) err = yaml.Unmarshal(content, &services)
if err != nil { if err != nil {
log.Errorf("Failed to unmarshal %s: %v", indexUrl, err) log.Errorf("Failed to unmarshal %s: %v", indexURL, err)
continue continue
} }
@ -59,14 +59,14 @@ func getServices(urls []string, key string) ([]string, error) {
} }
func SetProxyEnvironmentVariables(cfg *config.CloudConfig) { func SetProxyEnvironmentVariables(cfg *config.CloudConfig) {
if cfg.Rancher.Network.HttpProxy != "" { if cfg.Rancher.Network.HTTPProxy != "" {
err := os.Setenv("HTTP_PROXY", cfg.Rancher.Network.HttpProxy) err := os.Setenv("HTTP_PROXY", cfg.Rancher.Network.HTTPProxy)
if err != nil { if err != nil {
log.Errorf("Unable to set HTTP_PROXY: %s", err) log.Errorf("Unable to set HTTP_PROXY: %s", err)
} }
} }
if cfg.Rancher.Network.HttpsProxy != "" { if cfg.Rancher.Network.HTTPSProxy != "" {
err := os.Setenv("HTTPS_PROXY", cfg.Rancher.Network.HttpsProxy) err := os.Setenv("HTTPS_PROXY", cfg.Rancher.Network.HTTPSProxy)
if err != nil { if err != nil {
log.Errorf("Unable to set HTTPS_PROXY: %s", err) log.Errorf("Unable to set HTTPS_PROXY: %s", err)
} }
@ -128,7 +128,7 @@ func LoadResource(location string, network bool) ([]byte, error) {
return nil, ErrNotFound return nil, ErrNotFound
} }
func serviceUrl(url, name string) string { func serviceURL(url, name string) string {
return fmt.Sprintf("%s/%s/%s.yml", url, name[0:1], name) return fmt.Sprintf("%s/%s/%s.yml", url, name[0:1], name)
} }
@ -144,10 +144,10 @@ func LoadServiceResource(name string, useNetwork bool, cfg *config.CloudConfig)
urls := cfg.Rancher.Repositories.ToArray() urls := cfg.Rancher.Repositories.ToArray()
for _, url := range urls { for _, url := range urls {
serviceUrl := serviceUrl(url, name) serviceURL := serviceURL(url, name)
bytes, err = LoadResource(serviceUrl, useNetwork) bytes, err = LoadResource(serviceURL, useNetwork)
if err == nil { if err == nil {
log.Debugf("Loaded %s from %s", name, serviceUrl) log.Debugf("Loaded %s from %s", name, serviceURL)
return bytes, nil return bytes, nil
} }
} }

View File

@ -18,7 +18,7 @@ import (
) )
const ( const (
DOCKER_CGROUPS_FILE = "/proc/self/cgroup" dockerCgroupsFile = "/proc/self/cgroup"
) )
type AnyMap map[interface{}]interface{} type AnyMap map[interface{}]interface{}
@ -196,8 +196,8 @@ func TrimSplit(str, sep string) []string {
return TrimSplitN(str, sep, -1) return TrimSplitN(str, sep, -1)
} }
func GetCurrentContainerId() (string, error) { func GetCurrentContainerID() (string, error) {
file, err := os.Open(DOCKER_CGROUPS_FILE) file, err := os.Open(dockerCgroupsFile)
if err != nil { if err != nil {
return "", err return "", err