Skip to content

Commit

Permalink
Merge pull request #562 from SparebankenVest/feature/always-serve-hea…
Browse files Browse the repository at this point in the history
…lth-endpoint

Always serve /healthz endpoint for controller
  • Loading branch information
181192 authored Jul 2, 2023
2 parents 5567e33 + ceeddf6 commit 0adb24f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cmd/azure-keyvault-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var (
func initConfig() {
viper.SetDefault("auth_type", "azureCloudConfig")
viper.SetDefault("metrics_enabled", false)
viper.SetDefault("metrics_port", "9000")
viper.SetDefault("http_port", "9000")

viper.AutomaticEnv()
}
Expand Down Expand Up @@ -111,13 +111,9 @@ func main() {
akv2k8s.LogVersion()

authType := viper.GetString("auth_type")
serveMetrics := viper.GetBool("metrics_enabled")
metricsPort := viper.GetString("metrics_port")
objectLabels := viper.GetString("object_labels")

if serveMetrics {
createMetricsServer(metricsPort)
}
createHttpServer()

// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler()
Expand Down Expand Up @@ -227,20 +223,25 @@ func main() {
controller.Run(stopCh)
}

func createMetricsServer(metricsPort string) {
func createHttpServer() {
httpPort := viper.GetString("http_port")
serveMetrics := viper.GetBool("metrics_enabled")

router := mux.NewRouter()
httpURL := fmt.Sprintf(":%s", metricsPort)
httpURL := fmt.Sprintf(":%s", httpPort)

router.Handle("/metrics", promhttp.Handler())
klog.InfoS("serving metrics endpoint", "path", fmt.Sprintf("%s/metrics", httpURL))
if serveMetrics {
router.Handle("/metrics", promhttp.Handler())
klog.InfoS("serving metrics endpoint", "path", fmt.Sprintf("%s/metrics", httpURL))
}

router.HandleFunc("/healthz", healthHandler)
klog.InfoS("serving health endpoint", "path", fmt.Sprintf("%s/healthz", httpURL))

go func() {
err := http.ListenAndServe(httpURL, router)
if err != nil {
klog.ErrorS(err, "error serving metrics", "url", httpURL)
klog.ErrorS(err, "error serving http server", "url", httpURL)
os.Exit(1)
}
}()
Expand Down

0 comments on commit 0adb24f

Please sign in to comment.