Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 11949e0

Browse files
committed
agent: publish unit state regardless of hash
When starting up, the Agent may already have some Jobs loaded. In this case, the UnitStatePublisher will not have a cached hash for the corresponding Unit. The UnitStatePublisher must publish state regardless of the UnitHash being absent.
1 parent d555d28 commit 11949e0

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

agent/unit_state.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ func (p *UnitStatePublisher) publishOne(name string, us *unit.UnitState) {
8989
// Sanity check - don't want to publish incomplete UnitStates
9090
// TODO(jonboulle): consider teasing apart a separate UnitState-like struct
9191
// so we can rely on a UnitState always being fully hydrated?
92-
if len(us.UnitHash) == 0 {
93-
log.Errorf("Refusing to push UnitState(%s), no UnitHash: %#v", name, us)
94-
} else if len(us.MachineID) == 0 {
92+
93+
// See https://github.com/coreos/fleet/issues/720
94+
//if len(us.UnitHash) == 0 {
95+
// log.Errorf("Refusing to push UnitState(%s), no UnitHash: %#v", name, us)
96+
97+
if len(us.MachineID) == 0 {
9598
log.Errorf("Refusing to push UnitState(%s), no MachineID: %#v", name, us)
9699
} else {
97100
log.V(1).Infof("Pushing UnitState(%s) to Registry: %#v", name, us)

registry/unit_state.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,22 @@ func unitStateToModel(us *unit.UnitState) *unitStateModel {
148148
return nil
149149
}
150150

151+
// Refuse to create a UnitState without a Hash
152+
// See https://github.com/coreos/fleet/issues/720
153+
//if len(us.UnitHash) == 0 {
154+
// return nil
155+
//}
156+
151157
usm := unitStateModel{
152158
LoadState: us.LoadState,
153159
ActiveState: us.ActiveState,
154160
SubState: us.SubState,
161+
UnitHash: us.UnitHash,
155162
}
156163

157164
if us.MachineID != "" {
158165
usm.MachineState = &machine.MachineState{ID: us.MachineID}
159166
}
160167

161-
// Refuse to create a UnitState without a Hash
162-
if len(us.UnitHash) == 0 {
163-
return nil
164-
}
165-
usm.UnitHash = us.UnitHash
166-
167168
return &usm
168169
}

registry/unit_state_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ func TestSaveUnitState(t *testing.T) {
6161
mID := "mymachine"
6262
us := unit.NewUnitState("abc", "def", "ghi", mID)
6363

64-
// saving unit state with no hash should fail (nil action)
65-
r.SaveUnitState(j, us)
66-
if len(e.sets) != 0 || e.deletes != nil {
67-
t.Fatalf("SaveUnitState on UnitState with no hash acted unexpectedly!")
68-
t.Logf("sets: %#v", e.sets)
69-
t.Logf("deletes: %#v", e.deletes)
70-
}
64+
// Saving unit state with no hash should succeed for now, but should fail
65+
// in the future. See https://github.com/coreos/fleet/issues/720.
66+
//r.SaveUnitState(j, us)
67+
//if len(e.sets) != 1 || e.deletes == nil {
68+
// t.Logf("sets: %#v", e.sets)
69+
// t.Logf("deletes: %#v", e.deletes)
70+
// t.Fatalf("SaveUnitState on UnitState with no hash acted unexpectedly!")
71+
//}
7172

7273
us.UnitHash = "quickbrownfox"
7374
r.SaveUnitState(j, us)
@@ -139,9 +140,10 @@ func TestUnitStateToModel(t *testing.T) {
139140
want: nil,
140141
},
141142
{
142-
// No unit states without hashes
143+
// Unit state with no hash and no machineID is OK
144+
// See https://github.com/coreos/fleet/issues/720
143145
in: &unit.UnitState{"foo", "bar", "baz", "", ""},
144-
want: nil,
146+
want: &unitStateModel{"foo", "bar", "baz", nil, ""},
145147
},
146148
{
147149
// Unit state with hash but no machineID is OK

0 commit comments

Comments
 (0)