1
0
mirror of https://github.com/rancher/os.git synced 2025-06-25 14:31:33 +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"
)
type metadataService struct {
type MetadataService struct {
metadata.MetadataService
}
func NewDatasource(root string) *metadataService {
return &metadataService{metadata.NewDatasource(root, apiVersion, userdataPath, metadataPath, http.Header{"Metadata-Flavor": {"Google"}})}
func NewDatasource(root string) *MetadataService {
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")
if err != nil {
return datasource.Metadata{}, err
@ -53,16 +53,16 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {
return datasource.Metadata{}, err
}
projectSshKeys, err := ms.fetchString("project/attributes/sshKeys")
projectSSHKeys, err := ms.fetchString("project/attributes/sshKeys")
if err != nil {
return datasource.Metadata{}, err
}
instanceSshKeys, err := ms.fetchString("instance/attributes/sshKeys")
instanceSSHKeys, err := ms.fetchString("instance/attributes/sshKeys")
if err != nil {
return datasource.Metadata{}, err
}
keyStrings := strings.Split(projectSshKeys+"\n"+instanceSshKeys, "\n")
keyStrings := strings.Split(projectSSHKeys+"\n"+instanceSSHKeys, "\n")
sshPublicKeys := map[string]string{}
i := 0
@ -85,11 +85,11 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {
}, nil
}
func (ms metadataService) Type() string {
func (ms MetadataService) Type() string {
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)
if err != nil {
return "", err
@ -98,7 +98,7 @@ func (ms metadataService) fetchString(key string) (string, error) {
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)
if err != nil {
return nil, err
@ -110,12 +110,11 @@ func (ms metadataService) fetchIP(key string) (net.IP, error) {
if ip := net.ParseIP(str); 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())
if err != nil {
return nil, err

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -66,7 +66,7 @@ func installAction(c *cli.Context) error {
image := c.String("image")
cfg := config.LoadConfig()
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")

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.
func getImages() (*Images, error) {
upgradeUrl, err := getUpgradeUrl()
upgradeURL, err := getUpgradeURL()
if err != nil {
return nil, err
}
var body []byte
if strings.HasPrefix(upgradeUrl, "/") {
body, err = ioutil.ReadFile(upgradeUrl)
if strings.HasPrefix(upgradeURL, "/") {
body, err = ioutil.ReadFile(upgradeURL)
if err != nil {
return nil, err
}
} else {
u, err := url.Parse(upgradeUrl)
u, err := url.Parse(upgradeURL)
if err != nil {
return nil, err
}
q := u.Query()
q.Set("current", config.VERSION)
q.Set("current", config.Version)
u.RawQuery = q.Encode()
upgradeUrl = u.String()
upgradeURL = u.String()
resp, err := http.Get(upgradeUrl)
resp, err := http.Get(upgradeURL)
if err != nil {
return nil, err
}
@ -129,7 +129,7 @@ func osMetaDataGet(c *cli.Context) error {
}
cfg := config.LoadConfig()
runningName := cfg.Rancher.Upgrade.Image + ":" + config.VERSION
runningName := cfg.Rancher.Upgrade.Image + ":" + config.Version
foundRunning := false
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)
}
if !foundRunning {
fmt.Println(config.VERSION, "running")
fmt.Println(config.Version, "running")
}
return nil
@ -190,14 +190,14 @@ func osUpgrade(c *cli.Context) error {
}
func osVersion(c *cli.Context) error {
fmt.Println(config.VERSION)
fmt.Println(config.Version)
return nil
}
func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgradeConsole bool, kernelArgs string) error {
command := []string{
"-t", "rancher-upgrade",
"-r", config.VERSION,
"-r", config.Version,
}
if kexec {
@ -218,7 +218,7 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra
fmt.Printf("Upgrading to %s\n", image)
confirmation := "Continue"
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])
}
if !force && !yes(confirmation) {
@ -232,7 +232,7 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra
Pid: "host",
Image: image,
Labels: map[string]string{
config.SCOPE: config.SYSTEM,
config.ScopeLabel: config.System,
},
Command: command,
})
@ -290,7 +290,7 @@ func parseBody(body []byte) (*Images, error) {
return update, nil
}
func getUpgradeUrl() (string, error) {
func getUpgradeURL() (string, error) {
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", "/var/lib/selinux:/var/lib/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{})
return nil
}

View File

@ -16,8 +16,8 @@ import (
const (
NAME string = "rancher"
BITS int = 2048
ServerTlsPath string = "/etc/docker/tls"
ClientTlsPath string = "/home/rancher/.docker"
ServerTLSPath string = "/etc/docker/tls"
ClientTLSPath string = "/home/rancher/.docker"
Cert string = "cert.pem"
Key string = "key.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 {
if outDir == "" {
if generateServer {
outDir = ServerTlsPath
outDir = ServerTLSPath
} else {
outDir = ClientTlsPath
outDir = ClientTLSPath
}
log.Infof("Out directory (-d, --dir) not specified, using default: %s", outDir)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,7 +46,7 @@ type Config struct {
Fork bool
PidOne bool
CommandName string
DnsConfig config.DnsConfig
DNSConfig config.DNSConfig
BridgeName string
BridgeAddress string
BridgeMtu int
@ -209,10 +209,9 @@ func execDocker(config *Config, docker, cmd string, args []string) (*exec.Cmd, e
PidOne()
}
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 {
@ -352,8 +351,8 @@ ff02::2 ip6-allrouters
127.0.1.1 `+hostname)
if len(cfg.DnsConfig.Nameservers) != 0 {
if _, err := resolvconf.Build("/etc/resolv.conf", cfg.DnsConfig.Nameservers, cfg.DnsConfig.Search, nil); err != nil {
if len(cfg.DNSConfig.Nameservers) != 0 {
if _, err := resolvconf.Build("/etc/resolv.conf", cfg.DNSConfig.Nameservers, cfg.DNSConfig.Search, nil); err != nil {
return err
}
}
@ -382,12 +381,10 @@ func GetValue(index int, args []string) string {
if len(parts) == 1 {
if len(args) > index+1 {
return args[index+1]
} else {
return ""
}
} else {
return parts[1]
return ""
}
return parts[1]
}
func ParseConfig(config *Config, args ...string) []string {

View File

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

View File

@ -25,8 +25,8 @@ func NewClientFactory(opts composeClient.Options) (project.ClientFactory, error)
userOpts := opts
systemOpts := opts
userOpts.Host = config.DOCKER_HOST
systemOpts.Host = config.DOCKER_SYSTEM_HOST
userOpts.Host = config.DockerHost
systemOpts.Host = config.SystemDockerHost
userClient, err := composeClient.Create(userOpts)
if err != nil {
@ -46,11 +46,11 @@ func NewClientFactory(opts composeClient.Options) (project.ClientFactory, error)
func (c *ClientFactory) Create(service project.Service) dockerclient.APIClient {
if IsSystemContainer(service.Config()) {
waitFor(&c.systemOnce, c.systemClient, config.DOCKER_SYSTEM_HOST)
waitFor(&c.systemOnce, c.systemClient, config.SystemDockerHost)
return c.systemClient
}
waitFor(&c.userOnce, c.userClient, config.DOCKER_HOST)
waitFor(&c.userOnce, c.userClient, config.DockerHost)
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 {
environment := cfg.Rancher.Environment
if cfg.Rancher.Network.HttpProxy != "" {
environment["http_proxy"] = cfg.Rancher.Network.HttpProxy
environment["HTTP_PROXY"] = cfg.Rancher.Network.HttpProxy
if cfg.Rancher.Network.HTTPProxy != "" {
environment["http_proxy"] = cfg.Rancher.Network.HTTPProxy
environment["HTTP_PROXY"] = cfg.Rancher.Network.HTTPProxy
}
if cfg.Rancher.Network.HttpsProxy != "" {
environment["https_proxy"] = cfg.Rancher.Network.HttpsProxy
environment["HTTPS_PROXY"] = cfg.Rancher.Network.HttpsProxy
if cfg.Rancher.Network.HTTPSProxy != "" {
environment["https_proxy"] = cfg.Rancher.Network.HTTPSProxy
environment["HTTPS_PROXY"] = cfg.Rancher.Network.HTTPSProxy
}
if 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 {
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 {
@ -93,8 +93,8 @@ func (s *Service) shouldRebuild(ctx context.Context) (bool, error) {
}
name := containerInfo.Name[1:]
origRebuildLabel := containerInfo.Config.Labels[config.REBUILD]
newRebuildLabel := s.Config().Labels[config.REBUILD]
origRebuildLabel := containerInfo.Config.Labels[config.RebuildLabel]
newRebuildLabel := s.Config().Labels[config.RebuildLabel]
rebuildLabelChanged := newRebuildLabel != origRebuildLabel
logrus.WithFields(logrus.Fields{
"origRebuildLabel": origRebuildLabel,
@ -113,8 +113,8 @@ func (s *Service) shouldRebuild(ctx context.Context) (bool, error) {
}
if outOfSync {
if s.Name() == "console" {
origConsoleLabel := containerInfo.Config.Labels[config.CONSOLE]
newConsoleLabel := s.Config().Labels[config.CONSOLE]
origConsoleLabel := containerInfo.Config.Labels[config.ConsoleLabel]
newConsoleLabel := s.Config().Labels[config.ConsoleLabel]
if newConsoleLabel != origConsoleLabel {
return true, nil
}
@ -154,13 +154,13 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
return err
}
}
if labels[config.CREATE_ONLY] == "true" {
if labels[config.CreateOnlyLabel] == "true" {
return s.checkReload(labels)
}
if err := s.Service.Up(ctx, options); err != nil {
return err
}
if labels[config.DETACH] == "false" {
if labels[config.DetachLabel] == "false" {
if err := s.wait(ctx); err != nil {
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 {
if labels[config.RELOAD_CONFIG] == "true" {
if labels[config.ReloadConfigLabel] == "true" {
return project.ErrRestart
}
return nil
@ -223,7 +223,6 @@ func (s *Service) rename(ctx context.Context) error {
if len(info.Name) > 0 && 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())
} else {
return nil
}
return nil
}

View File

@ -6,6 +6,5 @@ import (
)
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.NoLog = true
cmd, err := dfs.LaunchDocker(launchConfig, config.SYSTEM_DOCKER_BIN, args...)
cmd, err := dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil {
return nil, err
}

View File

@ -21,11 +21,11 @@ import (
)
const (
STATE string = "/state"
BOOT2DOCKER_MAGIC string = "boot2docker, please format-me"
state string = "/state"
boot2DockerMagic string = "boot2docker, please format-me"
TMPFS_MAGIC int64 = 0x01021994
RAMFS_MAGIC int64 = 0x858458f6
tmpfsMagic int64 = 0x01021994
ramfsMagic int64 = 0x858458f6
)
var (
@ -68,10 +68,10 @@ func loadModules(cfg *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{
Path: config.ROS_BIN,
Path: config.RosBin,
Args: args,
}
@ -117,7 +117,7 @@ func mountConfigured(display, dev, fsType, target string) 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) {
@ -164,12 +164,12 @@ func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*
args := dfs.ParseConfig(&launchConfig, dockerCfg.FullArgs()...)
launchConfig.DnsConfig.Nameservers = cfg.Rancher.Defaults.Network.Dns.Nameservers
launchConfig.DnsConfig.Search = cfg.Rancher.Defaults.Network.Dns.Search
launchConfig.DNSConfig.Nameservers = cfg.Rancher.Defaults.Network.DNS.Nameservers
launchConfig.DNSConfig.Search = cfg.Rancher.Defaults.Network.DNS.Search
launchConfig.Environment = dockerCfg.Environment
if !cfg.Rancher.Debug {
launchConfig.LogFile = config.SYSTEM_DOCKER_LOG
launchConfig.LogFile = config.SystemDockerLog
}
return &launchConfig, args
@ -178,7 +178,7 @@ func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*
func isInitrd() bool {
var stat syscall.Statfs_t
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) {
@ -246,7 +246,7 @@ func RunInit() error {
}
devices := []string{"/dev/sda", "/dev/vda"}
data := make([]byte, len(BOOT2DOCKER_MAGIC))
data := make([]byte, len(boot2DockerMagic))
for _, device := range devices {
f, err := os.Open(device)
@ -254,7 +254,7 @@ func RunInit() error {
defer f.Close()
_, err = f.Read(data)
if err == nil && string(data) == BOOT2DOCKER_MAGIC {
if err == nil && string(data) == boot2DockerMagic {
boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
cfg.Rancher.State.Autoformat = []string{device}
@ -278,7 +278,7 @@ func RunInit() error {
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 {
log.Error(err)
}
@ -324,8 +324,8 @@ func RunInit() error {
if !shouldSwitchRoot {
return cfg, nil
}
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 {
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 {
return cfg, err
}
return cfg, nil
@ -377,7 +377,7 @@ func RunInit() error {
launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec
log.Info("Launching System Docker")
_, err = dfs.LaunchDocker(launchConfig, config.SYSTEM_DOCKER_BIN, args...)
_, err = dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
if err != nil {
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 {
usrVer := fmt.Sprintf("usr-%s", config.VERSION)
usrVer := fmt.Sprintf("usr-%s", config.Version)
usr := path.Join(rootfs, usrVer)
targetUsr := path.Join(rootfs, "usr")
tmpDir := path.Join(rootfs, "tmp")

View File

@ -20,7 +20,7 @@ const (
)
func hasImage(name string) bool {
stamp := path.Join(STATE, name)
stamp := path.Join(state, name)
if _, err := os.Stat(stamp); os.IsNotExist(err) {
return false
}
@ -28,13 +28,13 @@ func hasImage(name string) bool {
}
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{}
dir, err := os.Open(config.IMAGES_PATH)
dir, err := os.Open(config.ImagesPath)
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
}
if err != nil {
@ -49,7 +49,7 @@ func findImages(cfg *config.CloudConfig) ([]string, error) {
}
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)
result = append(result, fileName)
}
@ -74,7 +74,7 @@ func loadImages(cfg *config.CloudConfig) (*config.CloudConfig, error) {
continue
}
inputFileName := path.Join(config.IMAGES_PATH, image)
inputFileName := path.Join(config.ImagesPath, image)
input, err := os.Open(inputFileName)
if err != nil {
return cfg, err
@ -119,7 +119,7 @@ func SysInit() error {
return cfg, nil
},
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 err

View File

@ -27,7 +27,7 @@ var entrypoints = map[string]func(){
"halt": power.Halt,
"init": osInit.MainInit,
"netconf": network.Main,
"poweroff": power.PowerOff,
"poweroff": power.Off,
"reboot": power.Reboot,
"respawn": respawn.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 {
logrus.Errorf("Failed to set %s=%s on %s: %v", key, value, b.name, 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
}

View File

@ -85,8 +85,8 @@ func createSlaveInterfaces(netCfg *config.NetworkConfig) {
}
for _, vlanDef := range vlanDefs {
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)
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)
}
}
}
@ -183,7 +183,7 @@ func ApplyNetworkConfigs(netCfg *config.NetworkConfig) error {
return err
}
func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDns bool) error {
func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDNS bool) error {
populateDefault(netCfg)
links, err := netlink.LinkList()
@ -203,7 +203,7 @@ func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDns bool) error {
for iface, args := range dhcpLinks {
wg.Add(1)
go func(iface, args string) {
runDhcp(netCfg, iface, args, setHostname, setDns)
runDhcp(netCfg, iface, args, setHostname, setDNS)
wg.Done()
}(iface, args)
}
@ -212,7 +212,7 @@ func RunDhcp(netCfg *config.NetworkConfig, setHostname, setDns bool) error {
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)
args := []string{}
if argstr != "" {
@ -230,7 +230,7 @@ func runDhcp(netCfg *config.NetworkConfig, iface string, argstr string, setHostn
args = append(args, "-e", "force_hostname=true")
}
if !setDns {
if !setDNS {
args = append(args, "--nohook", "resolv.conf")
}
@ -273,14 +273,14 @@ func setGateway(gateway string) error {
return nil
}
gatewayIp := net.ParseIP(gateway)
if gatewayIp == nil {
gatewayIP := net.ParseIP(gateway)
if gatewayIP == nil {
return errors.New("Invalid gateway address " + gateway)
}
route := netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
Gw: gatewayIp,
Gw: gatewayIP,
}
if err := netlink.RouteAdd(&route); err == syscall.EEXIST {

View File

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

View File

@ -15,5 +15,5 @@ fi
OUTPUT=${OUTPUT:-bin/ros}
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}

View File

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

View File

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