Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Siryk authored and Bohdan Siryk committed Jan 22, 2024
1 parent f0c1a68 commit b935480
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 62 deletions.
6 changes: 3 additions & 3 deletions apis/clusters/v1beta1/cadence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ type AdvancedVisibility struct {

// CadenceStatus defines the observed state of Cadence
type CadenceStatus struct {
ClusterStatus `json:",inline"`
TargetSecondaryCadence []*TargetCadence `json:"targetSecondaryCadence,omitempty"`
ClusterStatus[DataCentre] `json:",inline"`
TargetSecondaryCadence []*TargetCadence `json:"targetSecondaryCadence,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -313,7 +313,7 @@ func (cdc *CadenceDataCentre) ToInstAPI() *models.CadenceDataCentre {
PrivateLink: cdc.privateLinkToInstAPI(),
ClientToClusterEncryption: cdc.ClientEncryption,
DataCentre: models.DataCentre{
CloudProvider: cdc.CloudProvider,
CloudPrxovider: cdc.CloudProvider,

Check failure on line 316 in apis/clusters/v1beta1/cadence_types.go

View workflow job for this annotation

GitHub Actions / PRE-MAIN Build and push the Instaclustr Operator

unknown field `CloudPrxovider` in struct literal (typecheck)
Name: cdc.Name,
Network: cdc.Network,
NodeSize: cdc.NodeSize,
Expand Down
30 changes: 17 additions & 13 deletions apis/clusters/v1beta1/generic_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ import "github.com/instaclustr/operator/apis/clusterresources/v1beta1"

type GenericStatus struct {
ID string `json:"id,omitempty"`
MaintenanceEvents []*v1beta1.ClusteredMaintenanceEventStatus `json:"maintenanceEvents,omitempty"`
State string `json:"state,omitempty"`
CurrentClusterOperationStatus string `json:"currentClusterOperationStatus,omitempty"`
MaintenanceEvents []*v1beta1.ClusteredMaintenanceEventStatus `json:"maintenanceEvents,omitempty"`
}

func (s *GenericStatus) Equals(o *GenericStatus) bool {
return false
}

type GenericDataCentreStatus struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"`
ResizeOperations []*ResizeOperation `json:"resizeOperations,omitempty"`
}

func (s *GenericDataCentreStatus) Equals(o *GenericDataCentreStatus) bool {
return false
return s.ID == o.ID &&
s.State == o.State &&
s.CurrentClusterOperationStatus == o.CurrentClusterOperationStatus
}

func (s *GenericStatus) MaintenanceEventsEqual(events []*v1beta1.ClusteredMaintenanceEventStatus) bool {
Expand All @@ -37,3 +28,16 @@ func (s *GenericStatus) MaintenanceEventsEqual(events []*v1beta1.ClusteredMainte

return true
}

type GenericDataCentreStatus struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
ResizeOperations []*ResizeOperation `json:"resizeOperations,omitempty"`
}

func (s *GenericDataCentreStatus) Equals(o *GenericDataCentreStatus) bool {
return s.Name == o.Name &&
s.Status == o.Status &&
s.ID == o.ID
}
6 changes: 3 additions & 3 deletions apis/clusters/v1beta1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func (s *OpenSearchDataCentreStatus) Equals(o *OpenSearchDataCentreStatus) bool

for _, k8sNode := range s.Nodes {
for _, instaNode := range o.Nodes {
if !k8sNode.Equals(&instaNode) {
if k8sNode.ID == instaNode.ID && !k8sNode.Equals(&instaNode) {
return false
}
}
Expand All @@ -635,7 +635,7 @@ func (oss *OpenSearchStatus) DataCentreEquals(s *OpenSearchStatus) bool {

for _, k8sDC := range oss.DataCentres {
for _, iDC := range s.DataCentres {
if !k8sDC.Equals(&iDC) {
if k8sDC.ID == iDC.ID && !k8sDC.Equals(&iDC) {
return false
}
}
Expand All @@ -645,7 +645,7 @@ func (oss *OpenSearchStatus) DataCentreEquals(s *OpenSearchStatus) bool {
}

func (oss *OpenSearchStatus) Equals(o *OpenSearchStatus) bool {
return oss.ID != o.ID &&
return oss.ID == o.ID &&
oss.State == o.State &&
oss.CurrentClusterOperationStatus == o.CurrentClusterOperationStatus &&
oss.PublicEndpoint == o.PublicEndpoint &&
Expand Down
182 changes: 182 additions & 0 deletions apis/clusters/v1beta1/opensearch_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package v1beta1

import (
"testing"
)

func TestOpenSearchStatus_Equals(t *testing.T) {
tests := map[string]struct {
fields OpenSearchStatus
args OpenSearchStatus
want bool
}{
"Equal Empty Objects": {
fields: OpenSearchStatus{},
args: OpenSearchStatus{},
want: true,
},
"Different LoadBalancerConnectionURL": {
fields: OpenSearchStatus{LoadBalancerConnectionURL: ""},
args: OpenSearchStatus{LoadBalancerConnectionURL: "http://loadbalancer1"},
want: false,
},
"Different PrivateEndpoint": {
fields: OpenSearchStatus{PrivateEndpoint: ""},
args: OpenSearchStatus{PrivateEndpoint: "http://private1"},
want: false,
},
"Different PublicEndpoint": {
fields: OpenSearchStatus{PublicEndpoint: ""},
args: OpenSearchStatus{PublicEndpoint: "http://public1"},
want: false,
},
"Different IngestNodesLoadBalancerConnectionURL": {
fields: OpenSearchStatus{IngestNodesLoadBalancerConnectionURL: ""},
args: OpenSearchStatus{IngestNodesLoadBalancerConnectionURL: "http://ingest1"},
want: false,
},

"Different GenericStatus ID": {
fields: OpenSearchStatus{GenericStatus: GenericStatus{ID: ""}},
args: OpenSearchStatus{GenericStatus: GenericStatus{ID: "1"}},
want: false,
},
"Different GenericStatus State": {
fields: OpenSearchStatus{GenericStatus: GenericStatus{State: "PROVISIONING"}},
args: OpenSearchStatus{GenericStatus: GenericStatus{State: "RUNNING"}},
want: false,
},
"Different GenericStatus CurrentClusterOperationStatus": {
fields: OpenSearchStatus{GenericStatus: GenericStatus{CurrentClusterOperationStatus: "NO_OPERATION"}},
args: OpenSearchStatus{GenericStatus: GenericStatus{CurrentClusterOperationStatus: "OPERATION_IN_PROGRESS"}},
want: false,
},

"Different DataCentre ID": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{GenericDataCentreStatus: GenericDataCentreStatus{ID: ""}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{GenericDataCentreStatus: GenericDataCentreStatus{ID: "dc1"}}}},
want: false,
},
"Different DataCentre Name": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{GenericDataCentreStatus: GenericDataCentreStatus{Name: ""}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{GenericDataCentreStatus: GenericDataCentreStatus{Name: "DataCentre1"}}}},
want: false,
},
"Different DataCentre Status": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{GenericDataCentreStatus: GenericDataCentreStatus{Status: "PROVISIONING"}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{GenericDataCentreStatus: GenericDataCentreStatus{Status: "RUNNING"}}}},
want: false,
},

"Different Node PublicEndpoint": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{PublicEndpoint: ""}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{PublicEndpoint: "http://public.node1"}}}}},
want: false,
},
"Different Node PrivateEndpoint": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{PrivateEndpoint: ""}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{PrivateEndpoint: "http://private.node1"}}}}},
want: false,
},
"Different Node PrivateLinkConnectionURL": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{PrivateLinkConnectionURL: ""}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{PrivateLinkConnectionURL: "http://privatelink.node1"}}}}},
want: false,
},

