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 8, 2023
1 parent efeef06 commit 3bcec33
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 37 deletions.
44 changes: 38 additions & 6 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 | OpenSearchIngestNodes
}

// OpenSearchSpec defines the desired state of OpenSearch
Expand All @@ -56,6 +56,8 @@ type OpenSearchSpec struct {
UserRefs []*UserReference `json:"userRefs,omitempty"`
//+kubuilder:validation:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
//+kubuilder:validation:MaxItems:=1
IngestNodes []*OpenSearchIngestNodes `json:"ingestNodes,omitempty"`
}

type OpenSearchDataCentre struct {
Expand Down Expand Up @@ -88,6 +90,11 @@ type ClusterManagerNodes struct {
DedicatedManager bool `json:"dedicatedManager"`
}

type OpenSearchIngestNodes 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 +120,7 @@ func (oss *OpenSearchSpec) ToInstAPI() *models.OpenSearchCluster {
SLATier: oss.SLATier,
AlertingPlugin: oss.AlertingPlugin,
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
IngestNodes: oss.ingestNodesToInstAPI(),
}
}

Expand Down Expand Up @@ -211,6 +219,17 @@ func (oss *OpenSearchSpec) dataNodesToInstAPI() (iDataNodes []*models.OpenSearch
return
}

func (oss *OpenSearchSpec) ingestNodesToInstAPI() (iIngestNodes []*models.OpenSearchIngestNodes) {
for _, ingestNode := range oss.IngestNodes {
iIngestNodes = append(iIngestNodes, &models.OpenSearchIngestNodes{
NodeSize: ingestNode.NodeSize,
NodeCount: ingestNode.NodeCount,
})
}

return
}

func (oss *OpenSearch) FromInstAPI(iData []byte) (*OpenSearch, error) {
iOpenSearch := &models.OpenSearchCluster{}
err := json.Unmarshal(iData, iOpenSearch)
Expand Down Expand Up @@ -253,6 +272,7 @@ func (oss *OpenSearchSpec) FromInstAPI(iOpenSearch *models.OpenSearchCluster) Op
AlertingPlugin: oss.AlertingPlugin,
BundledUseOnly: oss.BundledUseOnly,
ResizeSettings: resizeSettingsFromInstAPI(iOpenSearch.ResizeSettings),
IngestNodes: oss.IngestNodesFromInstAPI(iOpenSearch.IngestNodes),
}
}

Expand Down Expand Up @@ -339,6 +359,16 @@ func (oss *OpenSearchSpec) DataNodesFromInstAPI(iDataNodes []*models.OpenSearchD
return
}

