Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/controller/enterprisesearch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ func readinessProbeScript(ent entv1.EnterpriseSearch, config *settings.Canonical
}
basicAuthArgs := "" // no credentials: no basic auth
if esAuth.Elasticsearch.Username != "" {
basicAuthArgs = fmt.Sprintf("-u %s:%s", esAuth.Elasticsearch.Username, esAuth.Elasticsearch.Password)
basicAuthArgs = fmt.Sprintf("-u %s:'%s'", esAuth.Elasticsearch.Username, esAuth.Elasticsearch.Password)
}

return []byte(`#!/usr/bin/env bash

# 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/2 2> /dev/null
echo '{"timestamp": "'"${timestamp}"'", "message": "readiness probe failed", '"${1}"'}'| tee /proc/1/fd/2 2> /dev/null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

                                                                              ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.

exit 1
}

# request timeout can be overridden from an environment variable
READINESS_PROBE_TIMEOUT=${READINESS_PROBE_TIMEOUT:=` + fmt.Sprintf("%d", ReadinessProbeTimeoutSec) + `}

# request the health endpoint and expect http status code 200. Turning globbing off for unescaped IPv6 addresses
status=$(curl -g -o /dev/null -w "%{http_code}" ` + url + ` ` + basicAuthArgs + ` -k -s --max-time ${READINESS_PROBE_TIMEOUT})
status=$(curl -g -o /dev/null -w "%{http_code}" ` + url + ` ` + basicAuthArgs + ` -k -s --max-time "${READINESS_PROBE_TIMEOUT}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

                                                                                                                                                                                  ^------------------------^ SC2086 (info): Double quote to prevent globbing and word splitting

curl_rc=$?

if [[ ${curl_rc} -ne 0 ]]; then
Expand All @@ -144,7 +144,7 @@ func readinessProbeScript(ent entv1.EnterpriseSearch, config *settings.Canonical
if [[ ${status} == "200" ]]; then
exit 0
else
fail " \"status\": \"${status}\", \"version\":\"${version}\" "
fail " \"status\": \"${status}\" "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

                                              ^--------^ SC2154 (warning): version is referenced but not assigned.

fi
`), nil
}
Expand Down