Skip to content

Commit

Permalink
add readiness probe
Browse files Browse the repository at this point in the history
Change-Id: I314fe06a02203460dcdb621cf4de31d18dea0941
  • Loading branch information
aojea committed Dec 10, 2024
1 parent 8219799 commit 3129b9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"context"
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"sync/atomic"

"github.com/GoogleCloudPlatform/dranet/pkg/driver"

Expand All @@ -41,10 +43,14 @@ const (
var (
hostnameOverride string
kubeconfig string
bindAddress string

ready atomic.Bool
)

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
flag.StringVar(&bindAddress, "bind-address", ":9177", "The IP address and port for the metrics and healthz server to serve on")
flag.StringVar(&hostnameOverride, "hostname-override", "", "If non-empty, will be used as the name of the Node that kube-network-policies is running on. If unset, the node name is assumed to be the same as the node's hostname.")

flag.Usage = func() {
Expand All @@ -61,6 +67,20 @@ func main() {
klog.Infof("FLAG: --%s=%q", f.Name, f.Value)
})

healthMux := http.NewServeMux()
healthMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
if !ready.Load() {
fmt.Fprintf(w, "starting ...")
w.WriteHeader(http.StatusServiceUnavailable)
} else {
fmt.Fprintf(w, "ok")
w.WriteHeader(http.StatusOK)
}
})
go func() {
_ = http.ListenAndServe(bindAddress, healthMux)
}()

var config *rest.Config
var err error
if kubeconfig != "" {
Expand Down Expand Up @@ -106,6 +126,7 @@ func main() {
klog.Fatalf("driver failed to start: %v", err)
}
defer dranet.Stop()
ready.Store(true)
klog.Info("driver started")

select {
Expand Down
4 changes: 4 additions & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ spec:
- name: etc
hostPath:
path: /etc
readinessProbe:
httpGet:
path: /healthz
port: 8080
---

0 comments on commit 3129b9b

Please sign in to comment.