Skip to content

Commit 288923d

Browse files
committed
simplify volume dispense: compatible computing
1 parent b6288f4 commit 288923d

File tree

8 files changed

+155
-325
lines changed

8 files changed

+155
-325
lines changed

cluster/calcium/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio
101101
for nodename, rollbackIndices := range rollbackMap {
102102
if e := c.withNodeLocked(ctx, nodename, func(node *types.Node) error {
103103
for _, plan := range plans {
104-
plan.RollbackChangesOnNode(node, rollbackIndices...)
104+
plan.RollbackChangesOnNode(node, rollbackIndices...) // nolint:scopelint
105105
}
106106
return errors.WithStack(c.store.UpdateNodes(ctx, node))
107107
}); e != nil {

cluster/calcium/realloc.go

+17-19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/projecteru2/core/utils"
1212
)
1313

14+
// ReallocResource updates workload resource dynamically
1415
func (c *Calcium) ReallocResource(ctx context.Context, opts *types.ReallocOptions) (err error) {
1516
return c.withContainerLocked(ctx, opts.ID, func(container *types.Container) error {
1617
rrs, err := resources.MakeRequests(
@@ -41,11 +42,10 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
4142
if err != nil {
4243
return errors.WithStack(err)
4344
}
44-
if total != 1 {
45+
if total < 1 {
4546
return errors.WithStack(types.ErrInsufficientRes)
4647
}
4748

48-
originalContainer := *container
4949
return utils.Txn(
5050
ctx,
5151

@@ -60,17 +60,8 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
6060
}
6161
return c.store.UpdateNodes(ctx, node)
6262
},
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,
7465

7566
c.config.GlobalTimeout,
7667
)
@@ -80,12 +71,9 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
8071
func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types.Node, plans []resourcetypes.ResourcePlans, container *types.Container) (err error) {
8172
r := &types.ResourceMeta{}
8273
for _, plan := range plans {
83-
// TODO@zc: single existing instance
84-
// TODO@zc: no HardVolumeBindings
8574
if r, err = plan.Dispense(resourcetypes.DispenseOptions{
86-
Node: node,
87-
Index: 1,
88-
ExistingInstances: []*types.Container{container},
75+
Node: node,
76+
ExistingInstance: container,
8977
}, r); err != nil {
9078
return
9179
}
@@ -131,7 +119,17 @@ func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types
131119
if failureByCond {
132120
return nil
133121
}
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))
135133
},
136134

137135
c.config.GlobalTimeout,

0 commit comments

Comments
 (0)