Skip to content

Commit

Permalink
#51 Stale value in 'current-scaling-operation' causing ES Operator t…
Browse files Browse the repository at this point in the history
…o fail

Signed-off-by: Oliver Trosien <[email protected]>
  • Loading branch information
otrosien committed May 14, 2019
1 parent 5cb98e2 commit cde885b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions operator/es_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ func (c *ESClient) UpdateIndexSettings(indices []ESIndex) error {
}

if resp.StatusCode() != http.StatusOK {
// if the index doesn't exist ES would return a 404
if resp.StatusCode() == http.StatusNotFound {
log.Warnf("Index '%s' not found, assuming it has been deleted.", index.Index)
return nil
}
return fmt.Errorf("code status %d - %s", resp.StatusCode(), resp.Body())
}
}
Expand Down
26 changes: 26 additions & 0 deletions operator/es_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,33 @@ func TestUpdateIndexSettings(t *testing.T) {
err := systemUnderTest.UpdateIndexSettings(indices)

assert.NoError(t, err)
}

func TestUpdateIndexSettingsIgnoresUnknownIndex(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()

httpmock.RegisterResponder("GET", "http:https://elasticsearch:9200/_cluster/health",
httpmock.NewStringResponder(200, `{"status":"green"}`))
httpmock.RegisterResponder("PUT", "http:https://elasticsearch:9200/myindex/_settings",
httpmock.NewStringResponder(404, `{}`))

url, _ := url.Parse("http:https://elasticsearch:9200")
systemUnderTest := &ESClient{
Endpoint: url,
}

indices := make([]ESIndex, 0, 1)
indices = append(indices, ESIndex{
Primaries: 1,
Replicas: 1,
Index: "myindex",
})
err := systemUnderTest.UpdateIndexSettings(indices)
info := httpmock.GetCallCountInfo()

assert.NoError(t, err)
require.EqualValues(t, 0, info["GET http:https://elasticsearch:9200/myindex/_settings"])
}

func TestCreateIndex(t *testing.T) {
Expand Down

0 comments on commit cde885b

Please sign in to comment.