Skip to content

Commit b162f18

Browse files
authored
Version gate to deprecate node_version using update desired nodes API (#7628)
1 parent af7a019 commit b162f18

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

pkg/controller/elasticsearch/client/desired_nodes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
var desiredNodesMinVersion = version.MinFor(8, 3, 0)
15+
var DeprecatedNodeVersionReqBodyParamMinVersion = version.MinFor(8, 13, 0)
1516

1617
type DesiredNodesClient interface {
1718
IsDesiredNodesSupported() bool
@@ -38,7 +39,7 @@ type DesiredNode struct {
3839
ProcessorsRange ProcessorsRange `json:"processors_range"`
3940
Memory string `json:"memory"`
4041
Storage string `json:"storage"`
41-
NodeVersion string `json:"node_version"`
42+
NodeVersion string `json:"node_version,omitempty"` // deprecated in 8.13+
4243
}
4344

4445
type ProcessorsRange struct {

pkg/controller/elasticsearch/driver/desired_nodes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (d *defaultDriver) updateDesiredNodes(
3737
if err != nil {
3838
return results.WithError(err)
3939
}
40-
nodes, requeue, err := expectedResources.ToDesiredNodes(ctx, d.Client, esVersion.FinalizeVersion())
40+
nodes, requeue, err := expectedResources.ToDesiredNodes(ctx, d.Client, esVersion)
4141
switch {
4242
case err == nil:
4343
d.ReconcileState.ReportCondition(

pkg/controller/elasticsearch/nodespec/desired_nodes.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1"
2020
sset "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/statefulset"
2121
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing"
22+
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version"
2223
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/client"
2324
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/settings"
2425
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s"
@@ -226,7 +227,7 @@ const (
226227
func (l ResourcesList) ToDesiredNodes(
227228
ctx context.Context,
228229
k8sClient k8s.Client,
229-
version string,
230+
version version.Version,
230231
) (desiredNodes []client.DesiredNode, requeue bool, err error) {
231232
span, ctx := apm.StartSpan(ctx, "compute_desired_nodes", tracing.SpanTypeApp)
232233
defer span.End()
@@ -266,7 +267,7 @@ func (l ResourcesList) ToDesiredNodes(
266267
})
267268

268269
node := client.DesiredNode{
269-
NodeVersion: version,
270+
NodeVersion: emptyIfDeprecated(version, client.DeprecatedNodeVersionReqBodyParamMinVersion),
270271
ProcessorsRange: nodeResource.cpu,
271272
Memory: fmt.Sprintf("%db", nodeResource.memory),
272273
Storage: fmt.Sprintf("%db", nodeResource.storage),
@@ -279,6 +280,15 @@ func (l ResourcesList) ToDesiredNodes(
279280
return desiredNodes, requeue, nil
280281
}
281282

283+
// emptyIfDeprecated returns an empty string if the version is greater than equal to the deprecated version,
284+
// else the finalized version.
285+
func emptyIfDeprecated(version, deprecatedMinVersion version.Version) string {
286+
if version.GTE(deprecatedMinVersion) {
287+
return ""
288+
}
289+
return version.FinalizeVersion()
290+
}
291+
282292
// visit recursively visits a map holding a tree structure and apply a function to nodes that hold a string.
283293
func visit(keys []string, m map[string]interface{}, apply func(string) string) {
284294
for k, v := range m {

0 commit comments

Comments
 (0)