Skip to content

Commit

Permalink
set CertPath to global config
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Dec 5, 2019
1 parent de81703 commit 4d3f822
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ statsd: "127.0.0.1:8125"
profile: ":12346"
global_timeout: 300s
lock_timeout: 30s
cert_path: "/etc/eru/tls"

auth:
username: admin
Expand Down Expand Up @@ -37,7 +38,6 @@ docker:
config:
"max-size": "10m"
network_mode: "bridge"
cert_path: "/etc/eru/tls"
hub: "hub.docker.com"
namespace: "projecteru2"
build_pod: "eru-test"
Expand Down
8 changes: 4 additions & 4 deletions engine/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ type Engine struct {
// MakeClient make docker cli
func MakeClient(ctx context.Context, config coretypes.Config, nodename, endpoint, ca, cert, key string) (engine.API, error) {
var client *http.Client
if config.Docker.CertPath != "" && ca != "" && cert != "" && key != "" {
caFile, err := ioutil.TempFile(config.Docker.CertPath, fmt.Sprintf("ca-%s", nodename))
if config.CertPath != "" && ca != "" && cert != "" && key != "" {
caFile, err := ioutil.TempFile(config.CertPath, fmt.Sprintf("ca-%s", nodename))
if err != nil {
return nil, err
}
certFile, err := ioutil.TempFile(config.Docker.CertPath, fmt.Sprintf("cert-%s", nodename))
certFile, err := ioutil.TempFile(config.CertPath, fmt.Sprintf("cert-%s", nodename))
if err != nil {
return nil, err
}
keyFile, err := ioutil.TempFile(config.Docker.CertPath, fmt.Sprintf("key-%s", nodename))
keyFile, err := ioutil.TempFile(config.CertPath, fmt.Sprintf("key-%s", nodename))
if err != nil {
return nil, err
}
Expand Down
16 changes: 7 additions & 9 deletions store/etcdv3/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"strconv"

engineInterface "github.com/projecteru2/core/engine"
"github.com/projecteru2/core/engine"
"github.com/projecteru2/core/store"

"github.com/coreos/etcd/clientv3"
Expand Down Expand Up @@ -35,13 +35,13 @@ func (m *Mercury) AddNode(ctx context.Context, name, endpoint, podname, ca, cert

// 尝试加载的客户端
// 会自动判断是否是支持的 url
engine, err := enginefactory.GetEngine(ctx, m.config, name, endpoint, ca, cert, key)
client, err := enginefactory.GetEngine(ctx, m.config, name, endpoint, ca, cert, key)
if err != nil {
return nil, err
}

// 判断这货是不是活着的
info, err := engine.Info(ctx)
info, err := client.Info(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -209,21 +209,19 @@ func (m *Mercury) UpdateNodeResource(ctx context.Context, node *types.Node, cpu
return m.UpdateNode(ctx, node)
}

func (m *Mercury) makeClient(ctx context.Context, podname, nodename, endpoint string, force bool) (engineInterface.API, error) {
func (m *Mercury) makeClient(ctx context.Context, podname, nodename, endpoint string, force bool) (engine.API, error) {
// try get client, if nil, create a new one
var client engineInterface.API
var client engine.API
var err error
client = _cache.Get(nodename)
if client == nil || force {
var ca, cert, key string
if m.config.Docker.CertPath != "" {
if m.config.CertPath != "" {
keyFormats := []string{nodeCaKey, nodeCertKey, nodeKeyKey}
data := []string{"", "", ""}
for i := 0; i < 3; i++ {
ev, err := m.GetOne(ctx, fmt.Sprintf(keyFormats[i], nodename))
if err != nil {
if ev, err := m.GetOne(ctx, fmt.Sprintf(keyFormats[i], nodename)); err != nil {
log.Warnf("[makeClient] Get key failed %v", err)
data[i] = ""
} else {
data[i] = string(ev.Value)
}
Expand Down
2 changes: 1 addition & 1 deletion store/etcdv3/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ RdCPRPt513WozkJZZAjUSP2U
-----END PRIVATE KEY-----`
nodename3 := "nodename3"
endpoint3 := "tcp://path"
m.config.Docker.CertPath = "/tmp"
m.config.CertPath = "/tmp"
node3, err := m.doAddNode(ctx, nodename3, endpoint3, podname, ca, cert, certkey, cpu, share, memory, storage, labels, nil, nil)
assert.NoError(t, err)
engine3, err := m.makeClient(ctx, podname, nodename3, endpoint3, true)
Expand Down
2 changes: 1 addition & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {
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
Auth AuthConfig `yaml:"auth"` // grpc auth
GRPCConfig GRPCConfig `yaml:"grpc"` // grpc config

Expand Down Expand Up @@ -45,7 +46,6 @@ type GitConfig struct {
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
CertPath string `yaml:"cert_path" required:"true" default:"/tmp"` // docker cert files path
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
Expand Down

0 comments on commit 4d3f822

Please sign in to comment.