func (oss *OpenSearchSpec) IngestNodesFromInstAPI(iIngestNodes []*models.OpenSearchIngestNodes) (ingestNodes []*OpenSearchIngestNodes) {
for _, iNode := range iIngestNodes {
ingestNodes = append(ingestNodes, &OpenSearchIngestNodes{
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 +426,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[OpenSearchIngestNodes](a.IngestNodes, b.IngestNodes)
}

func (oss *OpenSearchSpec) areDCsEqual(b []*OpenSearchDataCentre) bool {
Expand Down Expand Up @@ -473,10 +504,11 @@ func areOpenSearchSettingsEqual[T OpenSearchNodeTypes](a, b []*T) bool {

func (oss *OpenSearchSpec) ToInstAPIUpdate() models.OpenSearchInstAPIUpdateRequest {
return models.OpenSearchInstAPIUpdateRequest{
DataNodes: oss.dataNodesToInstAPI(),
OpenSearchDashboards: oss.dashboardsToInstAPI(),
ClusterManagerNodes: oss.clusterManagerNodesToInstAPI(),
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
DataNodes: oss.dataNodesToInstAPI(),
OpenSearchDashboards: oss.dashboardsToInstAPI(),
ClusterManagerNodes: oss.clusterManagerNodesToInstAPI(),
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
OpenSearchIngestNodes: 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
6 changes: 5 additions & 1 deletion config/samples/clusters_v1beta1_opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,4 +54,4 @@ spec:
sqlPlugin: false
# resizeSettings:
# - notifySupportContacts: false
# concurrency: 3
# concurrency: 3
5 changes: 2 additions & 3 deletions controllers/clusterresources/nodereload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,17 @@ func (r *NodeReloadReconciler) Reconcile(ctx context.Context, req ctrl.Request)

if nodeReloadStatus.Status != nodeReloadOperationStatusCompleted {
l.Info("Node Reload operation is not completed yet, please wait a few minutes",
"nodeID", nrs.Status.NodeInProgress,
"status", nrs.Status,
)

return models.ReconcileRequeue, nil
}

l.Info("The node has been successfully reloaded",
"Node ID", nrs.Status.NodeInProgress.ID,
"status", nrs.Status,
)
r.EventRecorder.Eventf(nrs, models.Normal, models.UpdatedEvent,
"Node %s has been successfully reloaded", nrs.Status.NodeInProgress.ID,
"Node %s has been successfully reloaded", nrs.Status,
)

patch = nrs.NewPatch()
Expand Down
61 changes: 34 additions & 27 deletions pkg/models/opensearch_apiv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,35 @@ package models

type OpenSearchCluster struct {
ClusterStatus `json:",inline"`
DataNodes []*OpenSearchDataNodes `json:"dataNodes,omitempty"`
PCIComplianceMode bool `json:"pciComplianceMode"`
ICUPlugin bool `json:"icuPlugin"`
OpenSearchVersion string `json:"opensearchVersion"`
AsynchronousSearchPlugin bool `json:"asynchronousSearchPlugin"`
TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"`
KNNPlugin bool `json:"knnPlugin"`
OpenSearchDashboards []*OpenSearchDashboards `json:"opensearchDashboards,omitempty"`
ReportingPlugin bool `json:"reportingPlugin"`
SQLPlugin bool `json:"sqlPlugin"`
NotificationsPlugin bool `json:"notificationsPlugin"`
DataCentres []*OpenSearchDataCentre `json:"dataCentres"`
AnomalyDetectionPlugin bool `json:"anomalyDetectionPlugin"`
LoadBalancer bool `json:"loadBalancer"`
PrivateNetworkCluster bool `json:"privateNetworkCluster"`
Name string `json:"name"`
BundledUseOnly bool `json:"bundledUseOnly"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes"`
IndexManagementPlugin bool `json:"indexManagementPlugin"`
SLATier string `json:"slaTier,omitempty"`
AlertingPlugin bool `json:"alertingPlugin"`
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
Description string `json:"description,omitempty"`
DataNodes []*OpenSearchDataNodes `json:"dataNodes,omitempty"`
PCIComplianceMode bool `json:"pciComplianceMode"`
ICUPlugin bool `json:"icuPlugin"`
OpenSearchVersion string `json:"opensearchVersion"`
AsynchronousSearchPlugin bool `json:"asynchronousSearchPlugin"`
TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"`
KNNPlugin bool `json:"knnPlugin"`
OpenSearchDashboards []*OpenSearchDashboards `json:"opensearchDashboards,omitempty"`
ReportingPlugin bool `json:"reportingPlugin"`
SQLPlugin bool `json:"sqlPlugin"`
NotificationsPlugin bool `json:"notificationsPlugin"`
DataCentres []*OpenSearchDataCentre `json:"dataCentres"`
AnomalyDetectionPlugin bool `json:"anomalyDetectionPlugin"`
LoadBalancer bool `json:"loadBalancer"`
PrivateNetworkCluster bool `json:"privateNetworkCluster"`
Name string `json:"name"`
BundledUseOnly bool `json:"bundledUseOnly"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes"`
IndexManagementPlugin bool `json:"indexManagementPlugin"`
SLATier string `json:"slaTier,omitempty"`
AlertingPlugin bool `json:"alertingPlugin"`
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
Description string `json:"description,omitempty"`
IngestNodes []*OpenSearchIngestNodes `json:"ingestNodes,omitempty"`
}

type OpenSearchIngestNodes struct {
NodeSize string `json:"nodeSize"`
NodeCount int `json:"nodeCount"`
}

type OpenSearchDataNodes struct {
Expand All @@ -66,8 +72,9 @@ type ClusterManagerNodes struct {
}

type OpenSearchInstAPIUpdateRequest struct {
DataNodes []*OpenSearchDataNodes `json:"dataNodes,omitempty"`
OpenSearchDashboards []*OpenSearchDashboards `json:"opensearchDashboards,omitempty"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes"`
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
DataNodes []*OpenSearchDataNodes `json:"dataNodes,omitempty"`
OpenSearchDashboards []*OpenSearchDashboards `json:"opensearchDashboards,omitempty"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes"`
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
OpenSearchIngestNodes []*OpenSearchIngestNodes `json:"ingestNodes,omitempty"`
}

0 comments on commit 3bcec33

Please sign in to comment.