Skip to content

Commit 0d93575

Browse files
committed
rewrite the config sample
1 parent e349cfa commit 0d93575

File tree

7 files changed

+137
-119
lines changed

7 files changed

+137
-119
lines changed

cluster/calcium/calcium_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewTestCluster() *Calcium {
3232
Git: types.GitConfig{
3333
CloneTimeout: 300 * time.Second,
3434
},
35-
Scheduler: types.SchedConfig{
35+
Scheduler: types.SchedulerConfig{
3636
MaxShare: -1,
3737
ShareBase: 100,
3838
},

core.yaml.sample

+53-33
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,78 @@
1-
log_level: "DEBUG"
2-
bind: ":5001"
3-
statsd: "127.0.0.1:8125"
4-
profile: ":12346"
5-
global_timeout: 300s
6-
connection_timeout: 10s
7-
lock_timeout: 30s
8-
cert_path: "/etc/eru/tls"
9-
sentry_dsn: "https://examplePublicKey@o0.ingest.sentry.io/0"
10-
max_concurrency: 20
11-
12-
auth:
1+
log_level: "DEBUG" # required, default INFO
2+
bind: ":5001" # required, default 5001
3+
lock_timeout: 30s # required, default 30s
4+
global_timeout: 300s # required, default 300s
5+
connection_timeout: 10s # required, default 10s
6+
ha_keepalive_interval: 16s # required, default 16s
7+
statsd: "127.0.0.1:8125" # optional
8+
profile: ":12346" # optional
9+
cert_path: "/etc/eru/tls" # optional, if you need connect to daemon without https
10+
max_concurrency: 20 # optional, default 20 for pool size
11+
store: etcd # optional, default etcd can choose redis
12+
sentry_dsn: "https://examplePublicKey@o0.ingest.sentry.io/0" # optional
13+
14+
wal_file: core.wal # required, default core.wal
15+
wal_open_timeout: 8s # required, default 8s
16+
17+
resource_plugins_dir: /etc/eru/plugins # optional, default /etc/eru/plugins
18+
resource_plugins_timeout: 30s # optional, if need to use plugin, set it
19+
20+
auth: # optional
1321
username: admin
1422
password: password
1523

16-
grpc:
17-
max_concurrent_streams: 100
18-
max_recv_msg_size: 30 # will covert to MBytes
19-
service_discovery_interval: 5s # WatchServiceStatus push interval
20-
service_heartbeat_interval: 5s # RegisterService heartbeat
24+
grpc: # required
25+
max_concurrent_streams: 100 # default 100
26+
max_recv_msg_size: 20971520 # in MBytes # default 20971520
27+
service_discovery_interval: 5s # WatchServiceStatus push interval # default 15s
28+
service_heartbeat_interval: 5s # RegisterService heartbeat # default 15s
2129

22-
store: etcd
30+
git: # optional
31+
scm_type: "github"
32+
private_key: "***REMOVED***" # file path
33+
token: "***REMOVED***"
34+
clone_timeout: 300s
2335

2436
etcd:
25-
machines:
37+
machines: # required
2638
- "http://127.0.0.1:2379"
27-
prefix: "/core"
28-
lock_prefix: "core/_lock"
39+
prefix: "/eru" # required, default /eru
40+
lock_prefix: "__lock__/eru" # required, default __lock__/eru
2941
ca: PATH_TO_CA
3042
key: PATH_TO_KEY
3143
cert: PATH_TO_CERT
3244
auth:
3345
username: root
3446
password: root
3547

36-
git:
37-
private_key: "***REMOVED***"
38-
token: "***REMOVED***"
39-
scm_type: "github"
40-
clone_timeout: 300s
48+
redis: # optional
49+
addr: localhost:6379
50+
lock_prefix: "/lock" # default /lock
51+
db: 0
4152

4253
docker:
54+
version: "1.32" # required, default 1.32
55+
network_mode: "bridge" # required, default host
56+
use_local_dns: true
4357
log:
44-
type: "json-file"
58+
type: "json-file" # required, default journald
4559
config:
4660
"max-size": "10m"
47-
network_mode: "bridge"
61+
4862
hub: "hub.docker.com"
4963
namespace: "projecteru2"
5064
build_pod: "eru-test"
51-
local_dns: true
52-
53-
scheduler:
54-
maxshare: -1
55-
sharebase: 100
65+
auth:
66+
username: root
67+
password: root
5668

5769
virt:
5870
version: "v1"
71+
72+
systemd:
73+
runtime: "io.containerd.eru.v2"
74+
75+
scheduler:
76+
maxshare: -1 # required default -1
77+
sharebase: 100 # required default 100
78+
max_deploy_count: 10000

resources/cpumem/models/cpumem_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newTestCPUMem(t *testing.T) *CPUMem {
1919
Etcd: coretypes.EtcdConfig{
2020
Prefix: "/cpumem",
2121
},
22-
Scheduler: coretypes.SchedConfig{
22+
Scheduler: coretypes.SchedulerConfig{
2323
MaxShare: -1,
2424
ShareBase: 100,
2525
},
@@ -73,7 +73,7 @@ func TestNewCPUMem(t *testing.T) {
7373
Etcd: coretypes.EtcdConfig{
7474
Machines: []string{"invalid-address"},
7575
},
76-
Scheduler: coretypes.SchedConfig{
76+
Scheduler: coretypes.SchedulerConfig{
7777
MaxShare: -1,
7878
ShareBase: 100,
7979
},

resources/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewPluginManager(config types.Config) (*PluginManager, error) {
3434

3535
// LoadPlugins .
3636
func (pm *PluginManager) LoadPlugins(ctx context.Context) error {
37-
if len(pm.config.ResourcePluginsDir) > 0 {
37+
if len(pm.config.ResourcePluginsDir) > 0 { // it's not a slice !
3838
pluginFiles, err := utils.ListAllExecutableFiles(pm.config.ResourcePluginsDir)
3939
if err != nil {
4040
log.Errorf(ctx, "[LoadPlugins] failed to list all executable files dir: %v, err: %v", pm.config.ResourcePluginsDir, err)

resources/volume/models/volume_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func newTestVolume(t *testing.T) *Volume {
1818
Etcd: coretypes.EtcdConfig{
1919
Prefix: "/Volume",
2020
},
21-
Scheduler: coretypes.SchedConfig{
21+
Scheduler: coretypes.SchedulerConfig{
2222
MaxShare: -1,
2323
ShareBase: 100,
2424
MaxDeployCount: 1000,

types/config.go

+76-80
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package types
22

33
import (
4-
"crypto/sha1" // #nosec
4+
// #nosec
5+
"crypto/sha256"
6+
"encoding/json"
57
"fmt"
6-
"strconv"
7-
"strings"
88
"time"
99
)
1010

@@ -18,50 +18,70 @@ const (
1818
// Config holds eru-core config
1919
type Config struct {
2020
LogLevel string `yaml:"log_level" required:"true" default:"INFO"`
21-
Bind string `yaml:"bind" required:"true" default:"5001"` // HTTP API address
22-
LockTimeout time.Duration `yaml:"lock_timeout" required:"true" default:"30s"` // timeout for lock (ttl)
23-
GlobalTimeout time.Duration `yaml:"global_timeout" required:"true" default:"300s"` // timeout for remove, run_and_wait and build, in second
24-
ConnectionTimeout time.Duration `yaml:"connection_timeout" default:"10s"` // timeout for connections
25-
HAKeepaliveInterval time.Duration `yaml:"ha_keepalive_interval" default:"16s"` // interval for node status watcher
26-
Statsd string `yaml:"statsd"` // statsd host and port
27-
Profile string `yaml:"profile"` // profile ip:port
28-
CertPath string `yaml:"cert_path"` // docker cert files path
29-
MaxConcurrency int64 `yaml:"max_concurrency" default:"20"` // concurrently call single runtime in the same time
30-
Store string `yaml:"store" default:"etcd"` // store type
31-
32-
ResourcePluginsDir string `yaml:"resource_plugins_dir" default:"/etc/eru/resource_plugins"` // resource plugins path
33-
ResourcePluginsTimeout time.Duration `yaml:"resource_plugins_timeout" default:"30s"` // timeout for calling resource plugins
34-
35-
Auth AuthConfig `yaml:"auth"` // grpc auth
36-
GRPCConfig GRPCConfig `yaml:"grpc"` // grpc config
21+
Bind string `yaml:"bind" required:"true" default:"5001"` // HTTP API address
22+
LockTimeout time.Duration `yaml:"lock_timeout" required:"true" default:"30s"` // timeout for lock (ttl)
23+
GlobalTimeout time.Duration `yaml:"global_timeout" required:"true" default:"300s"` // timeout for remove, run_and_wait and build, in second
24+
ConnectionTimeout time.Duration `yaml:"connection_timeout" required:"true" default:"10s"` // timeout for connections
25+
HAKeepaliveInterval time.Duration `yaml:"ha_keepalive_interval" required:"true" default:"16s"` // interval for node status watcher
26+
Statsd string `yaml:"statsd"` // statsd host and port
27+
Profile string `yaml:"profile"` // profile ip:port
28+
CertPath string `yaml:"cert_path"` // docker cert files path
29+
MaxConcurrency int64 `yaml:"max_concurrency" default:"20"` // concurrently call single runtime in the same time
30+
Store string `yaml:"store" default:"etcd"` // store type
31+
SentryDSN string `yaml:"sentry_dsn"`
3732

3833
WALFile string `yaml:"wal_file" required:"true" default:"core.wal"` // WAL file path
3934
WALOpenTimeout time.Duration `yaml:"wal_open_timeout" required:"true" default:"8s"` // timeout for opening a WAL file
4035

41-
Git GitConfig `yaml:"git"`
42-
Etcd EtcdConfig `yaml:"etcd"`
43-
Redis RedisConfig `yaml:"redis"`
44-
Docker DockerConfig `yaml:"docker"`
45-
Scheduler SchedConfig `yaml:"scheduler"`
46-
Virt VirtConfig `yaml:"virt"`
47-
Systemd SystemdConfig `yaml:"systemd"`
48-
SentryDSN string `yaml:"sentry_dsn"`
36+
ResourcePluginsDir string `yaml:"resource_plugins_dir" default:"/etc/eru/plugins"` // resource plugins path
37+
ResourcePluginsTimeout time.Duration `yaml:"resource_plugins_timeout" default:"30s"` // timeout for calling resource plugins
38+
39+
Auth AuthConfig `yaml:"auth"` // grpc auth
40+
GRPCConfig GRPCConfig `yaml:"grpc"` // grpc config
41+
Git GitConfig `yaml:"git"`
42+
Etcd EtcdConfig `yaml:"etcd"`
43+
Redis RedisConfig `yaml:"redis"`
44+
Docker DockerConfig `yaml:"docker"`
45+
Virt VirtConfig `yaml:"virt"`
46+
Systemd SystemdConfig `yaml:"systemd"`
47+
Scheduler SchedulerConfig `yaml:"scheduler"`
4948
}
5049

5150
// Identifier returns the id of this config
5251
// we consider the same storage as the same config
53-
func (c Config) Identifier() string {
54-
s := strings.Builder{}
55-
_, _ = s.WriteString(c.Store)
56-
for _, e := range c.Etcd.Machines {
57-
_, _ = s.WriteString(e)
52+
func (c Config) Identifier() (string, error) {
53+
b, err := json.Marshal(c)
54+
if err != nil {
55+
return "", err
5856
}
59-
_, _ = s.WriteString(c.Etcd.Prefix)
60-
_, _ = s.WriteString(c.Redis.Addr)
61-
_, _ = s.WriteString(strconv.Itoa(c.Redis.DB))
62-
h := sha1.New() // #nosec
63-
_, _ = h.Write([]byte(s.String()))
64-
return fmt.Sprintf("%x", h.Sum(nil))
57+
h := sha256.New()
58+
h.Write(b)
59+
return fmt.Sprintf("%x", h.Sum(nil)), nil
60+
}
61+
62+
// AuthConfig contains authorization information for connecting to a Registry
63+
// Basically copied from https://github.com/moby/moby/blob/16a1736b9b93e44c898f95d670bbaf20a558103d/api/types/auth.go#L4
64+
// But use yaml instead of json
65+
// And we use it as grpc simple auth
66+
type AuthConfig struct {
67+
Username string `yaml:"username,omitempty" json:"username,omitempty"`
68+
Password string `yaml:"password,omitempty" json:"password,omitempty"`
69+
}
70+
71+
// GRPCConfig indicate grpc config
72+
type GRPCConfig struct {
73+
MaxConcurrentStreams int `yaml:"max_concurrent_streams,omitempty" json:"max_concurrent_streams,omitempty" required:"true" default:"100"`
74+
MaxRecvMsgSize int `yaml:"max_recv_msg_size,omitempty" json:"max_recv_msg_size,omitempty" required:"true" default:"20971520"`
75+
ServiceDiscoveryPushInterval time.Duration `yaml:"service_discovery_interval" required:"true" default:"15s"`
76+
ServiceHeartbeatInterval time.Duration `yaml:"service_heartbeat_interval" required:"true" default:"15s"`
77+
}
78+
79+
// GitConfig holds eru-core git config
80+
type GitConfig struct {
81+
SCMType string `yaml:"scm_type"` // source code manager type [gitlab/github]
82+
PrivateKey string `yaml:"private_key"` // private key to clone code
83+
Token string `yaml:"token"` // token to call SCM API
84+
CloneTimeout time.Duration `yaml:"clone_timeout" default:"300s"` // clone timeout
6585
}
6686

6787
// EtcdConfig holds eru-core etcd config
@@ -79,66 +99,42 @@ type EtcdConfig struct {
7999
// LockPrefix is used for lock
80100
type RedisConfig struct {
81101
Addr string `yaml:"addr" default:"localhost:6379"` // redis address
82-
DB int `yaml:"db" default:"0"` // redis db
83102
LockPrefix string `yaml:"lock_prefix" default:"/lock"` // redis lock prefix
84-
}
85-
86-
// GitConfig holds eru-core git config
87-
type GitConfig struct {
88-
SCMType string `yaml:"scm_type"` // source code manager type [gitlab/github]
89-
PrivateKey string `yaml:"private_key"` // private key to clone code
90-
Token string `yaml:"token"` // token to call SCM API
91-
CloneTimeout time.Duration `yaml:"clone_timeout" required:"true" default:"300s"` // clone timeout
103+
DB int `yaml:"db" default:"0"` // redis db
92104
}
93105

94106
// DockerConfig holds eru-core docker config
95107
type DockerConfig struct {
96-
APIVersion string `yaml:"version" required:"true" default:"1.32"` // docker API version
97-
NetworkMode string `yaml:"network_mode" required:"true" default:"host"` // docker network mode
98-
Hub string `yaml:"hub"` // docker hub address
99-
Namespace string `yaml:"namespace"` // docker hub prefix, will be set to $Hub/$HubPrefix/$appname
100-
BuildPod string `yaml:"build_pod"` // podname used to build
101-
UseLocalDNS bool `yaml:"local_dns"` // use node IP as dns
102-
Log LogConfig `yaml:"log"` // docker log driver
103-
AuthConfigs map[string]AuthConfig `yaml:"auths"` // docker registry credentials
108+
APIVersion string `yaml:"version" required:"true" default:"1.32"` // docker API version
109+
NetworkMode string `yaml:"network_mode" required:"true" default:"host"` // docker network mode
110+
UseLocalDNS bool `yaml:"use_local_dns"` // use node IP as dns
111+
Log LogConfig `yaml:"log"` // docker log driver
112+
113+
Hub string `yaml:"hub"` // docker hub address
114+
Namespace string `yaml:"namespace"` // docker hub prefix, will be set to $Hub/$HubPrefix/$appname
115+
BuildPod string `yaml:"build_pod"` // podname used to build
116+
AuthConfigs map[string]AuthConfig `yaml:"auths"` // docker registry credentials
104117
}
105118

106119
// VirtConfig holds yavirtd config
107120
type VirtConfig struct {
108-
APIVersion string `yaml:"version"` // Yavirtd API version
121+
APIVersion string `yaml:"version" default:"v1"` // Yavirtd API version
109122
}
110123

111124
// SystemdConfig is systemd config
112125
type SystemdConfig struct {
113126
Runtime string `yaml:"runtime" default:"io.containerd.eru.v2"`
114127
}
115128

129+
// SchedulerConfig holds scheduler config
130+
type SchedulerConfig struct {
131+
MaxShare int `yaml:"maxshare" required:"true" default:"-1"` // comlpex scheduler use maxshare
132+
ShareBase int `yaml:"sharebase" required:"true" default:"100"` // how many pieces for one core
133+
MaxDeployCount int `yaml:"max_deploy_count" default:"10000"` // max deploy count of each node
134+
}
135+
116136
// LogConfig define log type
117137
type LogConfig struct {
118138
Type string `yaml:"type" required:"true" default:"journald"` // Log type, can be "journald", "json-file", "none"
119139
Config map[string]string `yaml:"config"` // Log configs
120140
}
121-
122-
// SchedConfig holds scheduler config
123-
type SchedConfig struct {
124-
MaxShare int `yaml:"maxshare" required:"true" default:"-1"` // comlpex scheduler use maxshare
125-
ShareBase int `yaml:"sharebase" required:"true" default:"100"` // how many pieces for one core
126-
MaxDeployCount int `yaml:"max_deploy_count" required:"false" default:"10000"` // max deploy count of each node
127-
}
128-
129-
// AuthConfig contains authorization information for connecting to a Registry
130-
// Basically copied from https://github.com/moby/moby/blob/16a1736b9b93e44c898f95d670bbaf20a558103d/api/types/auth.go#L4
131-
// But use yaml instead of json
132-
// And we use it as grpc simple auth
133-
type AuthConfig struct {
134-
Username string `yaml:"username,omitempty" json:"username,omitempty"`
135-
Password string `yaml:"password,omitempty" json:"password,omitempty"`
136-
}
137-
138-
// GRPCConfig indicate grpc config
139-
type GRPCConfig struct {
140-
MaxConcurrentStreams int `yaml:"max_concurrent_streams,omitempty" json:"max_concurrent_streams,omitempty" required:"true" default:"100"`
141-
MaxRecvMsgSize int `yaml:"max_recv_msg_size,omitempty" json:"max_recv_msg_size,omitempty" required:"true" default:"20971520"`
142-
ServiceDiscoveryPushInterval time.Duration `yaml:"service_discovery_interval" required:"true" default:"15s"`
143-
ServiceHeartbeatInterval time.Duration `yaml:"service_heartbeat_interval" required:"true" default:"15s"`
144-
}

types/config_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ func TestIdentifier(t *testing.T) {
1414
"2.2.2.2",
1515
},
1616
}
17-
assert.NotEmpty(t, config.Identifier())
17+
r, err := config.Identifier()
18+
assert.NoError(t, err)
19+
assert.NotEmpty(t, r)
1820
}

0 commit comments

Comments
 (0)