Skip to content

Commit 9752350

Browse files
authored
[CI] Update cluster script to handle Security On by default auth (#333)
* CI: Update cluster script to handle Security On by default auth
1 parent 71e5613 commit 9752350

File tree

14 files changed

+35
-11
lines changed

14 files changed

+35
-11
lines changed

.ci/functions/imports.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ if [[ -z $es_node_name ]]; then
2626
export es_node_name=instance
2727
export elastic_password=changeme
2828
export elasticsearch_image=elasticsearch
29-
export elasticsearch_url=https://elastic:${elastic_password}@${es_node_name}:9200
29+
export elasticsearch_scheme="https"
3030
if [[ $TEST_SUITE != "platinum" ]]; then
31-
export elasticsearch_url=http://${es_node_name}:9200
31+
export elasticsearch_scheme="http"
3232
fi
33+
export elasticsearch_url=${elasticsearch_scheme}://elastic:${elastic_password}@${es_node_name}:9200
3334
export external_elasticsearch_url=${elasticsearch_url/$es_node_name/localhost}
3435
export elasticsearch_container="${elasticsearch_image}:${STACK_VERSION}"
3536

.ci/run-elasticsearch.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Export the TEST_SUITE variable, eg. 'free' or 'platinum' defaults to 'free'.
88
# Export the NUMBER_OF_NODES variable to start more than 1 node
99

10-
# Version 1.4.0
10+
# Version 1.5.0
1111
# - Initial version of the run-elasticsearch.sh script
1212
# - Deleting the volume should not dependent on the container still running
1313
# - Fixed `ES_JAVA_OPTS` config
@@ -18,6 +18,7 @@
1818
# - Added flags to make local CCR configurations work
1919
# - Added action.destructive_requires_name=false as the default will be true in v8
2020
# - Added ingest.geoip.downloader.enabled=false as it causes false positives in testing
21+
# - Moved ELASTIC_PASSWORD to the base arguments for "Security On by default"
2122

2223
script_path=$(dirname $(realpath -s $0))
2324
source $script_path/functions/imports.sh
@@ -31,6 +32,7 @@ cluster_name=${moniker}${suffix}
3132

3233
declare -a volumes
3334
environment=($(cat <<-END
35+
--env ELASTIC_PASSWORD=$elastic_password
3436
--env node.name=$es_node_name
3537
--env cluster.name=$cluster_name
3638
--env cluster.initial_master_nodes=$master_node_name
@@ -42,12 +44,10 @@ environment=($(cat <<-END
4244
--env repositories.url.allowed_urls=http://snapshot.test*
4345
--env action.destructive_requires_name=false
4446
--env ingest.geoip.downloader.enabled=false
45-
--env xpack.security.enabled=false
4647
END
4748
))
4849
if [[ "$TEST_SUITE" == "platinum" ]]; then
4950
environment+=($(cat <<-END
50-
--env ELASTIC_PASSWORD=$elastic_password
5151
--env xpack.license.self_generated.type=trial
5252
--env xpack.security.enabled=true
5353
--env xpack.security.http.ssl.enabled=true

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ endif
3131
$(eval testintegargs += "-cover" "-coverprofile=tmp/integration-client.cov" "-tags='$(testintegtags)'" "-timeout=1h")
3232
@mkdir -p tmp
3333
@if which gotestsum > /dev/null 2>&1 ; then \
34+
export ELASTICSEARCH_URL='http://elastic:elastic@localhost:9200'; \
3435
echo "gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml --" $(testintegargs); \
3536
gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "."; \
3637
gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "./estransport" "./esapi" "./esutil"; \
3738
else \
39+
export ELASTICSEARCH_URL='http://elastic:elastic@localhost:9200'; \
3840
echo "go test -v" $(testintegargs) "."; \
3941
go test -v $(testintegargs) "./estransport" "./esapi" "./esutil"; \
4042
fi;
@@ -72,7 +74,7 @@ ifeq ($(flavor), platinum)
7274
}
7375
else
7476
$(eval testapiargs += $(PWD)/esapi/test/*_test.go)
75-
@{ \
77+
{ \
7678
set -e ; \
7779
trap "test -d .git && git checkout --quiet $(PWD)/esapi/test/go.mod" INT TERM EXIT; \
7880
if which gotestsum > /dev/null 2>&1 ; then \
@@ -113,7 +115,7 @@ test-examples: ## Execute the _examples
113115
printf "\033[2m────────────────────────────────────────────────────────────────────────────────\n"; \
114116
printf "\033[1m$$f\033[0m\n"; \
115117
printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
116-
(go run $$f && true) || \
118+
(export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200 && go run $$f && true) || \
117119
( \
118120
printf "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \
119121
printf "\033[31;1m⨯ ERROR\033[0m\n"; \
@@ -286,6 +288,7 @@ else
286288
$(eval detach ?= "false")
287289
endif
288290

291+
$(eval elasticsearch_url = "http://elastic:elastic@es1:9200")
289292
ifeq ($(flavor), platinum)
290293
$(eval elasticsearch_url = "https://elastic:elastic@es1:9200")
291294
$(eval xpack_env += --env "ELASTIC_PASSWORD=elastic")
@@ -315,6 +318,7 @@ endif
315318
docker run \
316319
--name "es$$n" \
317320
--network elasticsearch \
321+
--env "ELASTIC_PASSWORD=elastic" \
318322
--env "node.name=es$$n" \
319323
--env "cluster.name=go-elasticsearch" \
320324
--env "cluster.initial_master_nodes=es1" \
@@ -324,7 +328,6 @@ endif
324328
--env "node.attr.testattr=test" \
325329
--env "path.repo=/tmp" \
326330
--env "repositories.url.allowed_urls=http://snapshot.test*" \
327-
--env "xpack.security.enabled=false" \
328331
--env ES_JAVA_OPTS="-Xms1g -Xmx1g" \
329332
$(xpack_env) \
330333
--volume `echo $(version) | tr -C "[:alnum:]" '-'`-node-$$n-data:/usr/share/elasticsearch/data \

_examples/bulk/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: test-default test-indexer
45

_examples/bulk/benchmarks/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replace github.com/elastic/go-elasticsearch/v8 => ../../..
66

77
require (
88
github.com/dustin/go-humanize v1.0.0
9-
github.com/elastic/go-elasticsearch/v8 master
9+
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210817150010-57d659deaca7
1010
github.com/mailru/easyjson v0.7.1
1111
github.com/montanaflynn/stats v0.6.3
1212
github.com/valyala/fasthttp v1.9.0

_examples/cloudfunction/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: ## Run tests
45
$(GO_TEST_CMD) -v ./...

_examples/encoding/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: clean setup ## Run tests
45
go run gjson.go

_examples/extension/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: ## Run tests
45
go run main.go

_examples/fasthttp/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: ## Run tests
45
go run cmd/main.go

_examples/instrumentation/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
2+
13
test:
24
go build -o /dev/null expvar.go
35
go build -o /dev/null opencensus.go

_examples/logging/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: ## Run tests
45
go run default.go

_examples/security/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
2+
13
test:
24
@for file in ./*.go; do \
35
echo "go build -o /dev/null $$file"; \

_examples/xkcdsearch/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GO_TEST_CMD = $(if $(shell which richgo),richgo test,go test)
2+
export ELASTICSEARCH_URL=http://elastic:elastic@localhost:9200
23

34
test: ## Run tests
45
$(GO_TEST_CMD) -v ./...

estransport/estransport_integration_test.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"net/http"
2828
"net/http/httptest"
2929
"net/url"
30+
"os"
3031
"strings"
3132
"testing"
3233

@@ -116,8 +117,16 @@ func TestTransportCompression(t *testing.T) {
116117
var req *http.Request
117118
var res *http.Response
118119
var err error
119-
120-
u, _ := url.Parse("http://localhost:9200")
120+
var u *url.URL
121+
122+
if envURL, ok := os.LookupEnv("ELASTICSEARCH_URL"); ok && envURL != "" {
123+
u, err = url.Parse(envURL)
124+
if err != nil {
125+
t.Fatalf("Cannot parse ELASTICSEARCH_URL: %v", err)
126+
}
127+
} else {
128+
u, _ = url.Parse("http://localhost:9200")
129+
}
121130

122131
transport, _ := estransport.New(estransport.Config{
123132
URLs: []*url.URL{u},

0 commit comments

Comments
 (0)