Skip to content

Commit 1ee5e6f

Browse files
jschwinger233CMGS
authored andcommitted
add ERU_CPU env to containers for their perception
1 parent 2825832 commit 1ee5e6f

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

cluster/calcium/create.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package calcium
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"sync"
78
"time"
@@ -202,8 +203,8 @@ func (c *Calcium) doDeployWorkloadsOnNode(ctx context.Context, ch chan *types.Cr
202203
// remap 就不搞进事务了吧, 回滚代价太大了
203204
// 放任 remap 失败的后果是, share pool 没有更新, 这个后果姑且认为是可以承受的
204205
// 而且 remap 是一个幂等操作, 就算这次 remap 失败, 下次 remap 也能收敛到正确到状态
205-
if err := c.withNodeLocked(ctx, nodename, func(ctx context.Context, node *types.Node) error {
206-
c.doRemapResourceAndLog(ctx, logger, node)
206+
if err := c.withNodeLocked(context.Background(), nodename, func(ctx context.Context, node *types.Node) error {
207+
c.doRemapResourceAndLog(context.Background(), logger, node)
207208
return nil
208209
}); err != nil {
209210
logger.Errorf("failed to lock node to remap: %v", err)
@@ -408,6 +409,10 @@ func (c *Calcium) doMakeWorkloadOptions(no int, msg *types.CreateWorkloadMessage
408409
env = append(env, fmt.Sprintf("ERU_WORKLOAD_SEQ=%d", no))
409410
env = append(env, fmt.Sprintf("ERU_MEMORY=%d", msg.MemoryLimit))
410411
env = append(env, fmt.Sprintf("ERU_STORAGE=%d", msg.StorageLimit))
412+
if msg.CPU != nil {
413+
bs, _ := json.Marshal(msg.CPU)
414+
env = append(env, fmt.Sprintf("ERU_CPU=%s", bs))
415+
}
411416
config.Env = env
412417
// basic labels, bind to LabelMeta
413418
config.Labels = map[string]string{

cluster/calcium/dissociate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (c *Calcium) DissociateWorkload(ctx context.Context, ids []string) (chan *t
5757
}
5858
ch <- msg
5959
}
60-
c.doRemapResourceAndLog(ctx, logger, node)
60+
c.doRemapResourceAndLog(context.Background(), logger, node)
6161
return nil
6262
}); err != nil {
6363
logger.WithField("nodename", nodename).Errorf("failed to lock node: %+v", err)

cluster/calcium/realloc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, workload
101101
return
102102
}
103103

104-
c.doRemapResourceAndLog(ctx, log.WithField("Calcium", "doReallocOnNode"), node)
104+
c.doRemapResourceAndLog(context.Background(), log.WithField("Calcium", "doReallocOnNode"), node)
105105
return nil
106106
})
107107
}

cluster/calcium/remove.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (c *Calcium) RemoveWorkload(ctx context.Context, ids []string, force bool,
6666
}
6767
ch <- ret
6868
}
69-
c.doRemapResourceAndLog(ctx, logger, node)
69+
c.doRemapResourceAndLog(context.Background(), logger, node)
7070
return nil
7171
}); err != nil {
7272
logger.WithField("nodename", nodename).Errorf("failed to lock node: %+v", err)

cluster/calcium/replace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (c *Calcium) doReplaceWorkload(
199199
}
200200

201201
if err := c.withNodeLocked(ctx, node.Name, func(ctx context.Context, node *types.Node) error {
202-
c.doRemapResourceAndLog(ctx, log.WithField("Calcium", "doReplaceWorkload"), node)
202+
c.doRemapResourceAndLog(context.Background(), log.WithField("Calcium", "doReplaceWorkload"), node)
203203
return nil
204204
}); err != nil {
205205
log.Errorf("[replaceAndRemove] failed to lock node to remap: %v", err)

0 commit comments

Comments
 (0)