/
opensearch_types.go
652 lines (563 loc) · 21.5 KB
/
opensearch_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1
import (
"encoding/json"
"fmt"
"strconv"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
clusterresourcesv1beta1 "github.com/instaclustr/operator/apis/clusterresources/v1beta1"
"github.com/instaclustr/operator/pkg/models"
)
// +kubebuilder:object:generate:=false
type OpenSearchNodeTypes interface {
OpenSearchDataNodes | OpenSearchDashboards | ClusterManagerNodes | OpenSearchIngestNodes
}
// OpenSearchSpec defines the desired state of OpenSearch
type OpenSearchSpec struct {
RestoreFrom *OpenSearchRestoreFrom `json:"restoreFrom,omitempty"`
Cluster `json:",inline"`
DataCentres []*OpenSearchDataCentre `json:"dataCentres,omitempty"`
DataNodes []*OpenSearchDataNodes `json:"dataNodes,omitempty"`
ICUPlugin bool `json:"icuPlugin,omitempty"`
AsynchronousSearchPlugin bool `json:"asynchronousSearchPlugin,omitempty"`
KNNPlugin bool `json:"knnPlugin,omitempty"`
Dashboards []*OpenSearchDashboards `json:"opensearchDashboards,omitempty"`
ReportingPlugin bool `json:"reportingPlugin,omitempty"`
SQLPlugin bool `json:"sqlPlugin,omitempty"`
NotificationsPlugin bool `json:"notificationsPlugin,omitempty"`
AnomalyDetectionPlugin bool `json:"anomalyDetectionPlugin,omitempty"`
LoadBalancer bool `json:"loadBalancer,omitempty"`
ClusterManagerNodes []*ClusterManagerNodes `json:"clusterManagerNodes,omitempty"`
IndexManagementPlugin bool `json:"indexManagementPlugin,omitempty"`
AlertingPlugin bool `json:"alertingPlugin,omitempty"`
BundledUseOnly bool `json:"bundledUseOnly,omitempty"`
UserRefs References `json:"userRefs,omitempty"`
//+kubuilder:validation:MaxItems:=1
ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"`
//+kubuilder:validation:MaxItems:=1
IngestNodes []*OpenSearchIngestNodes `json:"ingestNodes,omitempty"`
}
type OpenSearchDataCentre struct {
PrivateLink bool `json:"privateLink,omitempty"`
Name string `json:"name,omitempty"`
Region string `json:"region"`
CloudProvider string `json:"cloudProvider"`
ProviderAccountName string `json:"accountName,omitempty"`
CloudProviderSettings []*CloudProviderSettings `json:"cloudProviderSettings,omitempty"`
Network string `json:"network"`
Tags map[string]string `json:"tags,omitempty"`
// ReplicationFactor is a number of racks to use when allocating data nodes.
ReplicationFactor int `json:"replicationFactor"`
}
type OpenSearchDataNodes struct {
NodeSize string `json:"nodeSize"`
NodesNumber int `json:"nodesNumber"`
}
type OpenSearchDashboards struct {
NodeSize string `json:"nodeSize"`
OIDCProvider string `json:"oidcProvider,omitempty"`
Version string `json:"version"`
}
type ClusterManagerNodes struct {
NodeSize string `json:"nodeSize"`
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(),
PCIComplianceMode: oss.PCICompliance,
ICUPlugin: oss.ICUPlugin,
OpenSearchVersion: oss.Version,
AsynchronousSearchPlugin: oss.AsynchronousSearchPlugin,
TwoFactorDelete: oss.TwoFactorDeletesToInstAPI(),
KNNPlugin: oss.KNNPlugin,
OpenSearchDashboards: oss.dashboardsToInstAPI(),
ReportingPlugin: oss.ReportingPlugin,
SQLPlugin: oss.SQLPlugin,
Description: oss.Description,
NotificationsPlugin: oss.NotificationsPlugin,
DataCentres: oss.dcsToInstAPI(),
AnomalyDetectionPlugin: oss.AnomalyDetectionPlugin,
LoadBalancer: oss.LoadBalancer,
PrivateNetworkCluster: oss.PrivateNetworkCluster,
Name: oss.Name,
BundledUseOnly: oss.BundledUseOnly,
ClusterManagerNodes: oss.clusterManagerNodesToInstAPI(),
IndexManagementPlugin: oss.IndexManagementPlugin,
SLATier: oss.SLATier,
AlertingPlugin: oss.AlertingPlugin,
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
IngestNodes: oss.ingestNodesToInstAPI(),
}
}
func (oss *OpenSearchSpec) dcsToInstAPI() (iDCs []*models.OpenSearchDataCentre) {
for _, dc := range oss.DataCentres {
providerSettings := cloudProviderSettingsToInstAPI(dc)
iDCs = append(iDCs, &models.OpenSearchDataCentre{
DataCentre: models.DataCentre{
Name: dc.Name,
Network: dc.Network,
AWSSettings: providerSettings.AWSSettings,
GCPSettings: providerSettings.GCPSettings,
AzureSettings: providerSettings.AzureSettings,
Tags: tagsToInstAPI(dc.Tags),
CloudProvider: dc.CloudProvider,
Region: dc.Region,
ProviderAccountName: dc.ProviderAccountName,
},
PrivateLink: dc.PrivateLink,
NumberOfRacks: dc.ReplicationFactor,
})
}
return
}
func cloudProviderSettingsToInstAPI(dc *OpenSearchDataCentre) *models.CloudProviderSettings {
iSettings := &models.CloudProviderSettings{}
switch dc.CloudProvider {
case models.AWSVPC:
awsSettings := []*models.AWSSetting{}
for _, providerSettings := range dc.CloudProviderSettings {
awsSettings = append(awsSettings, providerSettings.AWSToInstAPI())
}
iSettings.AWSSettings = awsSettings
case models.AZUREAZ:
azureSettings := []*models.AzureSetting{}
for _, providerSettings := range dc.CloudProviderSettings {
azureSettings = append(azureSettings, providerSettings.AzureToInstAPI())
}
iSettings.AzureSettings = azureSettings
case models.GCP:
gcpSettings := []*models.GCPSetting{}
for _, providerSettings := range dc.CloudProviderSettings {
gcpSettings = append(gcpSettings, providerSettings.GCPToInstAPI())
}
iSettings.GCPSettings = gcpSettings
}
return iSettings
}
func tagsToInstAPI(k8sTags map[string]string) (iTags []*models.Tag) {
for key, value := range k8sTags {
iTags = append(iTags, &models.Tag{
Key: key,
Value: value,
})
}
return
}
func (oss *OpenSearchSpec) dashboardsToInstAPI() (iDashboards []*models.OpenSearchDashboards) {
for _, dashboard := range oss.Dashboards {
iDashboards = append(iDashboards, &models.OpenSearchDashboards{
NodeSize: dashboard.NodeSize,
OIDCProvider: dashboard.OIDCProvider,
Version: dashboard.Version,
})
}
return
}
func (oss *OpenSearchSpec) clusterManagerNodesToInstAPI() (iManagerNodes []*models.ClusterManagerNodes) {
for _, managerNodes := range oss.ClusterManagerNodes {
iManagerNodes = append(iManagerNodes, &models.ClusterManagerNodes{
NodeSize: managerNodes.NodeSize,
DedicatedManager: managerNodes.DedicatedManager,
})
}
return
}
func (oss *OpenSearchSpec) dataNodesToInstAPI() (iDataNodes []*models.OpenSearchDataNodes) {
for _, dataNode := range oss.DataNodes {
iDataNodes = append(iDataNodes, &models.OpenSearchDataNodes{
NodeSize: dataNode.NodeSize,
NodeCount: dataNode.NodesNumber,
})
}
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)
if err != nil {
return nil, err
}
return &OpenSearch{
TypeMeta: oss.TypeMeta,
ObjectMeta: oss.ObjectMeta,
Spec: oss.Spec.FromInstAPI(iOpenSearch),
Status: oss.Status.FromInstAPI(iOpenSearch),
}, nil
}
func (oss *OpenSearchSpec) FromInstAPI(iOpenSearch *models.OpenSearchCluster) OpenSearchSpec {
return OpenSearchSpec{
Cluster: Cluster{
Name: iOpenSearch.Name,
Version: iOpenSearch.OpenSearchVersion,
PCICompliance: iOpenSearch.PCIComplianceMode,
Description: iOpenSearch.Description,
PrivateNetworkCluster: iOpenSearch.PrivateNetworkCluster,
SLATier: iOpenSearch.SLATier,
TwoFactorDelete: oss.Cluster.TwoFactorDeleteFromInstAPI(iOpenSearch.TwoFactorDelete),
},
DataCentres: oss.DCsFromInstAPI(iOpenSearch.DataCentres),
DataNodes: oss.DataNodesFromInstAPI(iOpenSearch.DataNodes),
ICUPlugin: oss.ICUPlugin,
AsynchronousSearchPlugin: oss.AsynchronousSearchPlugin,
KNNPlugin: oss.KNNPlugin,
Dashboards: oss.DashboardsFromInstAPI(iOpenSearch.OpenSearchDashboards),
ReportingPlugin: oss.ReportingPlugin,
SQLPlugin: oss.SQLPlugin,
NotificationsPlugin: oss.NotificationsPlugin,
AnomalyDetectionPlugin: oss.AnomalyDetectionPlugin,
LoadBalancer: oss.LoadBalancer,
ClusterManagerNodes: oss.ClusterManagerNodesFromInstAPI(iOpenSearch.ClusterManagerNodes),
IndexManagementPlugin: oss.IndexManagementPlugin,
AlertingPlugin: oss.AlertingPlugin,
BundledUseOnly: oss.BundledUseOnly,
ResizeSettings: resizeSettingsFromInstAPI(iOpenSearch.ResizeSettings),
IngestNodes: oss.IngestNodesFromInstAPI(iOpenSearch.IngestNodes),
}
}
func (oss *OpenSearch) RestoreInfoToInstAPI(restoreData *OpenSearchRestoreFrom) any {
iRestore := struct {
RestoredClusterName string `json:"restoredClusterName,omitempty"`
CDCConfigs []*RestoreCDCConfig `json:"cdcConfigs,omitempty"`
PointInTime int64 `json:"pointInTime,omitempty"`
IndexNames string `json:"indexNames,omitempty"`
ClusterID string `json:"clusterId,omitempty"`
}{
RestoredClusterName: restoreData.RestoredClusterName,
CDCConfigs: restoreData.CDCConfigs,
PointInTime: restoreData.PointInTime,
IndexNames: restoreData.IndexNames,
ClusterID: restoreData.ClusterID,
}
return iRestore
}
func (oss *OpenSearchSpec) DCsFromInstAPI(iDCs []*models.OpenSearchDataCentre) (dcs []*OpenSearchDataCentre) {
for _, iDC := range iDCs {
dcs = append(dcs, &OpenSearchDataCentre{
Name: iDC.Name,
Region: iDC.Region,
CloudProvider: iDC.CloudProvider,
ProviderAccountName: iDC.ProviderAccountName,
CloudProviderSettings: cloudProviderSettingsFromInstAPI(iDC),
Network: iDC.Network,
Tags: tagsFromInstAPI(iDC.Tags),
PrivateLink: iDC.PrivateLink,
ReplicationFactor: iDC.NumberOfRacks,
})
}
return
}
func tagsFromInstAPI(iTags []*models.Tag) map[string]string {
newTags := map[string]string{}
for _, iTag := range iTags {
newTags[iTag.Key] = iTag.Value
}
return newTags
}
func cloudProviderSettingsFromInstAPI(iDC *models.OpenSearchDataCentre) (settings []*CloudProviderSettings) {
if isCloudProviderSettingsEmpty(iDC.DataCentre) {
return nil
}
switch iDC.CloudProvider {
case models.AWSVPC:
for _, awsSetting := range iDC.AWSSettings {
settings = append(settings, &CloudProviderSettings{
CustomVirtualNetworkID: awsSetting.CustomVirtualNetworkID,
DiskEncryptionKey: awsSetting.EBSEncryptionKey,
})
}
case models.GCP:
for _, gcpSetting := range iDC.GCPSettings {
settings = append(settings, &CloudProviderSettings{
CustomVirtualNetworkID: gcpSetting.CustomVirtualNetworkID,
})
}
case models.AZUREAZ:
for _, azureSetting := range iDC.AzureSettings {
settings = append(settings, &CloudProviderSettings{
ResourceGroup: azureSetting.ResourceGroup,
})
}
}
return
}
func (oss *OpenSearchSpec) DataNodesFromInstAPI(iDataNodes []*models.OpenSearchDataNodes) (dataNodes []*OpenSearchDataNodes) {
for _, iNode := range iDataNodes {
dataNodes = append(dataNodes, &OpenSearchDataNodes{
NodeSize: iNode.NodeSize,
NodesNumber: iNode.NodeCount,
})
}
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{
NodeSize: iDashboard.NodeSize,
OIDCProvider: iDashboard.OIDCProvider,
Version: iDashboard.Version,
})
}
return
}
func (oss *OpenSearchSpec) ClusterManagerNodesFromInstAPI(iManagerNodes []*models.ClusterManagerNodes) (managerNodes []*ClusterManagerNodes) {
for _, iNode := range iManagerNodes {
managerNodes = append(managerNodes, &ClusterManagerNodes{
NodeSize: iNode.NodeSize,
DedicatedManager: iNode.DedicatedManager,
})
}
return
}
func (oss *OpenSearchStatus) FromInstAPI(iOpenSearch *models.OpenSearchCluster) OpenSearchStatus {
return OpenSearchStatus{
ClusterStatus: ClusterStatus{
ID: iOpenSearch.ID,
State: iOpenSearch.Status,
DataCentres: oss.DCsFromInstAPI(iOpenSearch.DataCentres),
CurrentClusterOperationStatus: iOpenSearch.CurrentClusterOperationStatus,
MaintenanceEvents: oss.MaintenanceEvents,
},
}
}
func (oss *OpenSearchStatus) DCsFromInstAPI(iDCs []*models.OpenSearchDataCentre) (dcs []*DataCentreStatus) {
for _, iDC := range iDCs {
dcs = append(dcs, oss.ClusterStatus.DCFromInstAPI(iDC.DataCentre))
}
return
}
func (a *OpenSearchSpec) IsEqual(b OpenSearchSpec) bool {
return a.Cluster.IsEqual(b.Cluster) &&
a.IsTwoFactorDeleteEqual(b.TwoFactorDelete) &&
areOpenSearchSettingsEqual[OpenSearchDataNodes](a.DataNodes, b.DataNodes) &&
a.ICUPlugin == b.ICUPlugin &&
a.AsynchronousSearchPlugin == b.AsynchronousSearchPlugin &&
a.KNNPlugin == b.KNNPlugin &&
areOpenSearchSettingsEqual[OpenSearchDashboards](a.Dashboards, b.Dashboards) &&
a.ReportingPlugin == b.ReportingPlugin &&
a.SQLPlugin == b.SQLPlugin &&
a.NotificationsPlugin == b.NotificationsPlugin &&
a.AnomalyDetectionPlugin == b.AnomalyDetectionPlugin &&
a.LoadBalancer == b.LoadBalancer &&
areOpenSearchSettingsEqual[ClusterManagerNodes](a.ClusterManagerNodes, b.ClusterManagerNodes) &&
a.IndexManagementPlugin == b.IndexManagementPlugin &&
a.AlertingPlugin == b.AlertingPlugin &&
a.BundledUseOnly == b.BundledUseOnly &&
a.areDCsEqual(b.DataCentres) &&
areOpenSearchSettingsEqual[OpenSearchIngestNodes](a.IngestNodes, b.IngestNodes)
}
func (oss *OpenSearchSpec) areDCsEqual(b []*OpenSearchDataCentre) bool {
a := oss.DataCentres
if len(a) != len(b) {
return false
}
for i := range b {
if a[i].Name != b[i].Name {
continue
}
if a[i].Region != b[i].Region &&
a[i].CloudProvider != b[i].CloudProvider &&
a[i].ProviderAccountName != b[i].ProviderAccountName &&
areCloudProviderSettingsEqual(a[i].CloudProviderSettings, b[i].CloudProviderSettings) &&
a[i].Network != b[i].Network &&
areTagsEqual(a[i].Tags, b[i].Tags) &&
a[i].PrivateLink != b[i].PrivateLink ||
a[i].ReplicationFactor != b[i].ReplicationFactor {
return false
}
}
return true
}
func areCloudProviderSettingsEqual(a, b []*CloudProviderSettings) bool {
if len(a) != len(b) {
return false
}
for i := range b {
if *a[i] != *b[i] {
return false
}
}
return true
}
func areTagsEqual(a, b map[string]string) bool {
if len(a) != len(b) {
return false
}
for bKey, bValue := range b {
if aValue, exists := a[bKey]; !exists || aValue != bValue {
return false
}
}
return true
}
func areOpenSearchSettingsEqual[T OpenSearchNodeTypes](a, b []*T) bool {
if a == nil && b == nil {
return true
}
if len(a) != len(b) {
return false
}
for i := range a {
if *a[i] != *b[i] {
return false
}
}
return true
}
func (oss *OpenSearchSpec) ToInstAPIUpdate() models.OpenSearchInstAPIUpdateRequest {
return models.OpenSearchInstAPIUpdateRequest{
DataNodes: oss.dataNodesToInstAPI(),
OpenSearchDashboards: oss.dashboardsToInstAPI(),
ClusterManagerNodes: oss.clusterManagerNodesToInstAPI(),
ResizeSettings: resizeSettingsToInstAPI(oss.ResizeSettings),
OpenSearchIngestNodes: oss.ingestNodesToInstAPI(),
}
}
type OpenSearchRestoreFrom struct {
// Original cluster ID. Backup from that cluster will be used for restore
ClusterID string `json:"clusterId"`
// The display name of the restored cluster.
RestoredClusterName string `json:"restoredClusterName,omitempty"`
// An optional list of cluster data centres for which custom VPC settings will be used.
CDCConfigs []*RestoreCDCConfig `json:"cdcConfigs,omitempty"`
// Timestamp in milliseconds since epoch. All backed up data will be restored for this point in time.
PointInTime int64 `json:"pointInTime,omitempty"`
// Only data for the specified indices will be restored, for the point in time.
IndexNames string `json:"indexNames,omitempty"`
}
// OpenSearchStatus defines the observed state of OpenSearch
type OpenSearchStatus struct {
ClusterStatus `json:",inline"`
AvailableUsers References `json:"availableUsers,omitempty"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
//+kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id"
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state"
// OpenSearch is the Schema for the opensearches API
type OpenSearch struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec OpenSearchSpec `json:"spec,omitempty"`
Status OpenSearchStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// OpenSearchList contains a list of OpenSearch
type OpenSearchList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []OpenSearch `json:"items"`
}
func (os *OpenSearch) GetJobID(jobName string) string {
return os.Kind + "/" + client.ObjectKeyFromObject(os).String() + "/" + jobName
}
func (os *OpenSearch) NewPatch() client.Patch {
old := os.DeepCopy()
old.Annotations[models.ResourceStateAnnotation] = ""
return client.MergeFrom(old)
}
func (os *OpenSearch) NewBackupSpec(startTimestamp int) *clusterresourcesv1beta1.ClusterBackup {
return &clusterresourcesv1beta1.ClusterBackup{
TypeMeta: ctrl.TypeMeta{
Kind: models.ClusterBackupKind,
APIVersion: models.ClusterresourcesV1beta1APIVersion,
},
ObjectMeta: ctrl.ObjectMeta{
Name: models.SnapshotUploadPrefix + os.Status.ID + "-" + strconv.Itoa(startTimestamp),
Namespace: os.Namespace,
Annotations: map[string]string{models.StartTimestampAnnotation: strconv.Itoa(startTimestamp)},
Labels: map[string]string{models.ClusterIDLabel: os.Status.ID},
Finalizers: []string{models.DeletionFinalizer},
},
Spec: clusterresourcesv1beta1.ClusterBackupSpec{
ClusterRef: &clusterresourcesv1beta1.ClusterRef{
Name: os.Name,
Namespace: os.Namespace,
ClusterKind: models.OsClusterKind,
},
},
}
}
func (oss *OpenSearchSpec) HasRestore() bool {
if oss.RestoreFrom != nil && oss.RestoreFrom.ClusterID != "" {
return true
}
return false
}
func (oss *OpenSearchSpec) validateResizeSettings(nodesNumber int) error {
for _, rs := range oss.ResizeSettings {
if rs.Concurrency > nodesNumber {
return fmt.Errorf("resizeSettings.concurrency cannot be greater than number of nodes: %v", nodesNumber)
}
}
return nil
}
func (oss *OpenSearch) GetUserRefs() References {
return oss.Spec.UserRefs
}
func (oss *OpenSearch) SetUserRefs(refs References) {
oss.Spec.UserRefs = refs
}
func (oss *OpenSearch) GetAvailableUsers() References {
return oss.Status.AvailableUsers
}
func (oss *OpenSearch) SetAvailableUsers(users References) {
oss.Status.AvailableUsers = users
}
func (oss *OpenSearch) GetClusterID() string {
return oss.Status.ID
}
func (oss *OpenSearch) GetDataCentreID(cdcName string) string {
if cdcName == "" {
return oss.Status.DataCentres[0].ID
}
for _, cdc := range oss.Status.DataCentres {
if cdc.Name == cdcName {
return cdc.ID
}
}
return ""
}
func (oss *OpenSearch) SetClusterID(id string) {
oss.Status.ID = id
}
func init() {
SchemeBuilder.Register(&OpenSearch{}, &OpenSearchList{})
}