/
checker.go
116 lines (104 loc) · 3.43 KB
/
checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/pkg/errors"
"github.com/tsuru/config"
)
func checkBasicConfig() error {
return checkConfigPresent([]string{
"listen",
"host",
}, "Config error: you should have %q key set in your config file")
}
func checkDatabase() error {
if value, _ := config.GetString("database:driver"); value != "mongodb" && value != "" {
return errors.Errorf("Config error: mongodb is the only database driver currently supported")
}
return checkConfigPresent([]string{
"database:url",
"database:name",
}, "Config error: you should have %q key set in your config file")
}
// Check provisioner configs
func checkProvisioner() error {
if value, _ := config.Get("provisioner"); value == defaultProvisionerName || value == "" {
return checkDocker()
}
return nil
}
func checkBeanstalkd() error {
if value, _ := config.Get("queue"); value == "beanstalkd" {
return errors.New("beanstalkd is no longer supported, please use redis instead")
}
if _, err := config.Get("queue-server"); err == nil {
return errors.New(`beanstalkd is no longer supported, please remove the "queue-server" setting from your config file`)
}
return nil
}
func checkQueue() error {
queueConfig, _ := config.GetString("queue:mongo-url")
if queueConfig == "" {
return config.NewWarning(`Config entry "queue:mongo-url" is not set, default "localhost" will be used. Running "tsuru docker-node-{add,remove}" commands might not work.`)
}
return nil
}
// Check Docker configs
func checkDocker() error {
if _, err := config.Get("docker"); err != nil {
return errors.New("Config error: you should configure docker.")
}
err := checkDockerBasicConfig()
if err != nil {
return err
}
err = checkScheduler()
if err != nil {
return err
}
return checkCluster()
}
// Check default configs to Docker.
func checkDockerBasicConfig() error {
return checkConfigPresent([]string{
"docker:collection",
}, "Config error: you should configure %q")
}
func checkCluster() error {
storage, _ := config.GetString("docker:cluster:storage")
if storage != "mongodb" && storage != "" {
return errors.Errorf("Config error: docker:cluster:storage is deprecated. mongodb is now the only storage available.")
}
mustHave := []string{"docker:cluster:mongo-url", "docker:cluster:mongo-database"}
for _, value := range mustHave {
if _, err := config.Get(value); err != nil {
return errors.Errorf("Config error: you should configure %q", value)
}
}
return nil
}
// Check Schedulers
// It verifies your scheduler configuration and validates related confs.
func checkScheduler() error {
if servers, err := config.Get("docker:servers"); err == nil && servers != nil {
return errors.Errorf(`Using docker:servers is deprecated, please remove it your config and use "tsuru docker-node-add" do add docker nodes.`)
}
isSegregate, err := config.GetBool("docker:segregate")
if err == nil {
if isSegregate {
return config.NewWarning(`Setting "docker:segregate" is not necessary anymore, this is the default behavior from now on.`)
} else {
return errors.Errorf(`You must remove "docker:segregate" from your config.`)
}
}
return nil
}
func checkConfigPresent(keys []string, fmtMsg string) error {
for _, key := range keys {
if _, err := config.Get(key); err != nil {
return errors.Errorf(fmtMsg, key)
}
}
return nil
}