-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support setting tls configs in "SetNode" #526
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ 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" | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ import ( | |
"path/filepath" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
"go.etcd.io/etcd/api/v3/mvccpb" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
|
||
"github.com/projecteru2/core/engine" | ||
enginefactory "github.com/projecteru2/core/engine/factory" | ||
|
@@ -15,10 +20,6 @@ import ( | |
"github.com/projecteru2/core/store" | ||
"github.com/projecteru2/core/types" | ||
"github.com/projecteru2/core/utils" | ||
|
||
"github.com/pkg/errors" | ||
"go.etcd.io/etcd/api/v3/mvccpb" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
// AddNode save it to etcd | ||
|
@@ -145,6 +146,11 @@ func (m *Mercury) GetNodesByPod(ctx context.Context, podname string, labels map[ | |
// UpdateNodes . | ||
func (m *Mercury) UpdateNodes(ctx context.Context, nodes ...*types.Node) error { | ||
data := map[string]string{} | ||
addIfNotEmpty := func(key, value string) { | ||
if value != "" { | ||
data[key] = value | ||
} | ||
} | ||
for _, node := range nodes { | ||
bytes, err := json.Marshal(node) | ||
if err != nil { | ||
|
@@ -153,6 +159,10 @@ func (m *Mercury) UpdateNodes(ctx context.Context, nodes ...*types.Node) error { | |
d := string(bytes) | ||
data[fmt.Sprintf(nodeInfoKey, node.Name)] = d | ||
data[fmt.Sprintf(nodePodKey, node.Podname, node.Name)] = d | ||
addIfNotEmpty(fmt.Sprintf(nodeCaKey, node.Name), node.Ca) | ||
addIfNotEmpty(fmt.Sprintf(nodeCertKey, node.Name), node.Cert) | ||
addIfNotEmpty(fmt.Sprintf(nodeKeyKey, node.Name), node.Key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 所以怎么删掉 ca? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没法通过api删掉,但是可以去etcd里手动把那三个key给删了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 虽然我觉得不太好 但是也没想到好办法... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 硬要想办法的话,可以在proto里设置一个"message String",区分nil和""和含义...就是很麻烦和繁琐,看着也不好看 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 要不把 delta 用起来? node set options 里有个 delta 参数, 默认是 false, 规定只有 true 的时候才改变 ca. 这正好符合使用场景, 因为改变 ca 的时候就是需要 cli node set --delta 才能保持资源不变. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
感觉还是有点奇怪,比如原本这个node是有tls相关的这些东西的,然后cli node set --delta --memory 1G xxx-node,那这个时候要不要把ca置为空? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 还是保持现状吧.. |
||
enginefactory.RemoveEngineFromCache(node.Endpoint, node.Ca, node.Cert, node.Key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里提供一个可以清除engine缓存的入口,调用eru-cli node set可以清除对应node的engine缓存。 但是要保证ca / cert / key都跟之前的一致,才能清除掉缓存。例如对于开启了TLS的node,如果只是调用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这些很细节的地方需要好好文档记录 过一个月可能自己都忘了怎么清除缓存.. |
||
} | ||
|
||
resp, err := m.BatchUpdate(ctx, data) | ||
|
@@ -180,13 +190,19 @@ func (m *Mercury) UpdateNodeResource(ctx context.Context, node *types.Node, reso | |
} | ||
|
||
func (m *Mercury) makeClient(ctx context.Context, node *types.Node) (client engine.API, err error) { | ||
// try to get from cache without ca/cert/key | ||
if client = enginefactory.GetEngineFromCache(ctx, m.config, node.Endpoint, "", "", ""); client != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在不知道有没有配置TLS的情况下,先拿空的去试一试,这样可以减轻ETCD的压力。即使配置了TLS,缓存里查不到也不会有网络IO,性能应该还行。 |
||
return client, nil | ||
} | ||
|
||
keyFormats := []string{nodeCaKey, nodeCertKey, nodeKeyKey} | ||
data := []string{"", "", ""} | ||
for i := 0; i < 3; i++ { | ||
ev, err := m.GetOne(ctx, fmt.Sprintf(keyFormats[i], node.Name)) | ||
if err != nil { | ||
if !errors.Is(err, types.ErrBadCount) { | ||
log.Warnf(ctx, "[makeClient] Get key failed %v", err) | ||
return nil, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 拿不到就不应该继续了,否则用不正确的tls config去连接,可能会出奇怪问题。
This comment was marked as resolved.
Sorry, something went wrong. |
||
} | ||
continue | ||
} | ||
|
@@ -282,13 +298,21 @@ func (m *Mercury) doGetNodes(ctx context.Context, kvs []*mvccpb.KeyValue, labels | |
return nil, err | ||
} | ||
node.Init() | ||
if (!node.IsDown() || all) && utils.FilterWorkload(node.Labels, labels) { | ||
if node.Engine, err = m.makeClient(ctx, node); err != nil { | ||
return | ||
nodes = append(nodes, node) | ||
} | ||
wg := &sync.WaitGroup{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 因为后面GetEngine每次都要调用Info来validate一下,这里还是并发请求比较好。 |
||
wg.Add(len(nodes)) | ||
for _, node := range nodes { | ||
go func(node *types.Node) { | ||
defer wg.Done() | ||
if (!node.IsDown() || all) && utils.FilterWorkload(node.Labels, labels) { | ||
if node.Engine, err = m.makeClient(ctx, node); err != nil { | ||
return | ||
} | ||
} | ||
nodes = append(nodes, node) | ||
} | ||
}(node) | ||
} | ||
wg.Wait() | ||
return nodes, nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,16 @@ 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 | ||
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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加了一个配置项,“小timeout” There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 做咩的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 | ||
|
||
Auth AuthConfig `yaml:"auth"` // grpc auth | ||
GRPCConfig GRPCConfig `yaml:"grpc"` // grpc config | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里和L86都是为了真正检查这个engine的可用性,可以一定程度上防止之前http请求连接到https的问题。