Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ import (
"github.com/Azure/azure-container-networking/store"
"github.com/avast/retry-go/v3"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -932,10 +934,22 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
return err
}

// the nodeScopedCache sets Selector options on the Manager cache which are used
// to perform *server-side* filtering of the cached objects. This is very important
// for high node/pod count clusters, as it keeps us from watching objects at the
// whole cluster scope when we are only interested in the Node's scope.
nodeScopedCache := cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&v1alpha.NodeNetworkConfig{}: {
Field: fields.SelectorFromSet(fields.Set{"metadata.name": nodeName}),
},
},
})
manager, err := ctrl.NewManager(kubeConfig, ctrl.Options{
Scheme: nodenetworkconfig.Scheme,
MetricsBindAddress: cnsconfig.MetricsBindAddress,
Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config
NewCache: nodeScopedCache,
})
if err != nil {
return errors.Wrap(err, "failed to create manager")
Expand Down