diff --git a/pkg/controller/elasticsearch/client/desired_nodes.go b/pkg/controller/elasticsearch/client/desired_nodes.go index dc9ce11c75..18db6feccb 100644 --- a/pkg/controller/elasticsearch/client/desired_nodes.go +++ b/pkg/controller/elasticsearch/client/desired_nodes.go @@ -12,7 +12,7 @@ import ( ) var desiredNodesMinVersion = version.MinFor(8, 3, 0) -var DeprecatedNodeVersionReqBodyParamMinVersion = version.MinFor(8, 13, 0) +var deprecatedNodeVersionReqBodyParamMinVersion = version.MinFor(8, 13, 0) type DesiredNodesClient interface { IsDesiredNodesSupported() bool @@ -74,6 +74,12 @@ func (c *clientV8) GetLatestDesiredNodes(ctx context.Context) (LatestDesiredNode } func (c *clientV8) UpdateDesiredNodes(ctx context.Context, historyID string, version int64, desiredNodes DesiredNodes) error { + // remove deprecated field depending on the version + if c.version.GTE(deprecatedNodeVersionReqBodyParamMinVersion) { + for i := range desiredNodes.DesiredNodes { + desiredNodes.DesiredNodes[i].NodeVersion = "" + } + } return c.put( ctx, fmt.Sprintf("/_internal/desired_nodes/%s/%d", historyID, version), diff --git a/pkg/controller/elasticsearch/driver/desired_nodes.go b/pkg/controller/elasticsearch/driver/desired_nodes.go index a66cfa0ad0..af9c40af14 100644 --- a/pkg/controller/elasticsearch/driver/desired_nodes.go +++ b/pkg/controller/elasticsearch/driver/desired_nodes.go @@ -37,7 +37,7 @@ func (d *defaultDriver) updateDesiredNodes( if err != nil { return results.WithError(err) } - nodes, requeue, err := expectedResources.ToDesiredNodes(ctx, d.Client, esVersion) + nodes, requeue, err := expectedResources.ToDesiredNodes(ctx, d.Client, esVersion.FinalizeVersion()) switch { case err == nil: d.ReconcileState.ReportCondition( diff --git a/pkg/controller/elasticsearch/nodespec/desired_nodes.go b/pkg/controller/elasticsearch/nodespec/desired_nodes.go index c63acead62..5fa7ff336c 100644 --- a/pkg/controller/elasticsearch/nodespec/desired_nodes.go +++ b/pkg/controller/elasticsearch/nodespec/desired_nodes.go @@ -19,7 +19,6 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" sset "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/statefulset" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/settings" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" @@ -227,7 +226,7 @@ const ( func (l ResourcesList) ToDesiredNodes( ctx context.Context, k8sClient k8s.Client, - version version.Version, + version string, ) (desiredNodes []client.DesiredNode, requeue bool, err error) { span, ctx := apm.StartSpan(ctx, "compute_desired_nodes", tracing.SpanTypeApp) defer span.End() @@ -267,7 +266,7 @@ func (l ResourcesList) ToDesiredNodes( }) node := client.DesiredNode{ - NodeVersion: emptyIfDeprecated(version, client.DeprecatedNodeVersionReqBodyParamMinVersion), + NodeVersion: version, ProcessorsRange: nodeResource.cpu, Memory: fmt.Sprintf("%db", nodeResource.memory), Storage: fmt.Sprintf("%db", nodeResource.storage), @@ -280,15 +279,6 @@ func (l ResourcesList) ToDesiredNodes( return desiredNodes, requeue, nil } -// emptyIfDeprecated returns an empty string if the version is greater than equal to the deprecated version, -// else the finalized version. -func emptyIfDeprecated(version, deprecatedMinVersion version.Version) string { - if version.GTE(deprecatedMinVersion) { - return "" - } - return version.FinalizeVersion() -} - // visit recursively visits a map holding a tree structure and apply a function to nodes that hold a string. func visit(keys []string, m map[string]interface{}, apply func(string) string) { for k, v := range m {