Skip to content

Commit d19c64f

Browse files
committed
chore: only check NNCs if ChannelMode is CRD
not every instance of CNS will need (or can) check NNCs. The `CRD` channel mode is used by AKS to indicate that CNS will be reading/watching NNCs. `AzureHost` is a newer mode that's used in nodesubnet where NNCs aren't used and therefore CNS has no reason to have its health depend on NNC access.
1 parent 20ed505 commit d19c64f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

cns/healthserver/healthz.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package healthserver
22

33
import (
4+
"fmt"
45
"net/http"
56

7+
"github.com/Azure/azure-container-networking/cns"
8+
"github.com/Azure/azure-container-networking/cns/configuration"
69
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
710
"github.com/pkg/errors"
811
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -13,26 +16,27 @@ import (
1316
"sigs.k8s.io/controller-runtime/pkg/healthz"
1417
)
1518

16-
var schema = runtime.NewScheme()
19+
var scheme = runtime.NewScheme()
1720

1821
func init() {
19-
utilruntime.Must(v1alpha.AddToScheme(schema))
22+
utilruntime.Must(v1alpha.AddToScheme(scheme))
2023
}
2124

22-
func NewHealthzHandlerWithChecks() http.Handler {
25+
func NewHealthzHandlerWithChecks(cnsConfig *configuration.CNSConfig) http.Handler {
2326
cfg, err := ctrl.GetConfig()
2427
if err != nil {
25-
panic(err)
28+
panic(fmt.Errorf("unable to get config: %w", err))
2629
}
2730
cli, err := client.New(cfg, client.Options{
28-
Scheme: schema,
31+
Scheme: scheme,
2932
})
3033
if err != nil {
31-
panic(err)
34+
panic(fmt.Errorf("unable to create client: %w", err))
3235
}
3336

34-
checks := map[string]healthz.Checker{
35-
"nnc": func(req *http.Request) error {
37+
checks := make(map[string]healthz.Checker)
38+
if cnsConfig.ChannelMode == cns.CRD {
39+
checks["nnc"] = func(req *http.Request) error {
3640
ctx := req.Context()
3741
// we just care that we're allowed to List NNCs so set limit to 1 to minimize
3842
// additional load on apiserver
@@ -43,7 +47,7 @@ func NewHealthzHandlerWithChecks() http.Handler {
4347
return errors.Wrap(err, "failed to list NodeNetworkConfig")
4448
}
4549
return nil
46-
},
50+
}
4751
}
4852

4953
// strip prefix so that it runs through all checks registered on the handler.

cns/service/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ func main() {
642642
return nil
643643
}),
644644
}
645-
healthzHandler := healthserver.NewHealthzHandlerWithChecks()
645+
646+
healthzHandler := healthserver.NewHealthzHandlerWithChecks(cnsconfig)
646647
go healthserver.Start(z, cnsconfig.MetricsBindAddress, healthzHandler, readyChecker)
647648

648649
nmaConfig, err := nmagent.NewConfig(cnsconfig.WireserverIP)
@@ -982,7 +983,7 @@ func main() {
982983
// Start fs watcher here
983984
z.Info("AsyncPodDelete is enabled")
984985
logger.Printf("AsyncPodDelete is enabled")
985-
cnsclient, err := cnsclient.New("", cnsReqTimeout) //nolint
986+
cnsclient, err := cnsclient.New("", cnsReqTimeout) // nolint
986987
if err != nil {
987988
z.Error("failed to create cnsclient", zap.Error(err))
988989
}
@@ -1483,7 +1484,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
14831484
// wait for the Reconciler to run once on a NNC that was made for this Node.
14841485
// the nncReadyCtx has a timeout of 15 minutes, after which we will consider
14851486
// this false and the NNC Reconciler stuck/failed, log and retry.
1486-
nncReadyCtx, cancel := context.WithTimeout(ctx, 15*time.Minute) //nolint // it will time out and not leak
1487+
nncReadyCtx, cancel := context.WithTimeout(ctx, 15*time.Minute) // nolint // it will time out and not leak
14871488
if started, err := nncReconciler.Started(nncReadyCtx); !started {
14881489
logger.Errorf("NNC reconciler has not started, does the NNC exist? err: %v", err)
14891490
nncReconcilerStartFailures.Inc()

0 commit comments

Comments
 (0)