Skip to content

Commit

Permalink
add datastream support
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Groschupp <[email protected]>
  • Loading branch information
Christian Groschupp authored and cgroschupp committed Mar 4, 2024
1 parent 0494837 commit d1addb6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
10 changes: 10 additions & 0 deletions opensearch-operator/api/v1/opensearch_index_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

type OpensearchDatastreamTimestampFieldSpec struct {
// Name of the field that are used for the DataStream
Name string `json:"name"`
}

type OpensearchDatastreamSpec struct {
// TimestampField for dataStream
TimestampField OpensearchDatastreamTimestampFieldSpec `json:"timestamp_field,omitempty"`
}

// Describes the specs of an index
type OpensearchIndexSpec struct {
// Configuration options for the index
Expand Down
3 changes: 3 additions & 0 deletions opensearch-operator/api/v1/opensearch_indextemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type OpensearchIndexTemplateSpec struct {
// Array of wildcard expressions used to match the names of indices during creation
IndexPatterns []string `json:"indexPatterns"`

// The dataStream config that should be applied
DataStream *OpensearchDatastreamSpec `json:"dataStream,omitempty"`

// The template that should be applied
Template OpensearchIndexSpec `json:"template,omitempty"`

Expand Down
36 changes: 36 additions & 0 deletions opensearch-operator/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ spec:
items:
type: string
type: array
dataStream:
description: The dataStream config that should be applied
properties:
timestamp_field:
description: TimestampField for dataStream
properties:
name:
description: Name of the field that are used for the DataStream
type: string
required:
- name
type: object
type: object
indexPatterns:
description: Array of wildcard expressions used to match the names
of indices during creation
Expand Down
9 changes: 9 additions & 0 deletions opensearch-operator/opensearch-gateway/requests/Templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1

type IndexTemplate struct {
IndexPatterns []string `json:"index_patterns"`
DataStream *Datastream `json:"data_stream,omitempty"`
Template Index `json:"template,omitempty"`
ComposedOf []string `json:"composed_of,omitempty"`
Priority int `json:"priority,omitempty"`
Expand All @@ -24,6 +25,14 @@ type Index struct {
Aliases map[string]IndexAlias `json:"aliases,omitempty"`
}

type DatastreamTimestampFieldSpec struct {
Name string `json:"name"`
}

type Datastream struct {
TimestampField *DatastreamTimestampFieldSpec `json:"timestamp_field,omitempty"`
}

type IndexAlias struct {
Index string `json:"index,omitempty"`
Alias string `json:"alias,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions opensearch-operator/pkg/helpers/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func TranslateIndexTemplateToRequest(spec v1.OpensearchIndexTemplateSpec) requests.IndexTemplate {
request := requests.IndexTemplate{
IndexPatterns: spec.IndexPatterns,
DataStream: TranslateDatastreamToRequest(spec.DataStream),
Template: TranslateIndexToRequest(spec.Template),
Priority: spec.Priority,
Version: spec.Version,
Expand Down Expand Up @@ -37,6 +38,19 @@ func TranslateComponentTemplateToRequest(spec v1.OpensearchComponentTemplateSpec
return request
}

// TranslateDatastreamToRequest rewrites the CRD format to the gateway format
func TranslateDatastreamToRequest(spec *v1.OpensearchDatastreamSpec) *requests.Datastream {
if spec == nil {
return nil
}
request := requests.Datastream{}
if spec.TimestampField.Name != "" {
request.TimestampField = &requests.DatastreamTimestampFieldSpec{Name: spec.TimestampField.Name}
}

return &request
}

// TranslateIndexToRequest rewrites the CRD format to the gateway format
func TranslateIndexToRequest(spec v1.OpensearchIndexSpec) requests.Index {
aliases := make(map[string]requests.IndexAlias)
Expand Down

0 comments on commit d1addb6

Please sign in to comment.