Skip to content

Commit

Permalink
feat: use environments
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliang committed Jun 3, 2021
1 parent 3f34da4 commit faff41b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 98 deletions.
4 changes: 2 additions & 2 deletions examples/hello/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ plans:
parallel: 100
interval: 1

metadata:
org: lilithgame
environments:
branch: master
14 changes: 10 additions & 4 deletions pkg/agent/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type Config struct {
Plans []*transfer.Plan
Metadata map[string]string
Environments map[string]string
}

func (c *Config) MarshalBinary() (data []byte, err error) {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (b *Behavior) BuildEngineFromConfig(conf []byte) *Engine {
log.Panic("unmarshal plan config", zap.Error(err))
}
engine := &Engine{Behavior: b}
engine.metadata = cfg.Metadata
engine.metadata = cfg.Environments
for _, plan := range cfg.Plans {
if _, ok := b.trees[plan.TreeName]; !ok {
log.Panic("plan name not found")
Expand Down Expand Up @@ -126,6 +126,12 @@ func (e *Engine) setPlans(plans []*transfer.Plan) {
e.plans = plans
}

func (e *Engine) setMetadata(metadata map[string]string) {
e.metadata = metadata
func (e *Engine) setMetadata(envs map[string]string) {
if len(e.metadata) == 0 {
e.metadata = envs
return
}
for name, value := range envs {
e.metadata[name] = value
}
}
11 changes: 4 additions & 7 deletions pkg/agent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ func (m *manager) reviewMail(mail *transfer.Mail) error {
}

func (m *manager) startAgentEngine(content []byte) error {
var conf Config
err := json.Unmarshal(content, &conf)
var envs map[string]string
err := json.Unmarshal(content, &envs)
if err != nil {
return err
}
if conf.Plans != nil {
m.engine.setPlans(conf.Plans)
}
if len(conf.Metadata) != 0 {
m.engine.setMetadata(conf.Metadata)
if len(envs) != 0 {
m.engine.setMetadata(envs)
}
m.startReadyService()
return nil
Expand Down
176 changes: 92 additions & 84 deletions pkg/transfer/transfer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/transfer/transfer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ message Plan {
message Event {
string image = 1;
int32 agentNum = 2;
bytes rawCfg = 3;
map<string, string> environments = 3;
}

message EventReply {
Expand Down

0 comments on commit faff41b

Please sign in to comment.