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

Use new node_names query param for voting exclusions as of 7.8.0 #3950

Merged
merged 2 commits into from
Nov 18, 2020
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
2 changes: 2 additions & 0 deletions pkg/controller/elasticsearch/client/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type baseClient struct {
HTTP *http.Client
Endpoint string
caCerts []*x509.Certificate
version version.Version
}

// Close idle connections in the underlying http client.
Expand Down Expand Up @@ -129,6 +130,7 @@ func (c *baseClient) request(
}

func versioned(b *baseClient, v version.Version) Client {
b.version = v
v6 := clientV6{
baseClient: *b,
}
Expand Down
22 changes: 18 additions & 4 deletions pkg/controller/elasticsearch/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,10 @@ func TestClient_Equal(t *testing.T) {

func TestClient_AddVotingConfigExclusions(t *testing.T) {
tests := []struct {
expectedPath string
version version.Version
wantErr bool
expectedPath string
expectedQuery string
version version.Version
wantErr bool
}{
{
expectedPath: "",
Expand All @@ -458,11 +459,24 @@ func TestClient_AddVotingConfigExclusions(t *testing.T) {
version: version.MustParse("7.0.0"),
wantErr: false,
},
{
expectedPath: "/_cluster/voting_config_exclusions",
expectedQuery: "node_names=a,b",
version: version.MustParse("7.8.0"),
wantErr: false,
},
{
expectedPath: "/_cluster/voting_config_exclusions",
expectedQuery: "node_names=a,b",
version: version.MustParse("8.0.0"),
wantErr: false,
},
}

for _, tt := range tests {
client := NewMockClient(tt.version, func(req *http.Request) *http.Response {
require.Equal(t, tt.expectedPath, req.URL.Path)
require.Equal(t, tt.expectedPath, req.URL.Path, tt.version)
require.Equal(t, tt.expectedQuery, req.URL.RawQuery, tt.version)
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader("")),
Expand Down
9 changes: 8 additions & 1 deletion pkg/controller/elasticsearch/client/v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"github.com/elastic/cloud-on-k8s/pkg/controller/common/version"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -42,7 +43,13 @@ func (c *clientV7) StartTrial(ctx context.Context) (StartTrialResponse, error) {
}

func (c *clientV7) AddVotingConfigExclusions(ctx context.Context, nodeNames []string) error {
path := fmt.Sprintf("/_cluster/voting_config_exclusions/%s", strings.Join(nodeNames, ","))
var path string
if c.version.IsSameOrAfter(version.From(7, 8, 0)) {
path = fmt.Sprintf("/_cluster/voting_config_exclusions?node_names=%s", strings.Join(nodeNames, ","))
} else {
// versions < 7.8.0 or unversioned clients which is OK as this deprecated API will be supported until 8.0
path = fmt.Sprintf("/_cluster/voting_config_exclusions/%s", strings.Join(nodeNames, ","))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If c.version is empty (client constructed from client.NewElasticsearchClient()), we end up in this else path, which is fine.
Maybe worth explicitly pointing out in a comment though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow your argument wrt to client.NewElasticsearchClient() but I added a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant client which do not have a version set, which I think is the case when built from client.NewElasticsearchClient().
I'm 👍 with the comment.

}

if err := c.post(ctx, path, nil, nil); err != nil {
return errors.Wrap(err, "unable to add to voting_config_exclusions")
Expand Down
14 changes: 13 additions & 1 deletion pkg/controller/elasticsearch/client/v8.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ package client

import (
"context"
"errors"
"fmt"
"strings"

"github.com/pkg/errors"
)

type clientV8 struct {
clientV7
}

func (c *clientV8) AddVotingConfigExclusions(ctx context.Context, nodeNames []string) error {
path := fmt.Sprintf("/_cluster/voting_config_exclusions?node_names=%s", strings.Join(nodeNames, ","))

if err := c.post(ctx, path, nil, nil); err != nil {
return errors.Wrap(err, "unable to add to voting_config_exclusions")
}
return nil
}

func (c *clientV8) SyncedFlush(ctx context.Context) error {
return errors.New("synced flush is not supported in Elasticsearch 8.x")
}
Expand Down