Skip to content

Commit

Permalink
rewrite the config sample
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Jul 6, 2022
1 parent e349cfa commit 0d93575
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 119 deletions.
2 changes: 1 addition & 1 deletion cluster/calcium/calcium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewTestCluster() *Calcium {
Git: types.GitConfig{
CloneTimeout: 300 * time.Second,
},
Scheduler: types.SchedConfig{
Scheduler: types.SchedulerConfig{
MaxShare: -1,
ShareBase: 100,
},
Expand Down
86 changes: 53 additions & 33 deletions core.yaml.sample
Original file line number Diff line number Diff line change
@@ -1,58 +1,78 @@
log_level: "DEBUG"
bind: ":5001"
statsd: "127.0.0.1:8125"
profile: ":12346"
global_timeout: 300s
connection_timeout: 10s
lock_timeout: 30s
cert_path: "/etc/eru/tls"
sentry_dsn: "https://[email protected]/0"
max_concurrency: 20

auth:
log_level: "DEBUG" # required, default INFO
bind: ":5001" # required, default 5001
lock_timeout: 30s # required, default 30s
global_timeout: 300s # required, default 300s
connection_timeout: 10s # required, default 10s
ha_keepalive_interval: 16s # required, default 16s
statsd: "127.0.0.1:8125" # optional
profile: ":12346" # optional
cert_path: "/etc/eru/tls" # optional, if you need connect to daemon without https
max_concurrency: 20 # optional, default 20 for pool size
store: etcd # optional, default etcd can choose redis
sentry_dsn: "https://[email protected]/0" # optional

wal_file: core.wal # required, default core.wal
wal_open_timeout: 8s # required, default 8s

resource_plugins_dir: /etc/eru/plugins # optional, default /etc/eru/plugins
resource_plugins_timeout: 30s # optional, if need to use plugin, set it

auth: # optional
username: admin
password: password

grpc:
max_concurrent_streams: 100
max_recv_msg_size: 30 # will covert to MBytes
service_discovery_interval: 5s # WatchServiceStatus push interval
service_heartbeat_interval: 5s # RegisterService heartbeat
grpc: # required
max_concurrent_streams: 100 # default 100
max_recv_msg_size: 20971520 # in MBytes # default 20971520
service_discovery_interval: 5s # WatchServiceStatus push interval # default 15s
service_heartbeat_interval: 5s # RegisterService heartbeat # default 15s

store: etcd
git: # optional
scm_type: "github"
private_key: "***REMOVED***" # file path
token: "***REMOVED***"
clone_timeout: 300s

etcd:
machines:
machines: # required
- "http://127.0.0.1:2379"
prefix: "/core"
lock_prefix: "core/_lock"
prefix: "/eru" # required, default /eru
lock_prefix: "__lock__/eru" # required, default __lock__/eru
ca: PATH_TO_CA
key: PATH_TO_KEY
cert: PATH_TO_CERT
auth:
username: root
password: root

git:
private_key: "***REMOVED***"
token: "***REMOVED***"
scm_type: "github"
clone_timeout: 300s
redis: # optional
addr: localhost:6379
lock_prefix: "/lock" # default /lock
db: 0

docker:
version: "1.32" # required, default 1.32
network_mode: "bridge" # required, default host
use_local_dns: true
log:
type: "json-file"
type: "json-file" # required, default journald
config:
"max-size": "10m"
network_mode: "bridge"

hub: "hub.docker.com"
namespace: "projecteru2"
build_pod: "eru-test"
local_dns: true

scheduler:
maxshare: -1
sharebase: 100
auth:
username: root
password: root

virt:
version: "v1"

systemd:
runtime: "io.containerd.eru.v2"

scheduler:
maxshare: -1 # required default -1
sharebase: 100 # required default 100
max_deploy_count: 10000
4 changes: 2 additions & 2 deletions resources/cpumem/models/cpumem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newTestCPUMem(t *testing.T) *CPUMem {
Etcd: coretypes.EtcdConfig{
Prefix: "/cpumem",
},
Scheduler: coretypes.SchedConfig{
Scheduler: coretypes.SchedulerConfig{
MaxShare: -1,
ShareBase: 100,
},
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestNewCPUMem(t *testing.T) {
Etcd: coretypes.EtcdConfig{
Machines: []string{"invalid-address"},
},
Scheduler: coretypes.SchedConfig{
Scheduler: coretypes.SchedulerConfig{
MaxShare: -1,
ShareBase: 100,
},
Expand Down
2 changes: 1 addition & 1 deletion resources/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewPluginManager(config types.Config) (*PluginManager, error) {

// LoadPlugins .
func (pm *PluginManager) LoadPlugins(ctx context.Context) error {
if len(pm.config.ResourcePluginsDir) > 0 {
if len(pm.config.ResourcePluginsDir) > 0 { // it's not a slice !
pluginFiles, err := utils.ListAllExecutableFiles(pm.config.ResourcePluginsDir)
if err != nil {
log.Errorf(ctx, "[LoadPlugins] failed to list all executable files dir: %v, err: %v", pm.config.ResourcePluginsDir, err)
Expand Down
2 changes: 1 addition & 1 deletion resources/volume/models/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func newTestVolume(t *testing.T) *Volume {
Etcd: coretypes.EtcdConfig{
Prefix: "/Volume",
},
Scheduler: coretypes.SchedConfig{
Scheduler: coretypes.SchedulerConfig{
MaxShare: -1,
ShareBase: 100,
MaxDeployCount: 1000,
Expand Down
156 changes: 76 additions & 80 deletions types/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package types

import (
"crypto/sha1" // #nosec
// #nosec
"crypto/sha256"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
)

Expand All @@ -18,50 +18,70 @@ const (
// Config holds eru-core config
type Config struct {
LogLevel string `yaml:"log_level" required:"true" default:"INFO"`
Bind string `yaml:"bind" required:"true" default:"5001"` // HTTP API address
LockTimeout time.Duration `yaml:"lock_timeout" required:"true" default:"30s"` // timeout for lock (ttl)
GlobalTimeout time.Duration `yaml:"global_timeout" required:"true" default:"300s"` // timeout for remove, run_and_wait and build, in second
ConnectionTimeout time.Duration `yaml:"connection_timeout" default:"10s"` // timeout for connections
HAKeepaliveInterval time.Duration `yaml:"ha_keepalive_interval" default:"16s"` // interval for node status watcher
Statsd string `yaml:"statsd"` // statsd host and port
Profile string `yaml:"profile"` // profile ip:port
CertPath string `yaml:"cert_path"` // docker cert files path
MaxConcurrency int64 `yaml:"max_concurrency" default:"20"` // concurrently call single runtime in the same time
Store string `yaml:"store" default:"etcd"` // store type

ResourcePluginsDir string `yaml:"resource_plugins_dir" default:"/etc/eru/resource_plugins"` // resource plugins path
ResourcePluginsTimeout time.Duration `yaml:"resource_plugins_timeout" default:"30s"` // timeout for calling resource plugins

Auth AuthConfig `yaml:"auth"` // grpc auth
GRPCConfig GRPCConfig `yaml:"grpc"` // grpc config
Bind string `yaml:"bind" required:"true" default:"5001"` // HTTP API address
LockTimeout time.Duration `yaml:"lock_timeout" required:"true" default:"30s"` // timeout for lock (ttl)
GlobalTimeout time.Duration `yaml:"global_timeout" required:"true" default:"300s"` // timeout for remove, run_and_wait and build, in second
ConnectionTimeout time.Duration `yaml:"connection_timeout" required:"true" default:"10s"` // timeout for connections
HAKeepaliveInterval time.Duration `yaml:"ha_keepalive_interval" required:"true" default:"16s"` // interval for node status watcher
Statsd string `yaml:"statsd"` // statsd host and port
Profile string `yaml:"profile"` // profile ip:port
CertPath string `yaml:"cert_path"` // docker cert files path
MaxConcurrency int64 `yaml:"max_concurrency" default:"20"` // concurrently call single runtime in the same time
Store string `yaml:"store" default:"etcd"` // store type
SentryDSN string `yaml:"sentry_dsn"`

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

Git GitConfig `yaml:"git"`
Etcd EtcdConfig `yaml:"etcd"`
Redis RedisConfig `yaml:"redis"`
Docker DockerConfig `yaml:"docker"`
Scheduler SchedConfig `yaml:"scheduler"`
Virt VirtConfig `yaml:"virt"`
Systemd SystemdConfig `yaml:"systemd"`
SentryDSN string `yaml:"sentry_dsn"`
ResourcePluginsDir string `yaml:"resource_plugins_dir" default:"/etc/eru/plugins"` // resource plugins path
ResourcePluginsTimeout time.Duration `yaml:"resource_plugins_timeout" default:"30s"` // timeout for calling resource plugins

Auth AuthConfig `yaml:"auth"` // grpc auth
GRPCConfig GRPCConfig `yaml:"grpc"` // grpc config
Git GitConfig `yaml:"git"`
Etcd EtcdConfig `yaml:"etcd"`
Redis RedisConfig `yaml:"redis"`
Docker DockerConfig `yaml:"docker"`
Virt VirtConfig `yaml:"virt"`
Systemd SystemdConfig `yaml:"systemd"`
Scheduler SchedulerConfig `yaml:"scheduler"`
}

// Identifier returns the id of this config
// we consider the same storage as the same config
func (c Config) Identifier() string {
s := strings.Builder{}
_, _ = s.WriteString(c.Store)
for _, e := range c.Etcd.Machines {
_, _ = s.WriteString(e)
func (c Config) Identifier() (string, error) {
b, err := json.Marshal(c)
if err != nil {
return "", err
}
_, _ = s.WriteString(c.Etcd.Prefix)
_, _ = s.WriteString(c.Redis.Addr)
_, _ = s.WriteString(strconv.Itoa(c.Redis.DB))
h := sha1.New() // #nosec
_, _ = h.Write([]byte(s.String()))
return fmt.Sprintf("%x", h.Sum(nil))
h := sha256.New()
h.Write(b)
return fmt.Sprintf("%x", h.Sum(nil)), nil
}

// AuthConfig contains authorization information for connecting to a Registry
// Basically copied from https://github.com/moby/moby/blob/16a1736b9b93e44c898f95d670bbaf20a558103d/api/types/auth.go#L4
// But use yaml instead of json
// And we use it as grpc simple auth
type AuthConfig struct {
Username string `yaml:"username,omitempty" json:"username,omitempty"`
Password string `yaml:"password,omitempty" json:"password,omitempty"`
}

// GRPCConfig indicate grpc config
type GRPCConfig struct {
MaxConcurrentStreams int `yaml:"max_concurrent_streams,omitempty" json:"max_concurrent_streams,omitempty" required:"true" default:"100"`
MaxRecvMsgSize int `yaml:"max_recv_msg_size,omitempty" json:"max_recv_msg_size,omitempty" required:"true" default:"20971520"`
ServiceDiscoveryPushInterval time.Duration `yaml:"service_discovery_interval" required:"true" default:"15s"`
ServiceHeartbeatInterval time.Duration `yaml:"service_heartbeat_interval" required:"true" default:"15s"`
}

// GitConfig holds eru-core git config
type GitConfig struct {
SCMType string `yaml:"scm_type"` // source code manager type [gitlab/github]
PrivateKey string `yaml:"private_key"` // private key to clone code
Token string `yaml:"token"` // token to call SCM API
CloneTimeout time.Duration `yaml:"clone_timeout" default:"300s"` // clone timeout
}

// EtcdConfig holds eru-core etcd config
Expand All @@ -79,66 +99,42 @@ type EtcdConfig struct {
// LockPrefix is used for lock
type RedisConfig struct {
Addr string `yaml:"addr" default:"localhost:6379"` // redis address
DB int `yaml:"db" default:"0"` // redis db
LockPrefix string `yaml:"lock_prefix" default:"/lock"` // redis lock prefix
}

// GitConfig holds eru-core git config
type GitConfig struct {
SCMType string `yaml:"scm_type"` // source code manager type [gitlab/github]
PrivateKey string `yaml:"private_key"` // private key to clone code
Token string `yaml:"token"` // token to call SCM API
CloneTimeout time.Duration `yaml:"clone_timeout" required:"true" default:"300s"` // clone timeout
DB int `yaml:"db" default:"0"` // redis db
}

// DockerConfig holds eru-core docker config
type DockerConfig struct {
APIVersion string `yaml:"version" required:"true" default:"1.32"` // docker API version
NetworkMode string `yaml:"network_mode" required:"true" default:"host"` // docker network mode
Hub string `yaml:"hub"` // docker hub address
Namespace string `yaml:"namespace"` // docker hub prefix, will be set to $Hub/$HubPrefix/$appname
BuildPod string `yaml:"build_pod"` // podname used to build
UseLocalDNS bool `yaml:"local_dns"` // use node IP as dns
Log LogConfig `yaml:"log"` // docker log driver
AuthConfigs map[string]AuthConfig `yaml:"auths"` // docker registry credentials
APIVersion string `yaml:"version" required:"true" default:"1.32"` // docker API version
NetworkMode string `yaml:"network_mode" required:"true" default:"host"` // docker network mode
UseLocalDNS bool `yaml:"use_local_dns"` // use node IP as dns
Log LogConfig `yaml:"log"` // docker log driver

Hub string `yaml:"hub"` // docker hub address
Namespace string `yaml:"namespace"` // docker hub prefix, will be set to $Hub/$HubPrefix/$appname
BuildPod string `yaml:"build_pod"` // podname used to build
AuthConfigs map[string]AuthConfig `yaml:"auths"` // docker registry credentials
}

// VirtConfig holds yavirtd config
type VirtConfig struct {
APIVersion string `yaml:"version"` // Yavirtd API version
APIVersion string `yaml:"version" default:"v1"` // Yavirtd API version
}

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

// SchedulerConfig holds scheduler config
type SchedulerConfig struct {
MaxShare int `yaml:"maxshare" required:"true" default:"-1"` // comlpex scheduler use maxshare
ShareBase int `yaml:"sharebase" required:"true" default:"100"` // how many pieces for one core
MaxDeployCount int `yaml:"max_deploy_count" default:"10000"` // max deploy count of each node
}

// LogConfig define log type
type LogConfig struct {
Type string `yaml:"type" required:"true" default:"journald"` // Log type, can be "journald", "json-file", "none"
Config map[string]string `yaml:"config"` // Log configs
}

// SchedConfig holds scheduler config
type SchedConfig struct {
MaxShare int `yaml:"maxshare" required:"true" default:"-1"` // comlpex scheduler use maxshare
ShareBase int `yaml:"sharebase" required:"true" default:"100"` // how many pieces for one core
MaxDeployCount int `yaml:"max_deploy_count" required:"false" default:"10000"` // max deploy count of each node
}

// AuthConfig contains authorization information for connecting to a Registry
// Basically copied from https://github.com/moby/moby/blob/16a1736b9b93e44c898f95d670bbaf20a558103d/api/types/auth.go#L4
// But use yaml instead of json
// And we use it as grpc simple auth
type AuthConfig struct {
Username string `yaml:"username,omitempty" json:"username,omitempty"`
Password string `yaml:"password,omitempty" json:"password,omitempty"`
}

// GRPCConfig indicate grpc config
type GRPCConfig struct {
MaxConcurrentStreams int `yaml:"max_concurrent_streams,omitempty" json:"max_concurrent_streams,omitempty" required:"true" default:"100"`
MaxRecvMsgSize int `yaml:"max_recv_msg_size,omitempty" json:"max_recv_msg_size,omitempty" required:"true" default:"20971520"`
ServiceDiscoveryPushInterval time.Duration `yaml:"service_discovery_interval" required:"true" default:"15s"`
ServiceHeartbeatInterval time.Duration `yaml:"service_heartbeat_interval" required:"true" default:"15s"`
}
4 changes: 3 additions & 1 deletion types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ func TestIdentifier(t *testing.T) {
"2.2.2.2",
},
}
assert.NotEmpty(t, config.Identifier())
r, err := config.Identifier()
assert.NoError(t, err)
assert.NotEmpty(t, r)
}

0 comments on commit 0d93575

Please sign in to comment.