Skip to content

Commit

Permalink
Clean up and fix for NIC Pod failing to bind when NGINX exits unexpec…
Browse files Browse the repository at this point in the history
…tedly (#7121)
  • Loading branch information
AlexFenlon authored and pdabelf5 committed Jan 30, 2025
1 parent 16f2ee5 commit 9a1429d
Showing 1 changed file with 16 additions and 0 deletions.
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 @@ -788,6 +789,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 comments on commit 9a1429d

Please sign in to comment.