Skip to content

Commit 5adafb4

Browse files
authored
Clean up and fix for NIC Pod failing to bind when NGINX exits unexpectedly (#7121)
1 parent 80f67d3 commit 5adafb4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/nginx-ingress/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"os/signal"
13+
"path/filepath"
1314
"regexp"
1415
"runtime"
1516
"strings"
@@ -788,6 +789,21 @@ func handleTermination(lbc *k8s.LoadBalancerController, nginxManager nginx.Manag
788789
select {
789790
case err := <-cpcfg.nginxDone:
790791
if err != nil {
792+
// removes .sock files after nginx exits
793+
socketPath := "/var/lib/nginx/"
794+
files, readErr := os.ReadDir(socketPath)
795+
if readErr != nil {
796+
nl.Errorf(lbc.Logger, "error trying to read directory %s: %v", socketPath, readErr)
797+
} else {
798+
for _, f := range files {
799+
if !f.IsDir() && strings.HasSuffix(f.Name(), ".sock") {
800+
fullPath := filepath.Join(socketPath, f.Name())
801+
if removeErr := os.Remove(fullPath); removeErr != nil {
802+
nl.Errorf(lbc.Logger, "error trying to remove file %s: %v", fullPath, removeErr)
803+
}
804+
}
805+
}
806+
}
791807
nl.Fatalf(lbc.Logger, "nginx command exited unexpectedly with status: %v", err)
792808
} else {
793809
nl.Info(lbc.Logger, "nginx command exited successfully")

0 commit comments

Comments
 (0)