Skip to content

Commit b04c9ef

Browse files
committed
fix another regression
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent d6ed77b commit b04c9ef

2 files changed

Lines changed: 46 additions & 18 deletions

File tree

pkg/compose/reconcile.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ func reconcileNetworks(project *types.Project, observed *ObservedState, plan *Re
448448
n := net
449449
existing, found := observed.Networks[key]
450450
if !found {
451+
eventName := "Network " + n.Name
452+
emitCreatingID := fmt.Sprintf("emit-creating-network:%s", n.Name)
453+
plan.Operations[emitCreatingID] = emitEventOp(emitCreatingID, "", n.Name, eventName, api.Working, api.StatusCreating, nil)
454+
451455
id := fmt.Sprintf("create-network:%s", n.Name)
452456
plan.Operations[id] = &Operation{
453457
ID: id,
@@ -457,8 +461,12 @@ func reconcileNetworks(project *types.Project, observed *ObservedState, plan *Re
457461
NetworkKey: key,
458462
Desired: &n,
459463
},
460-
Reason: "network does not exist",
464+
DependsOn: []string{emitCreatingID},
465+
Reason: "network does not exist",
461466
}
467+
468+
emitCreatedID := fmt.Sprintf("emit-created-network:%s", n.Name)
469+
plan.Operations[emitCreatedID] = emitEventOp(emitCreatedID, "", n.Name, eventName, api.Done, api.StatusCreated, []string{id})
462470
continue
463471
}
464472
desiredHash, err := NetworkHash(&n)
@@ -647,6 +655,10 @@ func reconcileVolumes(project *types.Project, observed *ObservedState, plan *Rec
647655
v := vol
648656
existing, found := observed.Volumes[key]
649657
if !found {
658+
eventName := "Volume " + v.Name
659+
emitCreatingID := fmt.Sprintf("emit-creating-volume:%s", v.Name)
660+
plan.Operations[emitCreatingID] = emitEventOp(emitCreatingID, "", v.Name, eventName, api.Working, api.StatusCreating, nil)
661+
650662
id := fmt.Sprintf("create-volume:%s", v.Name)
651663
plan.Operations[id] = &Operation{
652664
ID: id,
@@ -656,8 +668,12 @@ func reconcileVolumes(project *types.Project, observed *ObservedState, plan *Rec
656668
VolumeKey: key,
657669
Desired: &v,
658670
},
659-
Reason: "volume does not exist",
671+
DependsOn: []string{emitCreatingID},
672+
Reason: "volume does not exist",
660673
}
674+
675+
emitCreatedID := fmt.Sprintf("emit-created-volume:%s", v.Name)
676+
plan.Operations[emitCreatedID] = emitEventOp(emitCreatedID, "", v.Name, eventName, api.Done, api.StatusCreated, []string{id})
661677
continue
662678
}
663679
desiredHash, err := VolumeHash(v)

pkg/compose/reconcile_test.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ func TestReconcileCreateMissingNetwork(t *testing.T) {
138138
})
139139
assert.NilError(t, err)
140140
assert.Equal(t, plan.String(), `
141-
1. create network testproject_default reason: network does not exist
141+
1. emit event testproject_default reason: Creating
142142
2. emit event testproject-web-1 reason: Creating
143-
[1,2] -> 3. create container testproject-web-1 reason: scale up
144-
[3] -> 4. emit event testproject-web-1 reason: Created
143+
[1] -> 3. create network testproject_default reason: network does not exist
144+
[3,2] -> 4. create container testproject-web-1 reason: scale up
145+
[3] -> 5. emit event testproject_default reason: Created
146+
[4] -> 6. emit event testproject-web-1 reason: Created
145147
`)
146148
}
147149

@@ -291,10 +293,12 @@ func TestReconcileCreateMissingVolume(t *testing.T) {
291293
})
292294
assert.NilError(t, err)
293295
assert.Equal(t, plan.String(), `
294-
1. create volume testproject_data reason: volume does not exist
296+
1. emit event testproject_data reason: Creating
295297
2. emit event testproject-web-1 reason: Creating
296-
[1,2] -> 3. create container testproject-web-1 reason: scale up
297-
[3] -> 4. emit event testproject-web-1 reason: Created
298+
[1] -> 3. create volume testproject_data reason: volume does not exist
299+
[3,2] -> 4. create container testproject-web-1 reason: scale up
300+
[3] -> 5. emit event testproject_data reason: Created
301+
[4] -> 6. emit event testproject-web-1 reason: Created
298302
`)
299303
}
300304

@@ -1188,11 +1192,15 @@ func TestReconcileContainerCreateDependsOnNetworkAndVolume(t *testing.T) {
11881192
})
11891193
assert.NilError(t, err)
11901194
assert.Equal(t, plan.String(), `
1191-
1. create network testproject_mynet reason: network does not exist
1192-
2. create volume testproject_myvol reason: volume does not exist
1195+
1. emit event testproject_mynet reason: Creating
1196+
2. emit event testproject_myvol reason: Creating
11931197
3. emit event testproject-app-1 reason: Creating
1194-
[1,2,3] -> 4. create container testproject-app-1 reason: scale up
1195-
[4] -> 5. emit event testproject-app-1 reason: Created
1198+
[1] -> 4. create network testproject_mynet reason: network does not exist
1199+
[2] -> 5. create volume testproject_myvol reason: volume does not exist
1200+
[4] -> 6. emit event testproject_mynet reason: Created
1201+
[4,5,3] -> 7. create container testproject-app-1 reason: scale up
1202+
[5] -> 8. emit event testproject_myvol reason: Created
1203+
[7] -> 9. emit event testproject-app-1 reason: Created
11961204
`)
11971205
}
11981206

@@ -4332,14 +4340,18 @@ func TestReconcileServiceDependsOnMissingNetworkVolumeAndService(t *testing.T) {
43324340
})
43334341
assert.NilError(t, err)
43344342
assert.Equal(t, plan.String(), `
4335-
1. create network tp_mynet reason: network does not exist
4336-
2. create volume tp_data reason: volume does not exist
4343+
1. emit event tp_mynet reason: Creating
4344+
2. emit event tp_data reason: Creating
43374345
3. emit event tp-db-1 reason: Creating
43384346
4. emit event tp-web-1 reason: Creating
4339-
[3] -> 5. create container tp-db-1 reason: scale up
4340-
[5] -> 6. emit event tp-db-1 reason: Created
4341-
[1,2,6,4] -> 7. create container tp-web-1 reason: scale up
4342-
[7] -> 8. emit event tp-web-1 reason: Created
4347+
[1] -> 5. create network tp_mynet reason: network does not exist
4348+
[2] -> 6. create volume tp_data reason: volume does not exist
4349+
[3] -> 7. create container tp-db-1 reason: scale up
4350+
[5] -> 8. emit event tp_mynet reason: Created
4351+
[6] -> 9. emit event tp_data reason: Created
4352+
[7] -> 10. emit event tp-db-1 reason: Created
4353+
[5,6,10,4] -> 11. create container tp-web-1 reason: scale up
4354+
[11] -> 12. emit event tp-web-1 reason: Created
43434355
`)
43444356
}
43454357

0 commit comments

Comments
 (0)