Skip to content

Commit

Permalink
simplify volume dispense: compatible computing
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 committed Nov 10, 2020
1 parent b6288f4 commit 9c4e50e
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 325 deletions.
2 changes: 1 addition & 1 deletion cluster/calcium/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio
for nodename, rollbackIndices := range rollbackMap {
if e := c.withNodeLocked(ctx, nodename, func(node *types.Node) error {
for _, plan := range plans {
plan.RollbackChangesOnNode(node, rollbackIndices...)
plan.RollbackChangesOnNode(node, rollbackIndices...) // nolint:scopelint
}
return errors.WithStack(c.store.UpdateNodes(ctx, node))
}); e != nil {
Expand Down
35 changes: 16 additions & 19 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
if err != nil {
return errors.WithStack(err)
}
if total != 1 {
if total < 1 {
return errors.WithStack(types.ErrInsufficientRes)
}

originalContainer := *container
return utils.Txn(
ctx,

Expand All @@ -60,17 +59,8 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
}
return c.store.UpdateNodes(ctx, node)
},
// rollback to origin
func(ctx context.Context, failureByCond bool) error {
if failureByCond {
return nil
}
for _, plan := range plans {
plan.RollbackChangesOnNode(node, 1)
}
node.PreserveResources(&originalContainer.ResourceMeta)
return c.store.UpdateNodes(ctx, node)
},
// no need rollback
nil,

c.config.GlobalTimeout,
)
Expand All @@ -80,12 +70,9 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types.Node, plans []resourcetypes.ResourcePlans, container *types.Container) (err error) {
r := &types.ResourceMeta{}
for _, plan := range plans {
// TODO@zc: single existing instance
// TODO@zc: no HardVolumeBindings
if r, err = plan.Dispense(resourcetypes.DispenseOptions{
Node: node,
Index: 1,
ExistingInstances: []*types.Container{container},
Node: node,
ExistingInstance: container,
}, r); err != nil {
return
}
Expand Down Expand Up @@ -131,7 +118,17 @@ func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types
if failureByCond {
return nil
}
return errors.WithStack(c.store.UpdateContainer(ctx, &originalContainer))
r := &enginetypes.VirtualizationResource{
CPU: originalContainer.CPU,
Quota: originalContainer.CPUQuotaLimit,
NUMANode: originalContainer.NUMANode,
Memory: originalContainer.MemoryLimit,
Volumes: originalContainer.VolumeLimit.ToStringSlice(false, false),
VolumePlan: originalContainer.VolumePlanLimit.ToLiteral(),
VolumeChanged: r.VolumeChanged,
Storage: originalContainer.StorageLimit,
}
return errors.WithStack(node.Engine.VirtualizationUpdateResource(ctx, container.ID, r))
},

c.config.GlobalTimeout,
Expand Down
Loading

0 comments on commit 9c4e50e

Please sign in to comment.