Skip to content

Commit

Permalink
ES-Operator doesn't separate system indices and ordinary users indices.
Browse files Browse the repository at this point in the history
Closes #161

Signed-off-by: Oliver <oliver.trosien@zalando.de>
  • Loading branch information
otrosien committed May 14, 2021
1 parent 5438f14 commit 9342f93
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/zalando.org_elasticsearchdatasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ spec:
spec:
description: ElasticsearchDataSetSpec is the spec part of the Elasticsearch dataset.
properties:
excludeSystemIndices:
description: Exclude management of System Indices on this Data Set. Defaults to false
type: boolean
replicas:
description: Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
format: int32
Expand Down
3 changes: 3 additions & 0 deletions docs/zalando.org_elasticsearchdatasets_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ spec:
spec:
description: ElasticsearchDataSetSpec is the spec part of the Elasticsearch dataset.
properties:
excludeSystemIndices:
description: Exclude management of System Indices on this Data Set. Defaults to false
type: boolean
replicas:
description: Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
format: int32
Expand Down
1 change: 1 addition & 0 deletions operator/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (o *ElasticsearchOperator) runAutoscaler(ctx context.Context) {

client := &ESClient{
Endpoint: endpoint,
excludeSystemIndices: es.ElasticsearchDataSet.Spec.ExcludeSystemIndices,
}

err := o.scaleEDS(ctx, es.ElasticsearchDataSet, es, client)
Expand Down
11 changes: 8 additions & 3 deletions operator/es_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var (

// ESClient is a pod drainer which can drain data from Elasticsearch pods.
type ESClient struct {
Endpoint *url.URL
mux sync.Mutex
Endpoint *url.URL
mux sync.Mutex
excludeSystemIndices bool
}

// ESIndex represent an index to be used in public APIs
Expand Down Expand Up @@ -388,9 +389,13 @@ func (c *ESClient) GetIndices() ([]ESIndex, error) {
return nil, err
}

// HACK: after-the-fact conversion of strings to integers from ES response.
returnStruct := make([]ESIndex, 0, len(esIndices))
for _, index := range esIndices {
// ignore system indices
if c.excludeSystemIndices && index.Index[0:1] == "." {
continue
}
// HACK: after-the-fact conversion of strings to integers from ES response.
primaries, err := strconv.Atoi(index.Primaries)
if err != nil {
return nil, err
Expand Down
28 changes: 24 additions & 4 deletions operator/es_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func TestGetIndices(t *testing.T) {

assert.NoError(t, err)

require.EqualValues(t, 3, len(indices))
require.EqualValues(t, "a", indices[0].Index)
require.EqualValues(t, 2, indices[0].Primaries)
require.EqualValues(t, 1, indices[0].Replicas)
require.EqualValues(t, 3, len(indices), indices)
require.EqualValues(t, "a", indices[0].Index, indices)
require.EqualValues(t, 2, indices[0].Primaries, indices)
require.EqualValues(t, 1, indices[0].Replicas, indices)

}

Expand Down Expand Up @@ -239,3 +239,23 @@ func TestEnsureGreenClusterState(t *testing.T) {

assert.Error(t, err)
}

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

httpmock.RegisterResponder("GET", "http://elasticsearch:9200/_cat/indices",
httpmock.NewStringResponder(200, `[{"index":".system","pri":"1","rep":"1"},{"index":"a","pri":"1","rep":"1"}]`))

url, _ := url.Parse("http://elasticsearch:9200")
systemUnderTest := &ESClient{
Endpoint: url,
excludeSystemIndices: true,
}
indices, err := systemUnderTest.GetIndices()

assert.NoError(t, err)
assert.Equal(t, 1, len(indices), indices)
assert.Equal(t, "a", indices[0].Index, indices)

}
4 changes: 4 additions & 0 deletions pkg/apis/zalando.org/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type ElasticsearchDataSetSpec struct {
// +optional
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`

// Exclude management of System Indices on this Data Set. Defaults to false
// +optional
ExcludeSystemIndices bool `json:"excludeSystemIndices"`

// // serviceName is the name of the service that governs this StatefulSet.
// // This service must exist before the StatefulSet, and is responsible for
// // the network identity of the set. Pods get DNS/hostnames that follow the
Expand Down

0 comments on commit 9342f93

Please sign in to comment.