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 committed Feb 22, 2024
1 parent c3d2a79 commit f5b16ca
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
8 changes: 8 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,14 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

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

type OpensearchDatastreamSpec struct {
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"`

// Array of wildcard expressions used to match the names of indices during creation
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,18 @@ spec:
items:
type: string
type: array
dataStream:
description: Array of wildcard expressions used to match the names
of indices during creation
properties:
timestamp_field:
properties:
name:
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
13 changes: 13 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,18 @@ func TranslateComponentTemplateToRequest(spec v1.OpensearchComponentTemplateSpec
return request
}

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 f5b16ca

Please sign in to comment.