-
Notifications
You must be signed in to change notification settings - Fork 708
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
Fix readiness probe #2272
Merged
Merged
Fix readiness probe #2272
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5b4aba9
Mount annotations in the Pod
barkbay 8143461
Merge with origin/master
barkbay 2daebf5
Api -> API
barkbay a11d11e
make it explicit that DownwardAPI implements VolumeLike
barkbay 654a03d
Redirect errors to stderr
barkbay 229eda1
Reuse label.VersionLabelName
barkbay 50451d7
Merge with origin/master
barkbay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package volume | ||
|
||
import ( | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var downwardApiVolume = corev1.Volume{ | ||
Name: volume.DownwardApiVolumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
DownwardAPI: &corev1.DownwardAPIVolumeSource{ | ||
Items: []corev1.DownwardAPIVolumeFile{ | ||
{ | ||
Path: volume.LabelsFile, | ||
FieldRef: &corev1.ObjectFieldSelector{ | ||
FieldPath: "metadata.labels", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var downwardApiVolumeMount = corev1.VolumeMount{ | ||
Name: volume.DownwardApiVolumeName, | ||
MountPath: volume.DownwardApiMountPath, | ||
ReadOnly: true, | ||
} | ||
|
||
type DownwardApi struct{} | ||
barkbay marked this conversation as resolved.
Show resolved
Hide resolved
barkbay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func (DownwardApi) Name() string { | ||
return volume.DownwardApiVolumeName | ||
} | ||
|
||
func (DownwardApi) Volume() corev1.Volume { | ||
return downwardApiVolume | ||
} | ||
|
||
func (DownwardApi) VolumeMount() corev1.VolumeMount { | ||
return downwardApiVolumeMount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -28,7 +28,25 @@ func NewReadinessProbe() *corev1.Probe { | |||
|
||||
const ReadinessProbeScriptConfigKey = "readiness-probe-script.sh" | ||||
const ReadinessProbeScript = `#!/usr/bin/env bash | ||||
# Consider a node to be healthy if it responds to a simple GET on "/_cat/nodes?local" | ||||
|
||||
# fail should be called as a last resort to help the user to understand why the probe failed | ||||
function fail { | ||||
timestamp=$(date --iso-8601=seconds) | ||||
echo "{\"timestamp\": \"${timestamp}\", \"message\": \"readiness probe failed\", "$1"}" | tee /proc/1/fd/1 | ||||
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. That's clever :-) But should it be |
||||
exit 1 | ||||
} | ||||
|
||||
labels="` + volume.DownwardApiMountPath + "/" + volume.LabelsFile + `" | ||||
|
||||
if [[ ! -f "${labels}" ]]; then | ||||
fail "\"reason\": \"${labels} does not exist\"" | ||||
fi | ||||
|
||||
# get Elasticsearch version from the downward API | ||||
version=$(grep "elasticsearch.k8s.elastic.co/version" ${labels} | cut -d '=' -f 2) | ||||
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. Nit: could be safer to use the
|
||||
# remove quotes | ||||
version=$(echo "${version}" | tr -d '"') | ||||
|
||||
CURL_TIMEOUT=${CURL_TIMEOUT:=3} | ||||
|
||||
# Check if PROBE_PASSWORD_PATH is set, otherwise fall back to its former name in 1.0.0.beta-1: PROBE_PASSWORD_FILE | ||||
|
@@ -46,14 +64,19 @@ else | |||
BASIC_AUTH='' | ||||
fi | ||||
|
||||
# request Elasticsearch | ||||
ENDPOINT="${READINESS_PROBE_PROTOCOL:-https}://127.0.0.1:9200/_cat/nodes?local" | ||||
# request Elasticsearch on / | ||||
ENDPOINT="${READINESS_PROBE_PROTOCOL:-https}://127.0.0.1:9200/" | ||||
status=$(curl -o /dev/null -w "%{http_code}" --max-time $CURL_TIMEOUT -XGET -s -k ${BASIC_AUTH} $ENDPOINT) | ||||
curl_rc=$? | ||||
|
||||
if [[ ${curl_rc} -ne 0 ]]; then | ||||
fail "\"curl_rc\": \"${curl_rc}\"" | ||||
fi | ||||
|
||||
# ready if status code 200 | ||||
if [[ $status == "200" ]]; then | ||||
exit 0 | ||||
# ready if status code 200, 503 is tolerable if ES version is 6.x | ||||
if [[ ${status} == "200" ]] || [[ ${status} == "503" && ${version:0:2} == "6." ]]; then | ||||
exit 0 | ||||
else | ||||
exit 1 | ||||
fail " \"status\": \"${status}\", \"version\":\"${version}\" " | ||||
fi | ||||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I feel like these don't need to be global variables (even though they're only package-private). Maybe they can be directly returned from the method calls of the
DownwardApi
object?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is to avoid to recreate what must be a constant everytime a Pod spec is created. I understand that it may sound like a very tiny optimization though 😐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I don't feel strongly about it. Happy to leave it as is.