"Different Node ID": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{ID: "node1"}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{ID: "node2"}}}}}},
want: false,
},
"Different Node Size": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Size: "large"}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Size: "small"}}}}}},
want: false,
},
"Different Node PublicAddress": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{PublicAddress: ""}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{PublicAddress: "192.168.1.2"}}}}}},
want: false,
},
"Different Node PrivateAddress": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{PrivateAddress: ""}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{PrivateAddress: "10.0.0.2"}}}}}},
want: false,
},
"Different Node Status": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Status: "PROVISIONING"}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Status: "RUNNING"}}}}}},
want: false,
},
"Different Node Roles": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Roles: []string{""}}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Roles: []string{"MASTER"}}}}}}},
want: false,
},
"Different Node Rack": {
fields: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Rack: ""}}}}}},
args: OpenSearchStatus{DataCentres: []OpenSearchDataCentreStatus{{Nodes: []OpenSearchNodeStatus{{Node: Node{Rack: "rack1"}}}}}},
want: false,
},

"Different OpenSearchNodeStatus PublicEndpoint": {
fields: OpenSearchStatus{
DataCentres: []OpenSearchDataCentreStatus{
{Nodes: []OpenSearchNodeStatus{{PublicEndpoint: ""}}},
},
},
args: OpenSearchStatus{
DataCentres: []OpenSearchDataCentreStatus{
{Nodes: []OpenSearchNodeStatus{{PublicEndpoint: "http://public.node1"}}},
},
},
want: false,
},
"Different OpenSearchNodeStatus PrivateEndpoint": {
fields: OpenSearchStatus{
DataCentres: []OpenSearchDataCentreStatus{
{Nodes: []OpenSearchNodeStatus{{PrivateEndpoint: ""}}},
},
},
args: OpenSearchStatus{
DataCentres: []OpenSearchDataCentreStatus{
{Nodes: []OpenSearchNodeStatus{{PrivateEndpoint: "http://private.node1"}}},
},
},
want: false,
},
"Different OpenSearchNodeStatus PrivateLinkConnectionURL": {
fields: OpenSearchStatus{
DataCentres: []OpenSearchDataCentreStatus{
{Nodes: []OpenSearchNodeStatus{{PrivateLinkConnectionURL: ""}}},
},
},
args: OpenSearchStatus{
DataCentres: []OpenSearchDataCentreStatus{
{Nodes: []OpenSearchNodeStatus{{PrivateLinkConnectionURL: "http://privatelink.node1"}}},
},
},
want: false,
},
}

