mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-31 00:03:47 +00:00

Add a PreStop lifecycle hook to the ProxyGroup ingress spec so that we can explicitly notify control that the service is being unadvertised and prompt it to update the netmap for clients faster. Without this, control just treats the device as temporarily offline and allows it a grace period before no longer considering it part of the service. Updates tailscale/corp#24795 Change-Id: I0a9a4fe7a5395ca76135ceead05cbc3ee32b3d3c Signed-off-by: Tom Proctor <tomhjp@users.noreply.github.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"sync"
|
|
|
|
"tailscale.com/kube/kubetypes"
|
|
)
|
|
|
|
// healthz is a simple health check server, if enabled it returns 200 OK if
|
|
// this tailscale node currently has at least one tailnet IP address else
|
|
// returns 503.
|
|
type healthz struct {
|
|
sync.Mutex
|
|
hasAddrs bool
|
|
podIPv4 string
|
|
}
|
|
|
|
func (h *healthz) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
h.Lock()
|
|
defer h.Unlock()
|
|
|
|
if h.hasAddrs {
|
|
w.Header().Add(kubetypes.PodIPv4Header, h.podIPv4)
|
|
if _, err := w.Write([]byte("ok")); err != nil {
|
|
http.Error(w, fmt.Sprintf("error writing status: %v", err), http.StatusInternalServerError)
|
|
}
|
|
} else {
|
|
http.Error(w, "node currently has no tailscale IPs", http.StatusServiceUnavailable)
|
|
}
|
|
}
|
|
|
|
func (h *healthz) update(healthy bool) {
|
|
h.Lock()
|
|
defer h.Unlock()
|
|
|
|
if h.hasAddrs != healthy {
|
|
log.Println("Setting healthy", healthy)
|
|
}
|
|
h.hasAddrs = healthy
|
|
}
|
|
|
|
// registerHealthHandlers registers a simple health handler at /healthz.
|
|
// A containerized tailscale instance is considered healthy if
|
|
// it has at least one tailnet IP address.
|
|
func registerHealthHandlers(mux *http.ServeMux, podIPv4 string) *healthz {
|
|
h := &healthz{podIPv4: podIPv4}
|
|
mux.Handle("GET /healthz", h)
|
|
return h
|
|
}
|