Skip to content

Commit

Permalink
Use discovery.seed_providers instead of discovery.zen.hosts_provider …
Browse files Browse the repository at this point in the history
…starting 7.x (#2029)

* Use discovery.seed_providers instead of discovery.zen.hosts_provider

Starting Elasticsearch 7.0, `discovery.zen.hosts_provider` is deprecated
in favor of `discovery.seed_providers`.
The setting is removed in 8.0, preventing any 8.0 cluster to bootstrap.

This commit switches over the Elasticsearch version when building the
elasticsearch.yml configuration, to make sure versions lower than 7.0
use `discovery.zen.hosts_provider`, and other versions use the newer
`discovery.seed_providers`.
  • Loading branch information
sebgl authored Oct 21, 2019
1 parent dcee46a commit 473267f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/nodespec/podspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestBuildPodTemplateSpec(t *testing.T) {
Labels: map[string]string{
"common.k8s.elastic.co/type": "elasticsearch",
"elasticsearch.k8s.elastic.co/cluster-name": "name",
"elasticsearch.k8s.elastic.co/config-hash": "593041036",
"elasticsearch.k8s.elastic.co/config-hash": "1308765141",
"elasticsearch.k8s.elastic.co/http-scheme": "https",
"elasticsearch.k8s.elastic.co/node-data": "false",
"elasticsearch.k8s.elastic.co/node-ingest": "true",
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/elasticsearch/settings/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const (

DiscoveryZenMinimumMasterNodes = "discovery.zen.minimum_master_nodes"
ClusterInitialMasterNodes = "cluster.initial_master_nodes"
DiscoveryZenHostsProvider = "discovery.zen.hosts_provider"

DiscoveryZenHostsProvider = "discovery.zen.hosts_provider" // ES < 7.X
DiscoverySeedProviders = "discovery.seed_providers" // ES >= 7.X

NetworkHost = "network.host"
NetworkPublishHost = "network.publish_host"
Expand Down
15 changes: 11 additions & 4 deletions pkg/controller/elasticsearch/settings/merged_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewMergedESConfig(
return CanonicalConfig{}, err
}
err = config.MergeWith(
baseConfig(clusterName).CanonicalConfig,
baseConfig(clusterName, ver).CanonicalConfig,
xpackConfig(ver, httpConfig, certResources).CanonicalConfig,
)
if err != nil {
Expand All @@ -39,21 +39,28 @@ func NewMergedESConfig(
}

// baseConfig returns the base ES configuration to apply for the given cluster
func baseConfig(clusterName string) *CanonicalConfig {
func baseConfig(clusterName string, ver version.Version) *CanonicalConfig {
cfg := map[string]interface{}{
// derive node name dynamically from the pod name, injected as env var
NodeName: "${" + EnvPodName + "}",
ClusterName: clusterName,

DiscoveryZenHostsProvider: "file",

// derive IP dynamically from the pod IP, injected as env var
NetworkPublishHost: "${" + EnvPodIP + "}",
NetworkHost: "0.0.0.0",

PathData: volume.ElasticsearchDataMountPath,
PathLogs: volume.ElasticsearchLogsMountPath,
}

// seed hosts setting name changed starting ES 7.X
fileProvider := "file"
if ver.Major < 7 {
cfg[DiscoveryZenHostsProvider] = fileProvider
} else {
cfg[DiscoverySeedProviders] = fileProvider
}

return &CanonicalConfig{common.MustCanonicalConfig(cfg)}
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/controller/elasticsearch/settings/merged_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ func TestNewMergedESConfig(t *testing.T) {
require.Equal(t, 1, len(cfg.HasKeys([]string{xPackSecurityAuthcRealmsNativeNative1Order})))
},
},
{
name: "in 6.x, seed hosts setting should be discovery.zen.hosts_provider",
version: "6.8.0",
cfgData: map[string]interface{}{},
assert: func(cfg CanonicalConfig) {
require.Equal(t, 1, len(cfg.HasKeys([]string{DiscoveryZenHostsProvider})))
require.Equal(t, 0, len(cfg.HasKeys([]string{DiscoverySeedProviders})))
},
},
{
name: "starting 7.x, seed hosts settings should be discovery.seed_providers",
version: "7.0.0",
cfgData: map[string]interface{}{},
assert: func(cfg CanonicalConfig) {
require.Equal(t, 0, len(cfg.HasKeys([]string{DiscoveryZenHostsProvider})))
require.Equal(t, 1, len(cfg.HasKeys([]string{DiscoverySeedProviders})))
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 473267f

Please sign in to comment.