-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
K8S: Support fsnotify and reload when ConfigMap update #1635
Comments
The paragraph in Aliyun's SLS log service says link is as follows:
Another solution is to listen for changes in the configuration file. However, there is an issue where the fsnotify signal may not be received due to symbolic links: link Here is an example of Nginx's reload, which is implemented using fsnotify: link watcher, watcherErr := fsnotify.NewWatcher()
go func() {
event, ok := <-watcher.Events:
if event.Op&fsnotify.Create != fsnotify.Create {
return;
}
if filepath.Base(event.Name) != "..data" {
return;
}
nginxProcess, nginxProcessErr := os.FindProcess(getMasterNginxPid())
nginxProcess.Signal(syscall.SIGHUP)
}
pathToWatch = "/etc/nginx"
if err := watcher.Add(pathToWatch); err != nil {
stderrLogger.Fatal(err)
} You can see that it also listens for changes in the file directory and then sends the SIGHUP (reload) signal to Nginx.
|
It is implemented using inotify under Linux.
Since inotify returns an fd and can be initialized as non-blocking mode using inotify_init1, reading it using read is an IO operation, so we should be able to use ST to read this fd.
|
SRS has added two configurations, automatically enabling auto reload under Docker, and disabling auto reload outside of Docker.
The added log prints are as follows:
You can see that there is an additional fd=10, a_inode(inotify):
|
If the file is deleted or moved, and then created again (as part of the ConfigMap update logic). When a file is deleted, including the target of symbolic links being moved or deleted:
When a file is created, including the creation of the target of symbolic links:
|
K8S will have a ..data subdirectory:
All events of K8S are as follows:
The key events are as follows, it appears that K8S executed a command similar to
After receiving the event, it is necessary to determine the file name. Only if it is
|
K8S uses ConfigMap to store configuration files, for example:
ConfigMap will be mounted as a volume and become a configuration file:
You can view the running pods:
When ConfigMap changes, you can use fsnotify to receive notifications of file changes, thereby triggering the reload of SRS.
TRANS_BY_GPT3
The text was updated successfully, but these errors were encountered: