Skip to content
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
3 changes: 3 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const (
ElasticsearchDefaultImage = "quay.io/openshift/origin-logging-elasticsearch6"
ProxyDefaultImage = "quay.io/openshift/origin-elasticsearch-proxy:latest"
TheoreticalShardMaxSizeInMB = 40960

// OcpTemplatePrefix is the prefix all operator generated templates
OcpTemplatePrefix = "ocp-gen"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion pkg/elasticsearch/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"

"github.com/openshift/elasticsearch-operator/pkg/constants"
"github.com/openshift/elasticsearch-operator/pkg/log"
estypes "github.com/openshift/elasticsearch-operator/pkg/types/elasticsearch"
"github.com/openshift/elasticsearch-operator/pkg/utils"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (ec *esClient) ListTemplates() (sets.String, error) {
func (ec *esClient) GetIndexTemplates() (map[string]estypes.GetIndexTemplate, error) {
payload := &EsRequest{
Method: http.MethodGet,
URI: "_template/common.*",
URI: fmt.Sprintf("_template/common.*,%s-*", constants.OcpTemplatePrefix),
}

ec.fnSendEsRequest(ec.cluster, ec.namespace, payload, ec.k8sClient)
Expand Down
22 changes: 15 additions & 7 deletions pkg/k8shandler/index_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import (
"k8s.io/apimachinery/pkg/util/sets"

logging "github.com/openshift/elasticsearch-operator/pkg/apis/logging/v1"
"github.com/openshift/elasticsearch-operator/pkg/constants"
"github.com/openshift/elasticsearch-operator/pkg/indexmanagement"
"github.com/openshift/elasticsearch-operator/pkg/log"
esapi "github.com/openshift/elasticsearch-operator/pkg/types/elasticsearch"
)

const (
//ocpTemplatePrefix is the prefix all operator generated templates
ocpTemplatePrefix = "ocp-gen"
)

func (er *ElasticsearchRequest) CreateOrUpdateIndexManagement() error {

cluster := er.cluster
Expand Down Expand Up @@ -80,7 +76,7 @@ func (er *ElasticsearchRequest) cullIndexManagement(mappings []logging.IndexMana
difference := existing.Difference(mappingNames)

for _, template := range difference.List() {
if strings.HasPrefix(template, ocpTemplatePrefix) {
if strings.HasPrefix(template, constants.OcpTemplatePrefix) {
if err := esClient.DeleteIndexTemplate(template); err != nil {
log.Error(err, "Unable to delete stale template in order to reconcile", "template", template)
}
Expand Down Expand Up @@ -112,7 +108,7 @@ func (er *ElasticsearchRequest) initializeIndexIfNeeded(mapping logging.IndexMan
}

func formatTemplateName(name string) string {
return fmt.Sprintf("%s-%s", ocpTemplatePrefix, name)
return fmt.Sprintf("%s-%s", constants.OcpTemplatePrefix, name)
}

func formatWriteAlias(mapping logging.IndexManagementPolicyMappingSpec) string {
Expand All @@ -130,5 +126,17 @@ func (er *ElasticsearchRequest) createOrUpdateIndexTemplate(mapping logging.Inde
aliases := append(mapping.Aliases, mapping.Name)
template := esapi.NewIndexTemplate(pattern, aliases, primaryShards, replicas)

// check to compare the current index templates vs what we just generated
templates, err := esClient.GetIndexTemplates()
if err != nil {
return err
}

for templateName := range templates {
if templateName == name {
return nil
}
}

return esClient.CreateIndexTemplate(name, template)
}
13 changes: 12 additions & 1 deletion pkg/k8shandler/index_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/gomega"

elasticsearch "github.com/openshift/elasticsearch-operator/pkg/apis/logging/v1"
"github.com/openshift/elasticsearch-operator/pkg/constants"
"github.com/openshift/elasticsearch-operator/test/helpers"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -97,8 +98,18 @@ var _ = Describe("Index Management", func() {
})
Describe("#createOrUpdateIndexTemplate", func() {
BeforeEach(func() {

templateURI := fmt.Sprintf("_template/common.*,%s-*", constants.OcpTemplatePrefix)

chatter = helpers.NewFakeElasticsearchChatter(
map[string]helpers.FakeElasticsearchResponses{
templateURI: {
{
Error: nil,
StatusCode: 200,
Body: `{}`,
},
},
"_template/ocp-gen-node.infra": {
{
Error: nil,
Expand All @@ -108,7 +119,7 @@ var _ = Describe("Index Management", func() {
},
},
)
request.esClient = helpers.NewFakeElasticsearchClient("elastichsearch", "openshift-logging", request.client, chatter)
request.esClient = helpers.NewFakeElasticsearchClient("elasticsearch", "openshift-logging", request.client, chatter)
})
It("should create an elasticsearch index template to support the index", func() {
Expect(request.createOrUpdateIndexTemplate(mapping)).To(BeNil())
Expand Down
9 changes: 9 additions & 0 deletions pkg/k8shandler/migrations/pvc_naming.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package migrations

func (mr *migrationRequest) createRenamedPVC() error {
return nil
}

func (mr *migrationRequest) rebindPV() error {
return nil
}