@@ -116,8 +116,24 @@ func start(config npmconfig.Config, flags npmconfig.Flags) error {
116
116
resyncPeriod := time .Duration (float64 (minResyncPeriod .Nanoseconds ()) * factor )
117
117
klog .Infof ("Resync period for NPM pod is set to %d." , int (resyncPeriod / time .Minute ))
118
118
factory := informers .NewSharedInformerFactory (clientset , resyncPeriod )
119
+ podFactory := factory // // Separate podFactory for different versions in npm and npm lite.
120
+ // npm-lite -> daemon set will listen to pods only in its own node
121
+ if config .Toggles .EnableNPMLite {
122
+ podFactory = informers .NewSharedInformerFactoryWithOptions (
123
+ clientset ,
124
+ resyncPeriod ,
125
+ informers .WithTweakListOptions (func (options * metav1.ListOptions ) {
126
+ // Use field selector to filter pods based on their assigned node
127
+ klog .Infof ("NPM agent is listening to pods only under its node" )
128
+ options .FieldSelector = "spec.nodeName=" + models .GetNodeName ()
129
+ }),
130
+ )
131
+ }
119
132
120
- k8sServerVersion := k8sServerVersion (clientset )
133
+ err = metrics .CreateTelemetryHandle (config .NPMVersion (), version , npm .GetAIMetadata ())
134
+ if err != nil {
135
+ klog .Infof ("CreateTelemetryHandle failed with error %v. AITelemetry is not initialized." , err )
136
+ }
121
137
122
138
var dp dataplane.GenericDataplane
123
139
stopChannel := wait .NeverStop
@@ -181,11 +197,9 @@ func start(config npmconfig.Config, flags npmconfig.Flags) error {
181
197
}
182
198
dp .RunPeriodicTasks ()
183
199
}
184
- npMgr := npm .NewNetworkPolicyManager (config , factory , dp , exec .New (), version , k8sServerVersion )
185
- err = metrics .CreateTelemetryHandle (config .NPMVersion (), version , npm .GetAIMetadata ())
186
- if err != nil {
187
- klog .Infof ("CreateTelemetryHandle failed with error %v. AITelemetry is not initialized." , err )
188
- }
200
+
201
+ k8sServerVersion := k8sServerVersion (clientset )
202
+ npMgr := npm .NewNetworkPolicyManager (config , factory , podFactory , dp , exec .New (), version , k8sServerVersion )
189
203
190
204
go restserver .NPMRestServerListenAndServe (config , npMgr )
191
205
0 commit comments