@@ -75,18 +75,32 @@ func Run(cmd *cobra.Command, args []string) {
7575 }
7676 }()
7777 }
78- if Flags .Prometheus {
79- logs .Log .Printf ("Prometheus was enabled.\n Running prometheus server on port :8081" )
80- go func () {
78+
79+ go func () {
80+ server := http .NewServeMux ()
81+
82+ if Flags .Prometheus {
83+ logs .Log .Printf ("Prometheus was enabled.\n Running prometheus on port :8081" )
8184 prometheus .MustRegister (metricPayloadSize )
82- metricsServer := http .NewServeMux ()
83- metricsServer .Handle ("/metrics" , promhttp .Handler ())
84- err := http .ListenAndServe (":8081" , metricsServer )
85- if err != nil && ! errors .Is (err , http .ErrServerClosed ) {
86- logs .Log .Fatalf ("failed to run prometheus server: %s" , err )
87- }
88- }()
89- }
85+ server .Handle ("/metrics" , promhttp .Handler ())
86+ }
87+
88+ // Health check endpoint. Since we haven't figured a good way of knowning
89+ // what "ready" means for the agent, we just return 200 OK inconditionally.
90+ // The goal is to satisfy some Kubernetes distributions, like OpenShift,
91+ // that require a liveness and health probe to be present for each pod.
92+ server .HandleFunc ("/healthz" , func (w http.ResponseWriter , r * http.Request ) {
93+ w .WriteHeader (http .StatusOK )
94+ })
95+ server .HandleFunc ("/readyz" , func (w http.ResponseWriter , r * http.Request ) {
96+ w .WriteHeader (http .StatusOK )
97+ })
98+
99+ err := http .ListenAndServe (":8081" , server )
100+ if err != nil && ! errors .Is (err , http .ErrServerClosed ) {
101+ logs .Log .Fatalf ("failed to run the health check server: %s" , err )
102+ }
103+ }()
90104
91105 _ , isVenConn := preflightClient .(* client.VenConnClient )
92106 if isVenConn {
0 commit comments