Skip to content

Commit 4ab94c3

Browse files
committed
meta
1 parent 912e9f1 commit 4ab94c3

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

cluster/calcium/create.go

+28-14
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,18 @@ func (c *Calcium) doDeployOneWorkload(
323323
}
324324
}
325325

326-
// start first
326+
// avoid be interrupted by MakeDeployStatus
327+
processing := opts.GetProcessing(node.Name)
328+
if !decrProcessing {
329+
processing = nil
330+
}
331+
// add workload metadata first
332+
if err := c.store.AddWorkload(ctx, workload, processing); err != nil {
333+
return errors.WithStack(err)
334+
}
335+
log.Infof(ctx, "[doDeployOneWorkload] workload metadata created: %s", workload.ID)
336+
337+
// start workload
327338
msg.Hook, err = c.doStartWorkload(ctx, workload, opts.IgnoreHook)
328339
if err != nil {
329340
return err
@@ -340,22 +351,20 @@ func (c *Calcium) doDeployOneWorkload(
340351
if workloadInfo.Networks != nil {
341352
msg.Publish = utils.MakePublishInfo(workloadInfo.Networks, opts.Entrypoint.Publish)
342353
}
343-
// reset users
344-
if workloadInfo.User != workload.User {
354+
355+
// if workload metadata changed, then update
356+
if workloadInfo.User != workload.User || workload.Hook != opts.Entrypoint.Hook {
357+
// reset users
345358
workload.User = workloadInfo.User
346-
}
347-
// reset workload.hook
348-
workload.Hook = opts.Entrypoint.Hook
359+
// reset workload.hook
360+
workload.Hook = opts.Entrypoint.Hook
349361

350-
// avoid be interrupted by MakeDeployStatus
351-
processing := opts.GetProcessing(node.Name)
352-
if !decrProcessing {
353-
processing = nil
354-
}
355-
if err := c.store.AddWorkload(ctx, workload, processing); err != nil {
356-
return errors.WithStack(err)
362+
if err := c.store.UpdateWorkload(ctx, workload); err != nil {
363+
return errors.WithStack(err)
364+
}
357365
}
358-
log.Infof(ctx, "[doDeployOneWorkload] workload created and saved: %s", workload.ID)
366+
367+
log.Infof(ctx, "[doDeployOneWorkload] workload updated: %s", workload.ID)
359368
msg.WorkloadID = workload.ID
360369
msg.WorkloadName = workload.Name
361370
msg.Podname = workload.Podname
@@ -368,6 +377,11 @@ func (c *Calcium) doDeployOneWorkload(
368377
if workload.ID == "" {
369378
return nil
370379
}
380+
381+
if err := c.store.RemoveWorkload(ctx, workload); err != nil {
382+
log.Errorf(ctx, "[doDeployOneWorkload] failed to remove workload %s")
383+
}
384+
371385
return workload.Remove(ctx, true)
372386
},
373387
c.config.GlobalTimeout,

rpc/rpc.go

+1
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ func (v *Vibranium) CreateWorkload(opts *pb.DeployOptions, stream pb.CoreRPC_Cre
615615
return grpcstatus.Error(CreateWorkload, err.Error())
616616
}
617617
for m := range ch {
618+
log.Debugf(ctx, "create workload message: %v", m)
618619
if err = stream.Send(toRPCCreateWorkloadMessage(m)); err != nil {
619620
v.logUnsentMessages(ctx, "CreateWorkload", err, m)
620621
}

store/etcdv3/meta/etcd.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (e *ETCD) bindStatusWithTTL(ctx context.Context, entityKey, statusKey, stat
277277
// There isn't the entity kv pair.
278278
if !entityTxn.Succeeded {
279279
e.revokeLease(ctx, leaseID)
280-
return nil
280+
return types.ErrEntityNotExists
281281
}
282282

283283
// There isn't a status bound to the entity.
@@ -311,10 +311,10 @@ func (e *ETCD) bindStatusWithoutTTL(ctx context.Context, statusKey, statusValue
311311
updateStatus := []clientv3.Op{clientv3.OpPut(statusKey, statusValue)}
312312
_, err := e.cliv3.Txn(ctx).
313313
If(clientv3.Compare(clientv3.Version(statusKey), "!=", 0)). // if there's an existing status key
314-
Then(clientv3.OpTxn( // deal with existing status key
314+
Then(clientv3.OpTxn( // deal with existing status key
315315
[]clientv3.Cmp{clientv3.Compare(clientv3.Value(statusKey), "!=", statusValue)}, // if the new value != the old value
316-
updateStatus, // then the status has been changed.
317-
[]clientv3.Op{}, // otherwise do nothing.
316+
updateStatus, // then the status has been changed.
317+
[]clientv3.Op{}, // otherwise do nothing.
318318
)).
319319
Else(updateStatus...). // otherwise deal with non-existing status key
320320
Commit()

types/errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var (
8585

8686
ErrNodeNotExists = errors.New("node not exists")
8787
ErrWorkloadNotExists = errors.New("workload not exists")
88+
ErrEntityNotExists = errors.New("entity not exists")
8889

8990
ErrUnregisteredWALEventType = errors.New("unregistered WAL event type")
9091
ErrInvalidWALBucket = errors.New("invalid WAL bucket")

0 commit comments

Comments
 (0)