@@ -19,6 +19,7 @@ package apiserver
1919import (
2020 "fmt"
2121
22+ "github.com/fsnotify/fsnotify"
2223 istiov1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
2324 admregv1 "k8s.io/api/admissionregistration/v1"
2425 authzv1 "k8s.io/api/authorization/v1"
@@ -169,6 +170,15 @@ func (c completedConfig) New() (*HigressServer, error) {
169170 }
170171 }
171172
173+ // Create shared watcher for file storage mode to avoid "too many open files"
174+ var sharedWatcher * fsnotify.Watcher
175+ if storageMode == options .Storage_File {
176+ sharedWatcher , err = fsnotify .NewWatcher ()
177+ if err != nil {
178+ return nil , fmt .Errorf ("failed to create shared file watcher: %v" , err )
179+ }
180+ }
181+
172182 storageCreateFunc := func (
173183 groupResource schema.GroupResource ,
174184 runtimeCodec runtime.Codec ,
@@ -185,7 +195,7 @@ func (c completedConfig) New() (*HigressServer, error) {
185195 switch storageMode {
186196 case options .Storage_File :
187197 runtimeCodec = codec .NewFlatAwareCodec (groupResource , runtimeCodec )
188- return registry .NewFileREST (groupResource , runtimeCodec , storageOptions .FileOptions .RootDir , extension , isNamespaced , singularName , newFunc , newListFunc , attrFunc )
198+ return registry .NewFileREST (groupResource , runtimeCodec , storageOptions .FileOptions .RootDir , extension , isNamespaced , singularName , newFunc , newListFunc , attrFunc , sharedWatcher )
189199 case options .Storage_Nacos :
190200 var encryptionKey []byte = nil
191201 if sensitive {
0 commit comments