From 1f5205922c380f9226a9d05d8b110366a36e141a Mon Sep 17 00:00:00 2001 From: "mykyta.oleksiienko" Date: Wed, 1 Nov 2023 17:38:27 +0200 Subject: [PATCH] issue-590, ingestNodes for OpenSearch in API v2 --- apis/clusters/v1beta1/opensearch_types.go | 37 +++++++++++++++++-- .../clusters/v1beta1/zz_generated.deepcopy.go | 26 +++++++++++++ ...clusters.instaclustr.com_opensearches.yaml | 12 ++++++ .../samples/clusters_v1beta1_opensearch.yaml | 6 ++- pkg/models/opensearch_apiv2.go | 7 ++++ 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/apis/clusters/v1beta1/opensearch_types.go b/apis/clusters/v1beta1/opensearch_types.go index b471405a5..0f94ef93b 100644 --- a/apis/clusters/v1beta1/opensearch_types.go +++ b/apis/clusters/v1beta1/opensearch_types.go @@ -31,7 +31,7 @@ import ( // +kubebuilder:object:generate:=false type OpenSearchNodeTypes interface { - OpenSearchDataNodes | OpenSearchDashboards | ClusterManagerNodes + OpenSearchDataNodes | OpenSearchDashboards | ClusterManagerNodes | OpenSearchIngestNode } // OpenSearchSpec defines the desired state of OpenSearch @@ -55,7 +55,8 @@ type OpenSearchSpec struct { BundledUseOnly bool `json:"bundledUseOnly,omitempty"` UserRefs []*UserReference `json:"userRefs,omitempty"` //+kubuilder:validation:MaxItems:=1 - ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + OpenSearchIngestNode []*OpenSearchIngestNode `json:"ingestNodes,omitempty"` } type OpenSearchDataCentre struct { @@ -88,6 +89,11 @@ type ClusterManagerNodes struct { DedicatedManager bool `json:"dedicatedManager"` } +type OpenSearchIngestNode struct { + NodeSize string `json:"nodeSize"` + NodeCount int `json:"nodeCount"` +} + func (oss *OpenSearchSpec) ToInstAPI() *models.OpenSearchCluster { return &models.OpenSearchCluster{ DataNodes: oss.dataNodesToInstAPI(), @@ -113,6 +119,7 @@ func (oss *OpenSearchSpec) ToInstAPI() *models.OpenSearchCluster { SLATier: oss.SLATier, AlertingPlugin: oss.AlertingPlugin, ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings), + OpenSearchIngestNode: oss.ingestNodesToInstAPI(), } } @@ -211,6 +218,17 @@ func (oss *OpenSearchSpec) dataNodesToInstAPI() (iDataNodes []*models.OpenSearch return } +func (oss *OpenSearchSpec) ingestNodesToInstAPI() (iIngestNodes []*models.OpenSearchIngestNode) { + for _, ingestNodes := range oss.OpenSearchIngestNode { + iIngestNodes = append(iIngestNodes, &models.OpenSearchIngestNode{ + NodeSize: ingestNodes.NodeSize, + NodeCount: ingestNodes.NodeCount, + }) + } + + return +} + func (oss *OpenSearch) FromInstAPI(iData []byte) (*OpenSearch, error) { iOpenSearch := &models.OpenSearchCluster{} err := json.Unmarshal(iData, iOpenSearch) @@ -253,6 +271,7 @@ func (oss *OpenSearchSpec) FromInstAPI(iOpenSearch *models.OpenSearchCluster) Op AlertingPlugin: oss.AlertingPlugin, BundledUseOnly: oss.BundledUseOnly, ResizeSettings: resizeSettingsFromInstAPI(iOpenSearch.ResizeSettings), + OpenSearchIngestNode: oss.IngestNodesFromInstAPI(iOpenSearch.OpenSearchIngestNode), } } @@ -339,6 +358,16 @@ func (oss *OpenSearchSpec) DataNodesFromInstAPI(iDataNodes []*models.OpenSearchD return } +func (oss *OpenSearchSpec) IngestNodesFromInstAPI(iIngestNodes []*models.OpenSearchIngestNode) (ingestNodes []*OpenSearchIngestNode) { + for _, iNode := range iIngestNodes { + ingestNodes = append(ingestNodes, &OpenSearchIngestNode{ + NodeSize: iNode.NodeSize, + NodeCount: iNode.NodeCount, + }) + } + return +} + func (oss *OpenSearchSpec) DashboardsFromInstAPI(iDashboards []*models.OpenSearchDashboards) (dashboards []*OpenSearchDashboards) { for _, iDashboard := range iDashboards { dashboards = append(dashboards, &OpenSearchDashboards{ @@ -396,7 +425,8 @@ func (a *OpenSearchSpec) IsEqual(b OpenSearchSpec) bool { a.IndexManagementPlugin == b.IndexManagementPlugin && a.AlertingPlugin == b.AlertingPlugin && a.BundledUseOnly == b.BundledUseOnly && - a.areDCsEqual(b.DataCentres) + a.areDCsEqual(b.DataCentres) && + areOpenSearchSettingsEqual[OpenSearchIngestNode](a.OpenSearchIngestNode, b.OpenSearchIngestNode) } func (oss *OpenSearchSpec) areDCsEqual(b []*OpenSearchDataCentre) bool { @@ -477,6 +507,7 @@ func (oss *OpenSearchSpec) ToInstAPIUpdate() models.OpenSearchInstAPIUpdateReque OpenSearchDashboards: oss.dashboardsToInstAPI(), ClusterManagerNodes: oss.clusterManagerNodesToInstAPI(), ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings), + OpenSearchIngestNode: oss.ingestNodesToInstAPI(), } } diff --git a/apis/clusters/v1beta1/zz_generated.deepcopy.go b/apis/clusters/v1beta1/zz_generated.deepcopy.go index eb4beebbd..df8ba019e 100644 --- a/apis/clusters/v1beta1/zz_generated.deepcopy.go +++ b/apis/clusters/v1beta1/zz_generated.deepcopy.go @@ -1407,6 +1407,21 @@ func (in *OpenSearchDataNodes) DeepCopy() *OpenSearchDataNodes { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenSearchIngestNode) DeepCopyInto(out *OpenSearchIngestNode) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenSearchIngestNode. +func (in *OpenSearchIngestNode) DeepCopy() *OpenSearchIngestNode { + if in == nil { + return nil + } + out := new(OpenSearchIngestNode) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OpenSearchList) DeepCopyInto(out *OpenSearchList) { *out = *in @@ -1540,6 +1555,17 @@ func (in *OpenSearchSpec) DeepCopyInto(out *OpenSearchSpec) { } } } + if in.OpenSearchIngestNode != nil { + in, out := &in.OpenSearchIngestNode, &out.OpenSearchIngestNode + *out = make([]*OpenSearchIngestNode, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(OpenSearchIngestNode) + **out = **in + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenSearchSpec. diff --git a/config/crd/bases/clusters.instaclustr.com_opensearches.yaml b/config/crd/bases/clusters.instaclustr.com_opensearches.yaml index c88f405ec..66c626ebe 100644 --- a/config/crd/bases/clusters.instaclustr.com_opensearches.yaml +++ b/config/crd/bases/clusters.instaclustr.com_opensearches.yaml @@ -127,6 +127,18 @@ spec: type: boolean indexManagementPlugin: type: boolean + ingestNodes: + items: + properties: + nodeCount: + type: integer + nodeSize: + type: string + required: + - nodeCount + - nodeSize + type: object + type: array knnPlugin: type: boolean loadBalancer: diff --git a/config/samples/clusters_v1beta1_opensearch.yaml b/config/samples/clusters_v1beta1_opensearch.yaml index beb1ed157..c7ddc75a6 100644 --- a/config/samples/clusters_v1beta1_opensearch.yaml +++ b/config/samples/clusters_v1beta1_opensearch.yaml @@ -30,6 +30,10 @@ spec: replicationFactor: 3 privateLink: false region: US_EAST_1 + ingestNodes: +# - nodeSize: SRH-DI-PRD-m6g.large-10 + - nodeSize: SRH-DI-PRD-m6g.xlarge-10 + nodeCount: 3 # dataNodes: # - nodeNumber: 3 # nodeSize: SRH-DEV-t4g.small-5 @@ -50,4 +54,4 @@ spec: sqlPlugin: false # resizeSettings: # - notifySupportContacts: false -# concurrency: 3 +# concurrency: 3 \ No newline at end of file diff --git a/pkg/models/opensearch_apiv2.go b/pkg/models/opensearch_apiv2.go index 51abc7776..faba6a523 100644 --- a/pkg/models/opensearch_apiv2.go +++ b/pkg/models/opensearch_apiv2.go @@ -41,6 +41,12 @@ type OpenSearchCluster struct { AlertingPlugin bool `json:"alertingPlugin"` ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` Description string `json:"description,omitempty"` + OpenSearchIngestNode []*OpenSearchIngestNode `json:"ingestNodes,omitempty"` +} + +type OpenSearchIngestNode struct { + NodeSize string `json:"nodeSize"` + NodeCount int `json:"nodeCount"` } type OpenSearchDataNodes struct { @@ -70,4 +76,5 @@ type OpenSearchInstAPIUpdateRequest struct { OpenSearchDashboards []*OpenSearchDashboards `json:"opensearchDashboards,omitempty"` ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes"` ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + OpenSearchIngestNode []*OpenSearchIngestNode `json:"ingestNodes,omitempty"` }