Skip to content

Commit

Permalink
issue-590, ingestNodes for OpenSearch in API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Nov 1, 2023
1 parent efeef06 commit c0bbd43
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

.PHONY: docker-build
docker-build: manifests generate test ## Build docker image with the manager.
docker-build: manifests generate ## test ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-push
Expand Down
37 changes: 34 additions & 3 deletions apis/clusters/v1beta1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand All @@ -113,6 +119,7 @@ func (oss *OpenSearchSpec) ToInstAPI() *models.OpenSearchCluster {
SLATier: oss.SLATier,
AlertingPlugin: oss.AlertingPlugin,
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
OpenSearchIngestNode: oss.ingestNodesToInstAPI(),
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -477,6 +507,7 @@ func (oss *OpenSearchSpec) ToInstAPIUpdate() models.OpenSearchInstAPIUpdateReque
OpenSearchDashboards: oss.dashboardsToInstAPI(),
ClusterManagerNodes: oss.clusterManagerNodesToInstAPI(),
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
OpenSearchIngestNode: oss.ingestNodesToInstAPI(),
}
}

Expand Down
26 changes: 26 additions & 0 deletions apis/clusters/v1beta1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions config/crd/bases/clusters.instaclustr.com_opensearches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions config/samples/clusters_v1beta1_opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
annotations:
test.annotation/first: testAnnotation
spec:
name: opensearch-test
name: mykyta-opensearch-test-2
alertingPlugin: false
anomalyDetectionPlugin: false
asynchronousSearchPlugin: false
Expand All @@ -22,14 +22,18 @@ spec:
# namespace: "default"
clusterManagerNodes:
- dedicatedManager: false
nodeSize: SRH-DEV-t4g.small-30
nodeSize: SRH-DEV-t4g.small-5
dataCentres:
- cloudProvider: AWS_VPC
name: AWS_VPC_US_EAST_1
network: 10.0.0.0/16
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
Expand All @@ -50,4 +54,4 @@ spec:
sqlPlugin: false
# resizeSettings:
# - notifySupportContacts: false
# concurrency: 3
# concurrency: 3
3 changes: 3 additions & 0 deletions pkg/instaclustr/client.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pkg/models/opensearch_apiv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
}

0 comments on commit c0bbd43

Please sign in to comment.