Skip to content

Commit 42de81f

Browse files
author
David Kowalski
committed
PR comments fixes
1 parent ef6adcf commit 42de81f

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

pkg/controller/common/defaults/pod_template.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ func (b *PodTemplateBuilder) WithPreStopHook(handler corev1.Handler) *PodTemplat
321321
b.Container.Lifecycle = &corev1.Lifecycle{}
322322
}
323323

324-
b.Container.Lifecycle.PreStop = &handler
324+
if b.Container.Lifecycle.PreStop == nil {
325+
// no user-provided hook, we can use our own
326+
b.Container.Lifecycle.PreStop = &handler
327+
}
328+
325329
return b
326330
}

pkg/controller/elasticsearch/nodespec/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func DefaultEnvVars(httpCfg commonv1.HTTPConfig, serviceName string) []corev1.En
5858
{Name: settings.EnvProbePasswordPath, Value: path.Join(esvolume.ProbeUserSecretMountPath, user.InternalProbeUserName)},
5959
{Name: settings.EnvProbeUsername, Value: user.InternalProbeUserName},
6060
{Name: settings.EnvReadinessProbeProtocol, Value: httpCfg.Protocol()},
61-
{Name: settings.ServiceName, Value: serviceName},
61+
{Name: settings.HeadlessServiceName, Value: serviceName},
6262

6363
// Disable curl/libnss use of sqlite caching to avoid triggering an issue in linux/kubernetes
6464
// where the kernel's dentry cache grows by 5mb every time curl is invoked. This cache usage

pkg/controller/elasticsearch/nodespec/lifecycle_hook.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,33 @@ const PreStopHookScriptConfigKey = "pre-stop-hook-script.sh"
2222
const PreStopHookScript = `#!/usr/bin/env bash
2323
2424
# This script will wait for up to $MAX_WAIT_SECONDS for $POD_IP to disappear from DNS record,
25-
# then it will wait additional $ADDN_WAIT_SECONDS and exit. This slows down the process shutdown
25+
# then it will wait additional $ADDITIONAL_WAIT_SECONDS and exit. This slows down the process shutdown
2626
# and allows to make changes to the pool gracefully, without blackholing traffic when DNS
27-
# contains IP that is already inactive. Assumes $SERVICE_NAME and $POD_IP env variables are defined.
27+
# contains IP that is already inactive. Assumes $HEADLESS_SERVICE_NAME and $POD_IP env variables are defined.
2828
29-
MAX_WAIT_SECONDS=20 # max time to wait for pods IP to disappear from DNS
30-
ADDN_WAIT_SECONDS=1 # additional wait, allows queries to successfully use IP from DNS from before pod termination
29+
# max time to wait for pods IP to disappear from DNS. As this runs in parallel to grace period
30+
# (defaulting to 30s) after which process is SIGKILLed, it should be set to allow enough time
31+
# for the process to gracefully terminate.
32+
MAX_WAIT_SECONDS=20
33+
34+
# additional wait, allows queries to successfully use IP from DNS from before pod termination
35+
# this gives a little bit more time for clients that resolved DNS just before DNS record
36+
# was updated.
37+
ADDITIONAL_WAIT_SECONDS=1
38+
39+
START_TIME=$(date +%s)
40+
while true; do
41+
ELAPSED_TIME=$(($(date +%s) - $START_TIME))
42+
43+
if [ $ELAPSED_TIME -gt $MAX_WAIT_SECONDS ]; then
44+
exit 1
45+
fi
46+
47+
if ! getent hosts $HEADLESS_SERVICE_NAME | grep $POD_IP; then
48+
sleep $ADDITIONAL_WAIT_SECONDS
49+
exit 0
50+
fi
3151
32-
for i in {1..$MAX_WAIT_SECONDS}
33-
do
34-
getent hosts $SERVICE_NAME | grep $POD_IP || sleep $ADDN_WAIT_SECONDS && exit 0
3552
sleep 1
3653
done
37-
38-
exit 1
3954
`

pkg/controller/elasticsearch/settings/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const (
1111
EnvProbePasswordPath = "PROBE_PASSWORD_PATH"
1212
EnvProbeUsername = "PROBE_USERNAME"
1313
EnvReadinessProbeProtocol = "READINESS_PROBE_PROTOCOL"
14-
ServiceName = "SERVICE_NAME"
14+
HeadlessServiceName = "HEADLESS_SERVICE_NAME"
1515

1616
// EnvPodName and EnvPodIP are injected as env var into the ES pod at runtime,
1717
// to be referenced in ES configuration file

test/e2e/es/mutation_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package es
66

77
import (
8+
"encoding/json"
89
"fmt"
910
"testing"
1011
"time"
@@ -250,6 +251,7 @@ func TestMutationWhileLoadTesting(t *testing.T) {
250251
w := test.NewOnceWatcher(
251252
"load test",
252253
func(k *test.K8sClient, t *testing.T) {
254+
// wait for the LoadBalancer IP to be available
253255
var ip string
254256
for {
255257
svc, err := k.GetService(b.Elasticsearch.Namespace, esv1.HTTPService(b.Elasticsearch.Name))
@@ -274,9 +276,11 @@ func TestMutationWhileLoadTesting(t *testing.T) {
274276
func(k *test.K8sClient, t *testing.T) {
275277
attacker.Stop()
276278
metrics.Close()
277-
assert.Equal(t, 1, len(metrics.StatusCodes))
279+
bytes, _ := json.Marshal(metrics)
280+
msgAndArgs := []interface{}{"metrics: %v", string(bytes)}
281+
assert.Equal(t, 1, len(metrics.StatusCodes), msgAndArgs)
278282
if _, ok := metrics.StatusCodes["401"]; !ok {
279-
assert.Fail(t, "all status codes should be 401")
283+
assert.Fail(t, "all status codes should be 401", msgAndArgs)
280284
}
281285
})
282286

0 commit comments

Comments
 (0)