1
1
package types
2
2
3
3
import (
4
- "crypto/sha1" // #nosec
4
+ // #nosec
5
+ "crypto/sha256"
6
+ "encoding/json"
5
7
"fmt"
6
- "strconv"
7
- "strings"
8
8
"time"
9
9
)
10
10
@@ -18,50 +18,70 @@ const (
18
18
// Config holds eru-core config
19
19
type Config struct {
20
20
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"`
37
32
38
33
WALFile string `yaml:"wal_file" required:"true" default:"core.wal"` // WAL file path
39
34
WALOpenTimeout time.Duration `yaml:"wal_open_timeout" required:"true" default:"8s"` // timeout for opening a WAL file
40
35
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"`
49
48
}
50
49
51
50
// Identifier returns the id of this config
52
51
// 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
58
56
}
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
65
85
}
66
86
67
87
// EtcdConfig holds eru-core etcd config
@@ -79,66 +99,42 @@ type EtcdConfig struct {
79
99
// LockPrefix is used for lock
80
100
type RedisConfig struct {
81
101
Addr string `yaml:"addr" default:"localhost:6379"` // redis address
82
- DB int `yaml:"db" default:"0"` // redis db
83
102
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
92
104
}
93
105
94
106
// DockerConfig holds eru-core docker config
95
107
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
104
117
}
105
118
106
119
// VirtConfig holds yavirtd config
107
120
type VirtConfig struct {
108
- APIVersion string `yaml:"version"` // Yavirtd API version
121
+ APIVersion string `yaml:"version" default:"v1" ` // Yavirtd API version
109
122
}
110
123
111
124
// SystemdConfig is systemd config
112
125
type SystemdConfig struct {
113
126
Runtime string `yaml:"runtime" default:"io.containerd.eru.v2"`
114
127
}
115
128
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
+
116
136
// LogConfig define log type
117
137
type LogConfig struct {
118
138
Type string `yaml:"type" required:"true" default:"journald"` // Log type, can be "journald", "json-file", "none"
119
139
Config map [string ]string `yaml:"config"` // Log configs
120
140
}
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
- }
0 commit comments