Skip to content

Commit e3a1e1c

Browse files
committed
send addon's ansible event
1 parent c8d8a8a commit e3a1e1c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pkg/graph/instances.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,24 @@ func (ctrl *instancesController) Create(ctx context.Context, group driver.Docume
597597
if err = ctrl.ansPs.Publish("hooks", services_registry.Topic("ansible_hooks"), &c); err != nil {
598598
log.Error("Failed to publish ansible hook", zap.Error(err))
599599
}
600+
for _, a := range i.GetAddons() {
601+
addon, err := ctrl.addons.Get(ctx, a)
602+
if err != nil {
603+
log.Error("Failed to get instance addon", zap.Error(err), zap.String("addon", a))
604+
continue
605+
}
606+
if addon.Action != nil && addon.Action.GetPlaybook() != "" {
607+
c := pb.Context{
608+
Instance: i.GetUuid(),
609+
Sp: sp,
610+
Event: "START",
611+
Addon: &a,
612+
}
613+
if err = ctrl.ansPs.Publish("hooks", services_registry.Topic("ansible_hooks"), &c); err != nil {
614+
log.Error("Failed to publish ansible hook addon event", zap.Error(err))
615+
}
616+
}
617+
}
600618
}
601619
e := epb.Event{
602620
Uuid: i.GetUuid(),
@@ -785,6 +803,24 @@ func (ctrl *instancesController) Update(ctx context.Context, _ string, inst, old
785803
if err = ctrl.ansPs.Publish("hooks", services_registry.Topic("ansible_hooks"), &c); err != nil {
786804
log.Error("Failed to publish ansible hook", zap.Error(err))
787805
}
806+
for _, a := range inst.GetAddons() {
807+
addon, err := ctrl.addons.Get(ctx, a)
808+
if err != nil {
809+
log.Error("Failed to get instance addon", zap.Error(err), zap.String("addon", a))
810+
continue
811+
}
812+
if addon.Action != nil && addon.Action.GetPlaybook() != "" {
813+
c := pb.Context{
814+
Instance: inst.GetUuid(),
815+
Sp: sp,
816+
Event: "START",
817+
Addon: &a,
818+
}
819+
if err = ctrl.ansPs.Publish("hooks", services_registry.Topic("ansible_hooks"), &c); err != nil {
820+
log.Error("Failed to publish ansible hook addon event", zap.Error(err))
821+
}
822+
}
823+
}
788824
}
789825
c := pb.Context{
790826
Instance: uuid,

0 commit comments

Comments
 (0)