-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Refactor health checks and wait until NGINX process ends #4487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"time" | ||
|
||
"k8s.io/ingress-nginx/internal/nginx" | ||
"k8s.io/klog" | ||
) | ||
|
||
func main() { | ||
err := exec.Command("bash", "-c", "pkill -SIGTERM -f nginx-ingress-controller").Run() | ||
if err != nil { | ||
klog.Errorf("unexpected error terminating ingress controller: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// wait for the NGINX process to terminate | ||
timer := time.NewTicker(time.Second * 1) | ||
for range timer.C { | ||
if !nginx.IsRunning() { | ||
timer.Stop() | ||
break | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ import ( | |
"time" | ||
|
||
ps "github.com/mitchellh/go-ps" | ||
"github.com/tv42/httpunix" | ||
"k8s.io/klog" | ||
) | ||
|
||
|
@@ -38,8 +37,8 @@ var TemplatePath = "/etc/nginx/template/nginx.tmpl" | |
// PID defines the location of the pid file used by NGINX | ||
var PID = "/tmp/nginx.pid" | ||
|
||
// StatusSocket defines the location of the unix socket used by NGINX for the status server | ||
var StatusSocket = "/tmp/nginx-status-server.sock" | ||
// StatusPort port used by NGINX for the status server | ||
var StatusPort = 10256 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason you're switching to tcp? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the node is smaller than should be or during spikes of CPU, the request fails (socket). I cannot reproduce this consistently but when I can is only related to CPU utilization. After this is merged I will add an e2e test so show how this can be reproduced (using stress) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aledbf did this e2e test ever get added? I'm running into a similar situation when CPU spikes and I'm wondering if the switch away from a socket actually resolves it |
||
|
||
// HealthPath defines the path used to define the health check location in NGINX | ||
var HealthPath = "/healthz" | ||
|
@@ -56,17 +55,12 @@ var StreamSocket = "/tmp/ingress-stream.sock" | |
|
||
var statusLocation = "nginx-status" | ||
|
||
var httpClient *http.Client | ||
|
||
func init() { | ||
httpClient = buildUnixSocketClient(HealthCheckTimeout) | ||
} | ||
|
||
// NewGetStatusRequest creates a new GET request to the internal NGINX status server | ||
func NewGetStatusRequest(path string) (int, []byte, error) { | ||
url := fmt.Sprintf("%v://%v%v", httpunix.Scheme, statusLocation, path) | ||
url := fmt.Sprintf("http://127.0.0.1:%v%v", StatusPort, path) | ||
|
||
res, err := httpClient.Get(url) | ||
client := http.Client{} | ||
res, err := client.Get(url) | ||
if err != nil { | ||
return 0, nil, err | ||
} | ||
|
@@ -82,14 +76,15 @@ func NewGetStatusRequest(path string) (int, []byte, error) { | |
|
||
// NewPostStatusRequest creates a new POST request to the internal NGINX status server | ||
func NewPostStatusRequest(path, contentType string, data interface{}) (int, []byte, error) { | ||
url := fmt.Sprintf("%v://%v%v", httpunix.Scheme, statusLocation, path) | ||
url := fmt.Sprintf("http://127.0.0.1:%v%v", StatusPort, path) | ||
|
||
buf, err := json.Marshal(data) | ||
if err != nil { | ||
return 0, nil, err | ||
} | ||
|
||
res, err := httpClient.Post(url, contentType, bytes.NewReader(buf)) | ||
client := http.Client{} | ||
res, err := client.Post(url, contentType, bytes.NewReader(buf)) | ||
if err != nil { | ||
return 0, nil, err | ||
} | ||
|
@@ -142,19 +137,6 @@ func readFileToString(path string) (string, error) { | |
return string(contents), nil | ||
} | ||
|
||
func buildUnixSocketClient(timeout time.Duration) *http.Client { | ||
u := &httpunix.Transport{ | ||
DialTimeout: 1 * time.Second, | ||
RequestTimeout: timeout, | ||
ResponseHeaderTimeout: timeout, | ||
} | ||
u.RegisterLocation(statusLocation, StatusSocket) | ||
|
||
return &http.Client{ | ||
Transport: u, | ||
} | ||
} | ||
|
||
// Version return details about NGINX | ||
func Version() string { | ||
flag := "-v" | ||
|
Uh oh!
There was an error while loading. Please reload this page.