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

Add metadata for transform node role #3411

Merged
merged 9 commits into from
Jul 22, 2020
77 changes: 52 additions & 25 deletions pkg/apis/elasticsearch/v1/elasticsearch_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
package v1

import (
"github.com/elastic/cloud-on-k8s/pkg/controller/common/version"
"github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil"
"github.com/elastic/go-ucfg"

commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1"
)

const (
NodeData = "node.data"
NodeIngest = "node.ingest"
NodeMaster = "node.master"
NodeML = "node.ml"
NodeData = "node.data"
NodeIngest = "node.ingest"
NodeMaster = "node.master"
NodeML = "node.ml"
NodeTransform = "node.transform"

MasterRole = "master"
DataRole = "data"
IngestRole = "ingest"
MLRole = "ml"
MasterRole = "master"
DataRole = "data"
IngestRole = "ingest"
MLRole = "ml"
TransformRole = "transform"
)

// ClusterSettings is the cluster node in elasticsearch.yml.
Expand All @@ -30,11 +33,12 @@ type ClusterSettings struct {

// Node is the node section in elasticsearch.yml.
type Node struct {
Master bool `config:"master"`
Data bool `config:"data"`
Ingest bool `config:"ingest"`
ML bool `config:"ml"`
Roles []string `config:"roles"` // available as of 7.9.0, takes priority over the other fields if non-nil
Master bool `config:"master"`
Data bool `config:"data"`
Ingest bool `config:"ingest"`
ML bool `config:"ml"`
Transform bool `config:"transform"` // available as of 7.7.0
Roles []string `config:"roles"` // available as of 7.9.0, takes priority over the other fields if non-nil
}

func (n *Node) HasMasterRole() bool {
Expand Down Expand Up @@ -65,34 +69,57 @@ func (n *Node) HasMLRole() bool {
return stringsutil.StringInSlice(MLRole, n.Roles)
}

func (n *Node) HasTransformRole() bool {
if n.Roles == nil {
return n.Transform
}
return stringsutil.StringInSlice(TransformRole, n.Roles)
}

// ElasticsearchSettings is a typed subset of elasticsearch.yml for purposes of the operator.
type ElasticsearchSettings struct {
Node Node `config:"node"`
Cluster ClusterSettings `config:"cluster"`
}

// DefaultCfg is an instance of ElasticsearchSettings with defaults set as they are in Elasticsearch.
var DefaultCfg = ElasticsearchSettings{
// Values below only make senses if there is no "node.roles" in the configuration provided by the user
Node: Node{
Master: true,
Data: true,
Ingest: true,
ML: true,
},
// cfg is the user provided config we want defaults for, ver is the version of Elasticsearch.
func DefaultCfg(cfg *ucfg.Config, ver version.Version) ElasticsearchSettings {
settings := ElasticsearchSettings{
// Values below only make sense if there is no "node.roles" in the configuration provided by the user
Node: Node{
Master: true,
Data: true,
Ingest: true,
ML: true,
Transform: false,
},
}
if ver.IsSameOrAfter(version.From(7, 7, 0)) {
// this setting did not exist before 7.7.0 its default depends on the node.data value
settings.Node.Transform = true
if cfg == nil {
return settings
}
dataNode, err := cfg.Bool(NodeData, -1, commonv1.CfgOptions...)
if err == nil && !dataNode {
settings.Node.Transform = false
}
}
return settings
}

// Unpack unpacks Config into a typed subset.
pebrc marked this conversation as resolved.
Show resolved Hide resolved
func UnpackConfig(c *commonv1.Config) (ElasticsearchSettings, error) {
esSettings := DefaultCfg // defensive copy
func UnpackConfig(c *commonv1.Config, ver version.Version) (ElasticsearchSettings, error) {
if c == nil {
// make this nil safe to allow a ptr value to work around Json serialization issues
return esSettings, nil
return DefaultCfg(ucfg.New(), ver), nil
}
config, err := ucfg.NewFrom(c.Data, commonv1.CfgOptions...)
if err != nil {
return esSettings, err
return ElasticsearchSettings{}, err
}
esSettings := DefaultCfg(config, ver)
err = config.Unpack(&esSettings, commonv1.CfgOptions...)
return esSettings, err
}
Loading