From 0b26bcec022ea6724cb635e82ee674b76a04106d Mon Sep 17 00:00:00 2001 From: Thibault Richard Date: Wed, 27 Mar 2024 11:52:31 +0100 Subject: [PATCH 1/3] Revert "Version gate to deprecate node_version using update desired nodes API (#7628)" This reverts commit b162f18b1402a1975cb213ad48aa2eda09c1d921. --- .../elasticsearch/client/desired_nodes.go | 3 +-- .../elasticsearch/driver/desired_nodes.go | 2 +- .../elasticsearch/nodespec/desired_nodes.go | 14 ++------------ 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/controller/elasticsearch/client/desired_nodes.go b/pkg/controller/elasticsearch/client/desired_nodes.go index dc9ce11c75..43de82ddd1 100644 --- a/pkg/controller/elasticsearch/client/desired_nodes.go +++ b/pkg/controller/elasticsearch/client/desired_nodes.go @@ -12,7 +12,6 @@ import ( ) var desiredNodesMinVersion = version.MinFor(8, 3, 0) -var DeprecatedNodeVersionReqBodyParamMinVersion = version.MinFor(8, 13, 0) type DesiredNodesClient interface { IsDesiredNodesSupported() bool @@ -39,7 +38,7 @@ type DesiredNode struct { ProcessorsRange ProcessorsRange `json:"processors_range"` Memory string `json:"memory"` Storage string `json:"storage"` - NodeVersion string `json:"node_version,omitempty"` // deprecated in 8.13+ + NodeVersion string `json:"node_version"` } type ProcessorsRange struct { 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 { From e4baec29a685e7e5b7c73149f104233ab8b4f273 Mon Sep 17 00:00:00 2001 From: Thibault Richard Date: Wed, 27 Mar 2024 11:58:40 +0100 Subject: [PATCH 2/3] remove deprecated field in the client which has the es minVersion --- pkg/controller/elasticsearch/client/desired_nodes.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/controller/elasticsearch/client/desired_nodes.go b/pkg/controller/elasticsearch/client/desired_nodes.go index 43de82ddd1..b4e9f9c271 100644 --- a/pkg/controller/elasticsearch/client/desired_nodes.go +++ b/pkg/controller/elasticsearch/client/desired_nodes.go @@ -12,6 +12,7 @@ import ( ) var desiredNodesMinVersion = version.MinFor(8, 3, 0) +var deprecatedNodeVersionReqBodyParamMinVersion = version.MinFor(8, 13, 0) type DesiredNodesClient interface { IsDesiredNodesSupported() bool @@ -38,7 +39,7 @@ type DesiredNode struct { ProcessorsRange ProcessorsRange `json:"processors_range"` Memory string `json:"memory"` Storage string `json:"storage"` - NodeVersion string `json:"node_version"` + NodeVersion string `json:"node_version"` // deprecated in 8.13+ } type ProcessorsRange struct { @@ -73,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), From 55e8e4a080e5636605e2aa7dc1d2300842e25ece Mon Sep 17 00:00:00 2001 From: Thibault Richard Date: Wed, 27 Mar 2024 14:08:16 +0100 Subject: [PATCH 3/3] Update pkg/controller/elasticsearch/client/desired_nodes.go --- pkg/controller/elasticsearch/client/desired_nodes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/elasticsearch/client/desired_nodes.go b/pkg/controller/elasticsearch/client/desired_nodes.go index b4e9f9c271..18db6feccb 100644 --- a/pkg/controller/elasticsearch/client/desired_nodes.go +++ b/pkg/controller/elasticsearch/client/desired_nodes.go @@ -39,7 +39,7 @@ type DesiredNode struct { ProcessorsRange ProcessorsRange `json:"processors_range"` Memory string `json:"memory"` Storage string `json:"storage"` - NodeVersion string `json:"node_version"` // deprecated in 8.13+ + NodeVersion string `json:"node_version,omitempty"` // deprecated in 8.13+ } type ProcessorsRange struct {