Skip to content
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

Update deployment check time limit #462

Merged
merged 3 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/deployment-check/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
docker build -t kuberhealthy/deployment-check:v1.4.1 -f Dockerfile ../../
docker build -t kuberhealthy/deployment-check:v1.4.3 -f Dockerfile ../../

push:
docker push kuberhealthy/deployment-check:v1.4.1
docker push kuberhealthy/deployment-check:v1.4.3
13 changes: 3 additions & 10 deletions cmd/deployment-check/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,12 @@ func parseInputValues() {
// Set check time limit to default
checkTimeLimit = defaultCheckTimeLimit
// Get the deadline time in unix from the env var
unixDeadline, err := kh.GetDeadline()
timeDeadline, err := kh.GetDeadline()
if err != nil {
log.Infoln("There was an issue getting the check deadline:", err.Error())
}
// Calculate check run duration from the deadline and now
deadline, err := strconv.Atoi(unixDeadline)
if err != nil {
log.Fatalln("Failed to parse unix deadline from environment.")
}
if deadline > 0 {
log.Infoln("Parsed check deadline time from the environment:", deadline)
checkTimeLimit = time.Duration((int64(deadline) - time.Now().Unix()) * 1e9) // Multiply by 1,000,000,000 because that's how many nanoseconds are in a second
}
checkTimeLimit = timeDeadline.Sub(time.Now().Add(time.Second * 5))
log.Infoln("Check time limit set to:", checkTimeLimit)

// Parse incoming deployment rolling-update environment variable
if len(rollingUpdateEnv) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/test-external-check/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
docker build -t kuberhealthy/test-external-check:v1.3.0 -f Dockerfile ../../
docker build -t kuberhealthy/test-external-check:v1.3.1 -f Dockerfile ../../

push:
docker push kuberhealthy/test-external-check:v1.3.0
docker push kuberhealthy/test-external-check:v1.3.1
13 changes: 3 additions & 10 deletions cmd/test-external-check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,12 @@ func init() {
// Set check time limit to default
timeLimit = time.Duration(time.Minute * 10)
// Get the deadline time in unix from the env var
unixDeadline, err := checkclient.GetDeadline()
timeDeadline, err := checkclient.GetDeadline()
if err != nil {
log.Println("There was an issue getting the check deadline:", err.Error())
}
// Calculate check run duration from the deadline and now
deadline, err := strconv.Atoi(unixDeadline)
if err != nil {
log.Fatalln("Failed to parse unix deadline from environment.")
}
if deadline > 0 {
log.Println("Parsed check deadline time from the environment:", deadline)
timeLimit = time.Duration((int64(deadline) - time.Now().Unix()) * 1e9) // Multiply by 1,000,000,000 because that's how many nanoseconds are in a second
}
timeLimit = timeDeadline.Sub(time.Now().Add(time.Second * 5))
log.Println("Check time limit set to:", timeLimit)
Comment on lines -53 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better!

}

func main() {
Expand Down
14 changes: 11 additions & 3 deletions pkg/checks/external/checkclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"log"
"net/http"
"os"
"strconv"
"time"

"github.com/Comcast/kuberhealthy/v2/pkg/checks/external"
"github.com/Comcast/kuberhealthy/v2/pkg/checks/external/status"
Expand Down Expand Up @@ -110,13 +112,19 @@ func getKuberhealthyURL() (string, error) {

// GetDeadline fetches the KH_CHECK_RUN_DEADLINE environment variable and returns it.
// Checks are given up to the deadline to complete their check runs.
func GetDeadline() (string, error) {
func GetDeadline() (time.Time, error) {
unixDeadline := os.Getenv(external.KHDeadline)

if len(unixDeadline) < 1 {
writeLog("ERROR: kuberhealthy check deadline from environment variable", external.KHDeadline, "was blank")
return "", fmt.Errorf("fetched %s environment variable but it was blank", external.KHDeadline)
return time.Time{}, fmt.Errorf("fetched %s environment variable but it was blank", external.KHDeadline)
}

return unixDeadline, nil
unixDeadlineInt, err := strconv.Atoi(unixDeadline)
if err != nil {
writeLog("ERROR: unable to parse", external.KHDeadline+": "+err.Error())
return time.Time{}, fmt.Errorf("unable to parse %s: %s", external.KHDeadline, err.Error())
}

return time.Unix(int64(unixDeadlineInt), 0), nil
}