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

Use Elasticsearch readiness port #7847

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
430 changes: 427 additions & 3 deletions NOTICE.txt

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion docs/reference/dependencies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/davecgh/go-spew[$$github.com/davecgh/go-spew$$] | v1.1.2-0.20180830191138-d8f796af33cc | ISC
| link:https://github.com/elastic/go-ucfg[$$github.com/elastic/go-ucfg$$] | v0.8.8 | Apache-2.0
| link:https://github.com/ghodss/yaml[$$github.com/ghodss/yaml$$] | v1.0.0 | MIT
| link:https://github.com/gkampitakis/go-snaps[$$github.com/gkampitakis/go-snaps$$] | v0.5.4 | MIT
| link:https://github.com/go-logr/logr[$$github.com/go-logr/logr$$] | v1.4.1 | Apache-2.0
| link:https://github.com/go-test/deep[$$github.com/go-test/deep$$] | v1.1.0 | MIT
| link:https://github.com/gobuffalo/flect[$$github.com/gobuffalo/flect$$] | v1.0.2 | MIT
Expand Down Expand Up @@ -93,6 +94,8 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/fatih/color[$$github.com/fatih/color$$] | v1.16.0 | MIT
| link:https://github.com/frankban/quicktest[$$github.com/frankban/quicktest$$] | v1.14.6 | MIT
| link:https://github.com/fsnotify/fsnotify[$$github.com/fsnotify/fsnotify$$] | v1.7.0 | BSD-3-Clause
| link:https://github.com/gkampitakis/ciinfo[$$github.com/gkampitakis/ciinfo$$] | v0.3.0 | MIT
| link:https://github.com/gkampitakis/go-diff[$$github.com/gkampitakis/go-diff$$] | v1.3.2 | MIT
| link:https://github.com/go-jose/go-jose[$$github.com/go-jose/go-jose/v4$$] | v4.0.1 | Apache-2.0
| link:https://github.com/go-logr/zapr[$$github.com/go-logr/zapr$$] | v1.3.0 | Apache-2.0
| link:https://github.com/go-openapi/jsonpointer[$$github.com/go-openapi/jsonpointer$$] | v0.21.0 | Apache-2.0
Expand Down Expand Up @@ -126,6 +129,7 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/kr/pretty[$$github.com/kr/pretty$$] | v0.3.1 | MIT
| link:https://github.com/kr/text[$$github.com/kr/text$$] | v0.2.0 | MIT
| link:https://github.com/mailru/easyjson[$$github.com/mailru/easyjson$$] | v0.7.7 | MIT
| link:https://github.com/maruel/natural[$$github.com/maruel/natural$$] | v1.1.1 | Apache-2.0
| link:https://github.com/mattn/go-colorable[$$github.com/mattn/go-colorable$$] | v0.1.13 | MIT
| link:https://github.com/mattn/go-isatty[$$github.com/mattn/go-isatty$$] | v0.0.20 | MIT
| link:https://github.com/mitchellh/copystructure[$$github.com/mitchellh/copystructure$$] | v1.0.0 | MIT
Expand All @@ -147,7 +151,7 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/prashantv/gostub[$$github.com/prashantv/gostub$$] | v1.1.0 | MIT
| link:https://github.com/prometheus/client_model[$$github.com/prometheus/client_model$$] | v0.6.1 | Apache-2.0
| link:https://github.com/prometheus/procfs[$$github.com/prometheus/procfs$$] | v0.14.0 | Apache-2.0
| link:https://github.com/rogpeppe/go-internal[$$github.com/rogpeppe/go-internal$$] | v1.11.0 | BSD-3-Clause
| link:https://github.com/rogpeppe/go-internal[$$github.com/rogpeppe/go-internal$$] | v1.12.0 | BSD-3-Clause
| link:https://github.com/ryanuber/go-glob[$$github.com/ryanuber/go-glob$$] | v1.0.0 | MIT
| link:https://github.com/sagikazarmark/locafero[$$github.com/sagikazarmark/locafero$$] | v0.4.0 | MIT
| link:https://github.com/sagikazarmark/slog-shim[$$github.com/sagikazarmark/slog-shim$$] | v0.1.0 | BSD-3-Clause
Expand All @@ -157,6 +161,10 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/spf13/afero[$$github.com/spf13/afero$$] | v1.11.0 | Apache-2.0
| link:https://github.com/spf13/cast[$$github.com/spf13/cast$$] | v1.6.0 | MIT
| link:https://github.com/subosito/gotenv[$$github.com/subosito/gotenv$$] | v1.6.0 | MIT
| link:https://github.com/tidwall/gjson[$$github.com/tidwall/gjson$$] | v1.17.0 | MIT
| link:https://github.com/tidwall/match[$$github.com/tidwall/match$$] | v1.1.1 | MIT
| link:https://github.com/tidwall/pretty[$$github.com/tidwall/pretty$$] | v1.2.1 | MIT
| link:https://github.com/tidwall/sjson[$$github.com/tidwall/sjson$$] | v1.2.5 | MIT
| link:https://github.com/vbatts/tar-split[$$github.com/vbatts/tar-split$$] | v0.11.3 | BSD-3-Clause
| link:https://go.elastic.co/fastjson[$$go.elastic.co/fastjson$$] | v1.3.0 | MIT
| link:https://go.uber.org/goleak[$$go.uber.org/goleak$$] | v1.3.0 | MIT
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/elastic/go-ucfg v0.8.8
github.com/ghodss/yaml v1.0.0
github.com/gkampitakis/go-snaps v0.5.4
github.com/go-logr/logr v1.4.1
github.com/go-test/deep v1.1.0
github.com/gobuffalo/flect v1.0.2
Expand Down Expand Up @@ -66,6 +67,8 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gkampitakis/ciinfo v0.3.0 // indirect
github.com/gkampitakis/go-diff v1.3.2 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
Expand All @@ -92,7 +95,10 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/maruel/natural v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
Expand All @@ -109,6 +115,7 @@ require (
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -118,6 +125,10 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/vbatts/tar-split v0.11.3 // indirect
go.elastic.co/fastjson v1.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
25 changes: 23 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ github.com/containerd/stargz-snapshotter/estargz v0.14.3 h1:OqlDCK3ZVUO6C3B/5FSk
github.com/containerd/stargz-snapshotter/estargz v0.14.3/go.mod h1:KY//uOCIkSuNAHhJogcZtrNHdKrA99/FCCRjE3HD36o=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -64,6 +65,12 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gkampitakis/ciinfo v0.3.0 h1:gWZlOC2+RYYttL0hBqcoQhM7h1qNkVqvRCV1fOvpAv8=
github.com/gkampitakis/ciinfo v0.3.0/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M=
github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk=
github.com/gkampitakis/go-snaps v0.5.4 h1:GX+dkKmVsRenz7SoTbdIEL4KQARZctkMiZ8ZKprRwT8=
github.com/gkampitakis/go-snaps v0.5.4/go.mod h1:ZABkO14uCuVxBHAXAfKG+bqNz+aa1bGPAg8jkI0Nk8Y=
github.com/go-jose/go-jose/v4 v4.0.1 h1:QVEPDE3OluqXBQZDcnNvQrInro2h0e4eqNbnZSWqS6U=
github.com/go-jose/go-jose/v4 v4.0.1/go.mod h1:WVf9LFMHh/QVrmqrOfqun0C45tMe3RoiKJMPvgWwLfY=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
Expand Down Expand Up @@ -164,6 +171,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand Down Expand Up @@ -208,6 +217,7 @@ github.com/opencontainers/image-spec v1.1.0-rc3 h1:fzg1mXZFj8YdPeNkRXMg+zb88BFV0
github.com/opencontainers/image-spec v1.1.0-rc3/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -225,8 +235,9 @@ github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+a
github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U=
github.com/prometheus/procfs v0.14.0 h1:Lw4VdGGoKEZilJsayHf0B+9YgLGREba2C6xr+Fdfq6s=
github.com/prometheus/procfs v0.14.0/go.mod h1:XL+Iwz8k8ZabyZfMFHPiilCniixqQarAy5Mu67pHlNQ=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
Expand Down Expand Up @@ -271,6 +282,16 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck=
github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY=
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/elasticsearch/v1/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

package v1

import "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version"

// as of 8.2.0 a simplified unauthenticated readiness port is available which takes cluster membership into account
// see https://www.elastic.co/guide/en/elasticsearch/reference/current/advanced-configuration.html#readiness-tcp-port
var MinReadinessPortVersion = version.MinFor(8, 2, 0)

const (
ClusterName = "cluster.name"

Expand All @@ -14,6 +20,8 @@ const (
DiscoverySeedProviders = "discovery.seed_providers" // ES >= 7.X
DiscoverySeedHosts = "discovery.seed_hosts" // ES >= 7.X

ReadinessPort = "readiness.port" // ES >= 8.2.0

NetworkHost = "network.host"
NetworkPublishHost = "network.publish_host"
HTTPPublishHost = "http.publish_host"
Expand Down
27 changes: 12 additions & 15 deletions pkg/controller/autoscaling/elasticsearch/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator"
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches"
esclient "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/client"
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/services"
eslabel "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/label"
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s"
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/net"
)
Expand All @@ -48,23 +48,20 @@ var (
return events
}

fakeService = &corev1.Service{
// fakePod is one running pod for online tests == ES considered reachable
fakePod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
Name: services.InternalServiceName("testes"),
Name: "testes-es-master",
Labels: map[string]string{
eslabel.HTTPSchemeLabelName: "http",
eslabel.StatefulSetNameLabelName: "sset",
eslabel.ClusterNameLabelName: "testes",
},
},
}
fakeEndpoints = &corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
Name: services.InternalServiceName("testes"),
Status: corev1.PodStatus{
Phase: corev1.PodRunning,
},
Subsets: []corev1.EndpointSubset{{
Addresses: []corev1.EndpointAddress{{
IP: "10.0.0.2",
}},
Ports: []corev1.EndpointPort{},
}},
}
)

