mirror of
https://github.com/acaloiaro/caddy-incus-upstreams
synced 2026-07-21 10:12:24 +00:00
fix: sleep until instance created properly
Fixes https://git.coopcloud.tech/decentral1se/caddy-incus-upstreams/issues/1
This commit is contained in:
parent
98536f1359
commit
3ed68872c3
2 changed files with 18 additions and 3 deletions
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
15
upstreams.go
15
upstreams.go
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue