8000 Clean up and fix for NIC Pod failing to bind when NGINX exits unexpectedly by AlexFenlon · Pull Request #7295 · nginx/kubernetes-ingress · GitHub
[go: up one dir, main page]

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
16 changes: 16 additions & 0 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"os/signal"
"path/filepath"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -785,6 +786,21 @@ func handleTermination(lbc *k8s.LoadBalancerController, nginxManager nginx.Manag
select {
case err := <-cpcfg.nginxDone:
if err != nil {
// removes .sock files after nginx exits
socketPath := "/var/lib/nginx/"
files, readErr := os.ReadDir(socketPath)
if readErr != nil {
nl.Errorf(lbc.Logger, "error trying to read directory %s: %v", socketPath, readErr)
} else {
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), ".sock") {
fullPath := filepath.Join(socketPath, f.Name())
if removeErr := os.Remove(fullPath); removeErr != nil {
nl.Errorf(lbc.Logger, "error trying to remove file %s: %v", fullPath, removeErr)
}
}
}
}
nl.Fatalf(lbc.Logger, "nginx command exited unexpectedly with status: %v", err)
} else {
nl.Info(lbc.Logger, "nginx command exited successfully")
Expand Down
0