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

Move desired nodes version gate in the client #7663

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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