Skip to content

Commit

Permalink
Merge pull request spegel-org#496 from spegel-org/fix/bootstrap-old-l…
Browse files Browse the repository at this point in the history
…ease

Fix p2p bootstrap to run on failed readiness check
  • Loading branch information
phillebaba authored May 21, 2024
2 parents 857d8c3 + ff30037 commit 36dc812
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#460](https://github.com/spegel-org/spegel/pull/460) Fix environment variable for http-bootstrap-addr flag.
- [#471](https://github.com/spegel-org/spegel/pull/471) Fix handler key in request logging.
- [#491](https://github.com/spegel-org/spegel/pull/491) Fix so that resolve timeout does not cancel mirroring attempts.
- [#496](https://github.com/spegel-org/spegel/pull/496) Fix p2p bootstrap to run on failed readiness check.

### Security

Expand Down
2 changes: 1 addition & 1 deletion charts/spegel/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ spec:
# Startup may take a bit longer on bootsrap as Pods need to find each other.
# This is why the startup proben is a bit more forgiving, while hitting the endpoint more often.
startupProbe:
periodSeconds: 1
periodSeconds: 3
failureThreshold: 60
httpGet:
path: /healthz
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func (r *Registry) handle(rw mux.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusNotFound)
}

func (r *Registry) readyHandler(rw mux.ResponseWriter, _ *http.Request) {
ok, err := r.router.Ready()
func (r *Registry) readyHandler(rw mux.ResponseWriter, req *http.Request) {
ok, err := r.router.Ready(req.Context())
if err != nil {
rw.WriteError(http.StatusInternalServerError, fmt.Errorf("could not determine router readiness: %w", err))
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/routing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewMockRouter(resolver map[string][]netip.AddrPort, self netip.AddrPort) *M
}
}

func (m *MockRouter) Ready() (bool, error) {
func (m *MockRouter) Ready(ctx context.Context) (bool, error) {
m.mx.RLock()
defer m.mx.RUnlock()
return len(m.resolver) > 0, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/routing/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *P2PRouter) Close() error {
return r.host.Close()
}

func (r *P2PRouter) Ready() (bool, error) {
func (r *P2PRouter) Ready(ctx context.Context) (bool, error) {
addrInfo, err := r.bootstrapper.Get()
if err != nil {
return false, err
Expand All @@ -144,6 +144,10 @@ func (r *P2PRouter) Ready() (bool, error) {
return true, nil
}
if r.kdht.RoutingTable().Size() == 0 {
err := r.kdht.Bootstrap(ctx)
if err != nil {
return false, err
}
return false, nil
}
return true, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Router interface {
Ready() (bool, error)
Ready(ctx context.Context) (bool, error)
Resolve(ctx context.Context, key string, allowSelf bool, count int) (<-chan netip.AddrPort, error)
Advertise(ctx context.Context, keys []string) error
}
2 changes: 0 additions & 2 deletions test/e2e/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ else
kubectl --kubeconfig $KIND_KUBECONFIG --namespace nginx delete deployments --all
kubectl --kubeconfig $KIND_KUBECONFIG --namespace conformance delete jobs --all
helm --kubeconfig $KIND_KUBECONFIG uninstall --ignore-not-found --namespace spegel spegel
# Delete lease due to bug causing forcing us to wait for Spegel to fails once.
kubectl --kubeconfig $KIND_KUBECONFIG --namespace spegel delete lease spegel-leader-election

# Delete test images from all expect one node
for NODE in control-plane worker2 worker3 worker4
Expand Down

0 comments on commit 36dc812

Please sign in to comment.