mirror of
https://github.com/rancher/os.git
synced 2025-09-01 23:04:41 +00:00
Fix golint errors
This commit is contained in:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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
|
||||
|
@@ -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"},
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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")
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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() {
|
||||
|
@@ -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()
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user