Skip to content

Commit

Permalink
Revert "Revert "Move desired nodes version gate in the client (#7663)""
Browse files Browse the repository at this point in the history
This reverts commit a411102.
  • Loading branch information
thbkrkr committed Mar 28, 2024
1 parent 0564371 commit 209d82c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
8 changes: 7 additions & 1 deletion pkg/controller/elasticsearch/client/desired_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/driver/desired_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 2 additions & 12 deletions pkg/controller/elasticsearch/nodespec/desired_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand All @@ -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 {
Expand Down

0 comments on commit 209d82c

Please sign in to comment.