for name, tt := range tests {
tt := tt

t.Run(name, func(t *testing.T) {
//t.Parallel()
oss := &OpenSearchStatus{
GenericStatus: tt.fields.GenericStatus,
DataCentres: tt.fields.DataCentres,
LoadBalancerConnectionURL: tt.fields.LoadBalancerConnectionURL,
PrivateEndpoint: tt.fields.PrivateEndpoint,
PublicEndpoint: tt.fields.PublicEndpoint,
IngestNodesLoadBalancerConnectionURL: tt.fields.IngestNodesLoadBalancerConnectionURL,
}
if got := oss.Equals(&tt.args); got != tt.want {
t.Errorf("Equals() = %v, want %v", got, tt.want)
}
})
}
}
4 changes: 2 additions & 2 deletions apis/clusters/v1beta1/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ type Cluster struct {
Description string `json:"description,omitempty"`
}

type ClusterStatus struct {
type ClusterStatus[T any] struct {
ID string `json:"id,omitempty"`
State string `json:"state,omitempty"`
DataCentres []*DataCentreStatus `json:"dataCentres,omitempty"`
DataCentres []*T `json:"dataCentres,omitempty"`
CDCID string `json:"cdcid,omitempty"`
TwoFactorDeleteEnabled bool `json:"twoFactorDeleteEnabled,omitempty"`
Options *Options `json:"options,omitempty"`
Expand Down
59 changes: 59 additions & 0 deletions config/samples/clusters_v1beta1_opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,63 @@ spec:
sqlPlugin: false
# resizeSettings:
# - notifySupportContacts: false
# concurrency: 3
---
#apiVersion: clusters.instaclustr.com/v1beta1
#kind: OpenSearch
#metadata:
# labels:
# app.kubernetes.io/name: opensearch
# app.kubernetes.io/instance: opensearch-sample
# app.kubernetes.io/part-of: operator
# app.kuberentes.io/managed-by: kustomize
# app.kubernetes.io/created-by: operator
# name: opensearch-sample2
# annotations:
# test.annotation/first: testAnnotation
#spec:
# name: bohdan-test-2
# alertingPlugin: false
# anomalyDetectionPlugin: false
# asynchronousSearchPlugin: false
# # userRefs:
# # - name: "test-user-1"
# # namespace: "default"
# # - name: "test-user-2"
# # namespace: "default"
# clusterManagerNodes:
# - dedicatedManager: false
# nodeSize: SRH-DEV-t4g.small-5
## nodeSize: SRH-PRD-c5d.2xlarge-200
# 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
# icuPlugin: false
# indexManagementPlugin: true
# knnPlugin: false
# loadBalancer: true
# notificationsPlugin: false
# # opensearchDashboards:
# # - nodeSize: SRH-DEV-t4g.small-5
# # oidcProvider: ''
# # version: opensearch-dashboards:2.5.0
# version: 2.11.1
# pciCompliance: false
# privateNetworkCluster: false
# reportingPlugin: false
# slaTier: NON_PRODUCTION
# sqlPlugin: false
## resizeSettings:
## - notifySupportContacts: false
# concurrency: 3
Loading

0 comments on commit b935480

Please sign in to comment.