Skip to content

Commit f4c50b5

Browse files
committed
refactor: only get kubeConfig when in CRD mode
1 parent e7602f7 commit f4c50b5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

cns/healthserver/healthz.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ func init() {
2626
// then the checks registered to the handler will test for those expectations. For example, in
2727
// ChannelMode: CRD, the health check will ensure that CNS is able to list NNCs successfully.
2828
func NewHealthzHandlerWithChecks(cnsConfig *configuration.CNSConfig) (http.Handler, error) {
29-
cfg, err := ctrl.GetConfig()
30-
if err != nil {
31-
return nil, errors.Wrap(err, "unable to get a kubeconfig")
32-
}
33-
cli, err := client.New(cfg, client.Options{
34-
Scheme: scheme,
35-
})
36-
if err != nil {
37-
return nil, errors.Wrap(err, "unable to create a client")
38-
}
39-
4029
checks := make(map[string]healthz.Checker)
4130
if cnsConfig.ChannelMode == cns.CRD {
31+
cfg, err := ctrl.GetConfig()
32+
if err != nil {
33+
return nil, errors.Wrap(err, "failed to get kubeconfig")
34+
}
35+
cli, err := client.New(cfg, client.Options{
36+
Scheme: scheme,
37+
})
38+
if err != nil {
39+
return nil, errors.Wrap(err, "failed to build client")
40+
}
41+
4242
checks["nnc"] = func(req *http.Request) error {
4343
ctx := req.Context()
4444
// we just care that we're allowed to List NNCs so set limit to 1 to minimize

0 commit comments

Comments
 (0)