@@ -11,6 +11,7 @@ import (
11
11
"github.com/projecteru2/core/utils"
12
12
)
13
13
14
+ // ReallocResource updates workload resource dynamically
14
15
func (c * Calcium ) ReallocResource (ctx context.Context , opts * types.ReallocOptions ) (err error ) {
15
16
return c .withContainerLocked (ctx , opts .ID , func (container * types.Container ) error {
16
17
rrs , err := resources .MakeRequests (
@@ -41,11 +42,10 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
41
42
if err != nil {
42
43
return errors .WithStack (err )
43
44
}
44
- if total != 1 {
45
+ if total < 1 {
45
46
return errors .WithStack (types .ErrInsufficientRes )
46
47
}
47
48
48
- originalContainer := * container
49
49
return utils .Txn (
50
50
ctx ,
51
51
@@ -60,17 +60,8 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
60
60
}
61
61
return c .store .UpdateNodes (ctx , node )
62
62
},
63
- // rollback to origin
64
- func (ctx context.Context , failureByCond bool ) error {
65
- if failureByCond {
66
- return nil
67
- }
68
- for _ , plan := range plans {
69
- plan .RollbackChangesOnNode (node , 1 )
70
- }
71
- node .PreserveResources (& originalContainer .ResourceMeta )
72
- return c .store .UpdateNodes (ctx , node )
73
- },
63
+ // no need rollback
64
+ nil ,
74
65
75
66
c .config .GlobalTimeout ,
76
67
)
@@ -80,12 +71,9 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
80
71
func (c * Calcium ) doReallocContainersOnInstance (ctx context.Context , node * types.Node , plans []resourcetypes.ResourcePlans , container * types.Container ) (err error ) {
81
72
r := & types.ResourceMeta {}
82
73
for _ , plan := range plans {
83
- // TODO@zc: single existing instance
84
- // TODO@zc: no HardVolumeBindings
85
74
if r , err = plan .Dispense (resourcetypes.DispenseOptions {
86
- Node : node ,
87
- Index : 1 ,
88
- ExistingInstances : []* types.Container {container },
75
+ Node : node ,
76
+ ExistingInstance : container ,
89
77
}, r ); err != nil {
90
78
return
91
79
}
@@ -131,7 +119,17 @@ func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types
131
119
if failureByCond {
132
120
return nil
133
121
}
134
- return errors .WithStack (c .store .UpdateContainer (ctx , & originalContainer ))
122
+ r := & enginetypes.VirtualizationResource {
123
+ CPU : originalContainer .CPU ,
124
+ Quota : originalContainer .CPUQuotaLimit ,
125
+ NUMANode : originalContainer .NUMANode ,
126
+ Memory : originalContainer .MemoryLimit ,
127
+ Volumes : originalContainer .VolumeLimit .ToStringSlice (false , false ),
128
+ VolumePlan : originalContainer .VolumePlanLimit .ToLiteral (),
129
+ VolumeChanged : r .VolumeChanged ,
130
+ Storage : originalContainer .StorageLimit ,
131
+ }
132
+ return errors .WithStack (node .Engine .VirtualizationUpdateResource (ctx , container .ID , r ))
135
133
},
136
134
137
135
c .config .GlobalTimeout ,
0 commit comments