11package healthserver
22
33import (
4- "fmt"
54"net/http"
65
76"github.com/Azure/azure-container-networking/cns"
@@ -22,16 +21,20 @@ func init() {
2221utilruntime .Must (v1alpha .AddToScheme (scheme ))
2322}
2423
25- func NewHealthzHandlerWithChecks (cnsConfig * configuration.CNSConfig ) http.Handler {
24+ // NewHealthzHandlerWithChecks will return a [http.Handler] for CNS's /healthz endpoint.
25+ // Depending on what we expect CNS to be able to read (based on the [configuration.CNSConfig])
26+ // then the checks registered to the handler will test for those expectations. For example, in
27+ // ChannelMode: CRD, the health check will ensure that CNS is able to list NNCs successfully.
28+ func NewHealthzHandlerWithChecks (cnsConfig * configuration.CNSConfig ) (http.Handler , error ) {
2629cfg , err := ctrl .GetConfig ()
2730if err != nil {
28- panic ( fmt . Errorf ( "unable to get config: %w" , err ) )
31+ return nil , errors . Wrap ( err , "unable to get a kubeconfig" )
2932}
3033cli , err := client .New (cfg , client.Options {
3134Scheme : scheme ,
3235})
3336if err != nil {
34- panic ( fmt . Errorf ( "unable to create client: %w" , err ) )
37+ return nil , errors . Wrap ( err , "unable to create a client" )
3538}
3639
3740checks := make (map [string ]healthz.Checker )
@@ -54,5 +57,5 @@ func NewHealthzHandlerWithChecks(cnsConfig *configuration.CNSConfig) http.Handle
5457// otherwise it will look for a check named "healthz" and return a 404 if not there.
5558return http .StripPrefix ("/healthz" , & healthz.Handler {
5659Checks : checks ,
57- })
60+ }), nil
5861}
0 commit comments