Skip to content

Commit 0bf0b78

Browse files
authored
Clean up and fix for NIC Pod failing to bind when NGINX exits unexpectedly (#7295)
1 parent 5b73e0c commit 0bf0b78

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"
@@ -785,6 +786,21 @@ func handleTermination(lbc *k8s.LoadBalancerController, nginxManager nginx.Manag
785786
select {
786787
case err := <-cpcfg.nginxDone:
787788
if err != nil {
789+
// removes .sock files after nginx exits
790+
socketPath := "/var/lib/nginx/"
791+
files, readErr := os.ReadDir(socketPath)
792+
if readErr != nil {
793+
nl.Errorf(lbc.Logger, "error trying to read directory %s: %v", socketPath, readErr)
794+
} else {
795+
for _, f := range files {
796+
if !f.IsDir() && strings.HasSuffix(f.Name(), ".sock") {
797+
fullPath := filepath.Join(socketPath, f.Name())
798+
if removeErr := os.Remove(fullPath); removeErr != nil {
799+
nl.Errorf(lbc.Logger, "error trying to remove file %s: %v", fullPath, removeErr)
800+
}
801+
}
802+
}
803+
}
788804
nl.Fatalf(lbc.Logger, "nginx command exited unexpectedly with status: %v", err)
789805
} else {
790806
nl.Info(lbc.Logger, "nginx command exited successfully")

0 commit comments

Comments
 (0)