Skip to content

Commit

Permalink
Merge pull request #130 from cybozu-go/fix-ignition-conflicts
Browse files Browse the repository at this point in the history
Fix ignition conflict
  • Loading branch information
morimoto-cybozu authored Dec 25, 2018
2 parents 9305721 + 2ac0a95 commit 3269d15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions models/etcd/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func (d *driver) PutTemplate(ctx context.Context, role, id string, template stri
if metadata == nil {
return errors.New("metadata should not be nil")
}
RETRY:
now := time.Now()
target := path.Join(KeyIgnitionsTemplate, role, id)
meta := path.Join(KeyIgnitionsMetadata, role, id)
metaJSON, err := json.Marshal(metadata)
Expand All @@ -41,10 +39,10 @@ RETRY:

if !tresp.Succeeded {
time.Sleep(1 * time.Nanosecond)
goto RETRY
return sabakan.ErrConflicted
}

d.addLog(ctx, now, tresp.Header.Revision, sabakan.AuditIgnition, role, "put",
d.addLog(ctx, time.Now(), tresp.Header.Revision, sabakan.AuditIgnition, role, "put",
fmt.Sprintf("id=%s\n%s", id, template))

tmplPrefix := path.Join(KeyIgnitionsTemplate, role) + "/"
Expand Down
4 changes: 4 additions & 0 deletions models/etcd/ignition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func testTemplate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = d.PutTemplate(context.Background(), "cs", id, "data", map[string]string{})
if err != sabakan.ErrConflicted {
t.Fatal(err)
}

ign, err := d.GetTemplate(context.Background(), "cs", id)
if err != nil {
Expand Down

0 comments on commit 3269d15

Please sign in to comment.