Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexFenlon committed Jan 14, 2025
1 parent d8c6f22 commit 5c7f933
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,18 @@ func handleTermination(lbc *k8s.LoadBalancerController, nginxManager nginx.Manag
case err := <-cpcfg.nginxDone:
if err != nil {
// removes .sock files after nginx exits
files, _ := os.ReadDir("/var/lib/nginx/")
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), ".sock") {
_ = os.Remove(filepath.Join("/var/lib/nginx/", f.Name()))
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)
}

Check warning on line 803 in cmd/nginx-ingress/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/main.go#L792-L803

Added lines #L792 - L803 were not covered by tests
}
}
}
nl.Fatalf(lbc.Logger, "nginx command exited unexpectedly with status: %v", err)
Expand Down

0 comments on commit 5c7f933

Please sign in to comment.