Expand Down Expand Up @@ -267,7 +264,7 @@ func TestReconcile(t *testing.T) {
t.Fatalf("yaml.Unmarshal error = %v, wantErr %v", err, tt.wantErr)
}
if tt.args.isOnline {
k8sClient = k8s.NewFakeClient(es.DeepCopy(), esa.DeepCopy(), fakeService, fakeEndpoints)
k8sClient = k8s.NewFakeClient(es.DeepCopy(), esa.DeepCopy(), fakePod)
} else {
k8sClient = k8s.NewFakeClient(es.DeepCopy(), esa.DeepCopy())
}
Expand Down
28 changes: 4 additions & 24 deletions pkg/controller/autoscaling/elasticsearch/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/go-logr/logr"
"go.elastic.co/apm/v2"
apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1alpha1"
esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1"
Expand All @@ -34,17 +33,9 @@ func (r *baseReconcileAutoscaling) reconcileInternal(
) (*esv1.Elasticsearch, error) {
defer tracing.Span(&ctx)()
log := logconf.FromContext(ctx)
if esReachable, err := r.isElasticsearchReachable(ctx, es); !esReachable || err != nil {
if !r.isElasticsearchReachable(ctx, es) {
// Elasticsearch is not reachable, or we got an error while checking Elasticsearch availability, follow up with an offline reconciliation.
if err != nil {
log.V(1).Info(
"error while checking if Elasticsearch is available, attempting offline reconciliation",
"error.message", err.Error(),
)
statusBuilder.SetOnline(false, fmt.Sprintf("Error while checking if Elasticsearch is available: %s", err.Error()))
} else {
statusBuilder.SetOnline(false, "Elasticsearch is not available")
}
statusBuilder.SetOnline(false, "Elasticsearch is not available")
return r.doOfflineReconciliation(ctx, es, statusBuilder, autoscaledNodeSets, autoscalingResource)
}
statusBuilder.SetOnline(true, "Elasticsearch is available")
Expand Down Expand Up @@ -98,20 +89,9 @@ func newStatusBuilder(log logr.Logger, autoscalingPolicies v1alpha1.AutoscalingP
}

// Check if the Service is available.
func (r *baseReconcileAutoscaling) isElasticsearchReachable(ctx context.Context, es esv1.Elasticsearch) (bool, error) {
func (r *baseReconcileAutoscaling) isElasticsearchReachable(ctx context.Context, es esv1.Elasticsearch) bool {
defer tracing.Span(&ctx)()
internalService, err := services.GetInternalService(r.Client, es)
if apierrors.IsNotFound(err) {
return false, nil
}
if err != nil {
return false, tracing.CaptureError(ctx, err)
}
esReachable, err := services.IsServiceReady(r.Client, internalService)
if err != nil {
return false, tracing.CaptureError(ctx, err)
}
return esReachable, nil
return services.NewElasticsearchURLProvider(es, r.Client).HasEndpoints()
}

// attemptOnlineReconciliation attempts an online autoscaling reconciliation with a call to the Elasticsearch autoscaling API.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/common/esclient/esclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func NewClient(
es esv1.Elasticsearch,
) (esclient.Client, error) {
defer tracing.Span(&ctx)()
url := services.ExternalServiceURL(es)
v, err := version.Parse(es.Spec.Version)
if err != nil {
return nil, err
Expand Down Expand Up @@ -68,10 +67,11 @@ func NewClient(
if err != nil {
return nil, err
}

return esclient.NewElasticsearchClient(
dialer,
k8s.ExtractNamespacedName(&es),
url,
services.NewElasticsearchURLProvider(es, c),
esclient.BasicAuth{
Name: user.ControllerUserName,
Password: string(password),
Expand Down
32 changes: 16 additions & 16 deletions pkg/controller/elasticsearch/client/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
)

type baseClient struct {
User BasicAuth
HTTP *http.Client
Endpoint string
es types.NamespacedName
caCerts []*x509.Certificate
version version.Version
debug bool
User BasicAuth
HTTP *http.Client
URLProvider URLProvider
es types.NamespacedName
caCerts []*x509.Certificate
version version.Version
debug bool
}

// Close idle connections in the underlying http client.
Expand Down Expand Up @@ -57,8 +57,8 @@ func (c *baseClient) equal(c2 *baseClient) bool {
return false
}
}
// compare endpoint and user creds
return c.Endpoint == c2.Endpoint &&
// compare endpoint svc url and user creds. Service URL acts purely as an identifier here.
return c.URLProvider.Equals(c2.URLProvider) &&
c.User == c2.User
}

Expand Down Expand Up @@ -128,7 +128,11 @@ func (c *baseClient) request(
body = bytes.NewBuffer(outData)
}

request, err := http.NewRequest(method, stringsutil.Concat(c.Endpoint, pathWithQuery), body) //nolint:noctx
url, err := c.URLProvider.URL()
if err != nil {
return err
}
request, err := http.NewRequest(method, stringsutil.Concat(url, pathWithQuery), body) //nolint:noctx
if err != nil {
return err
}
Expand Down Expand Up @@ -188,11 +192,7 @@ func versioned(b *baseClient, v version.Version) Client {
}
}

func (c *baseClient) URL() string {
return c.Endpoint
}

func (c *baseClient) HasProperties(version version.Version, user BasicAuth, url string, caCerts []*x509.Certificate) bool {
func (c *baseClient) HasProperties(version version.Version, user BasicAuth, url URLProvider, caCerts []*x509.Certificate) bool {
if len(c.caCerts) != len(caCerts) {
return false
}
Expand All @@ -201,5 +201,5 @@ func (c *baseClient) HasProperties(version version.Version, user BasicAuth, url
return false
}
}
return c.version.Equals(version) && c.User == user && c.Endpoint == url
return c.version.Equals(version) && c.User == user && c.URLProvider.Equals(url)
}
Loading