fix: sleep until instance created properly

Fixes #1
This commit is contained in:
decentral1se 2024-12-13 00:41:34 +01:00
parent 98536f1359
commit 3ed68872c3
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 18 additions and 3 deletions

View File

@ -35,10 +35,12 @@ example.com {
The plugin responds to the following Incus events:
* `api.EventLifecycleInstanceStarted`
* `api.EventLifecycleInstanceCreated`
* `api.EventLifecycleInstanceRestarted`
* `api.EventLifecycleInstanceResumed`
* `api.EventLifecycleInstanceStarted`
It currently *only* retrieves the ipv4 addresses of the instances.
It currently *only* matches against the upstream ipv4 addresses of instances.
## Hackin'

View File

@ -187,6 +187,13 @@ func (u *Upstreams) provisionCandidates(ctx caddy.Context, conn incus.InstanceSe
)
address := net.JoinHostPort(addr, port)
ctx.Logger().Info("new candidate provisioned",
zap.String("instance_name", i.Name),
zap.String("address", address),
zap.Any("matchers", matchers),
)
updated = append(updated, candidate{
matchers: matchers,
upstream: &reverseproxy.Upstream{Dial: address},
@ -213,8 +220,11 @@ func (u *Upstreams) keepUpdated(ctx caddy.Context, conn incus.InstanceServer) {
ctx.Logger().Debug("initialised event listener")
events := []string{
api.EventLifecycleInstanceStarted,
api.EventLifecycleInstanceCreated,
api.EventLifecycleInstanceReady,
api.EventLifecycleInstanceRestarted,
api.EventLifecycleInstanceResumed,
api.EventLifecycleInstanceStarted,
}
if _, err := listener.AddHandler([]string{"lifecycle"}, func(event api.Event) {
@ -228,6 +238,9 @@ func (u *Upstreams) keepUpdated(ctx caddy.Context, conn incus.InstanceServer) {
return
}
// NOTE(d1): ensure network comes up
time.Sleep(3 * time.Second)
ctx.Logger().Debug("handling event",
zap.String("instance_name", metadata.Name),
zap.String("event", metadata.Action),