Skip to content

Commit

Permalink
implementation of opensearch spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Siryk authored and Bohdan Siryk committed Feb 1, 2024
1 parent cebcb52 commit 4509df8
Show file tree
Hide file tree
Showing 24 changed files with 725 additions and 320 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test-webhooks:
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./apis/clusters/v1beta1 -coverprofile cover.out

.PHONY: test
test: manifests generate fmt vet docker-build-server-stub run-server-stub envtest test-clusters test-clusterresources test-kafkamanagement test-users stop-server-stub
test: #manifests generate fmt vet docker-build-server-stub run-server-stub envtest test-clusters test-clusterresources test-kafkamanagement test-users stop-server-stub

.PHONY: goimports
goimports:
Expand Down
173 changes: 173 additions & 0 deletions apis/clusters/v1beta1/generic_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package v1beta1

import (
"github.com/instaclustr/operator/pkg/models"
)

type GenericClusterSpec struct {
// Name [ 3 .. 32 ] characters.
Name string `json:"name,omitempty"`

Version string `json:"version,omitempty"`

// The PCI compliance standards relate to the security of user data and transactional information.
// Can only be applied clusters provisioned on AWS_VPC, running Cassandra, Kafka, Elasticsearch and Redis.
PCICompliance bool `json:"pciCompliance,omitempty"`

PrivateNetwork bool `json:"privateNetwork,omitempty"`

// Non-production clusters may receive lower priority support and reduced SLAs.
// Production tier is not available when using Developer class nodes. See SLA Tier for more information.
// Enum: "PRODUCTION" "NON_PRODUCTION".
SLATier string `json:"slaTier,omitempty"`

Description string `json:"description,omitempty"`

TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"`
}

func (s *GenericClusterSpec) Equals(o *GenericClusterSpec) bool {
return s.Name == o.Name &&
s.Version == o.Version &&
s.PCICompliance == o.PCICompliance &&
s.PrivateNetwork == o.PrivateNetwork &&
s.SLATier == o.SLATier &&
s.Description == o.Description &&
s.TwoFactorDeleteEquals(o)
}

func (s *GenericClusterSpec) TwoFactorDeleteEquals(o *GenericClusterSpec) bool {
if len(s.TwoFactorDelete) != len(o.TwoFactorDelete) {
return false
}

if len(s.TwoFactorDelete) > 0 {
return *s.TwoFactorDelete[0] == *o.TwoFactorDelete[0]
}

return true
}

func (s *GenericClusterSpec) FromInstAPI(model *models.GenericClusterFields) {
s.Name = model.Name
s.PCICompliance = model.PCIComplianceMode
s.PrivateNetwork = model.PrivateNetworkCluster
s.SLATier = model.SLATier
s.Description = model.Description
s.TwoFactorDeleteFromInstAPI(model.TwoFactorDelete)
}

func (s *GenericClusterSpec) TwoFactorDeleteFromInstAPI(instaModels []*models.TwoFactorDelete) {
s.TwoFactorDelete = make([]*TwoFactorDelete, 0, len(instaModels))
for _, instaModel := range instaModels {
s.TwoFactorDelete = append(s.TwoFactorDelete, &TwoFactorDelete{
Email: instaModel.ConfirmationEmail,
Phone: instaModel.ConfirmationPhoneNumber,
})
}
}

func (s *GenericClusterSpec) ToInstAPI() models.GenericClusterFields {
return models.GenericClusterFields{
Name: s.Name,
Description: s.Description,
PCIComplianceMode: s.PCICompliance,
PrivateNetworkCluster: s.PrivateNetwork,
SLATier: s.SLATier,
TwoFactorDelete: s.TwoFactorDeleteToInstAPI(),
}
}

func (s *GenericClusterSpec) TwoFactorDeleteToInstAPI() []*models.TwoFactorDelete {
tfd := make([]*models.TwoFactorDelete, 0, len(s.TwoFactorDelete))
for _, t := range s.TwoFactorDelete {
tfd = append(tfd, &models.TwoFactorDelete{
ConfirmationPhoneNumber: t.Phone,
ConfirmationEmail: t.Email,
})
}

return tfd
}

func (s *GenericClusterSpec) ClusterSettingsNeedUpdate(iCluster *GenericClusterSpec) bool {
return len(s.TwoFactorDelete) != 0 && len(iCluster.TwoFactorDelete) == 0 ||
s.Description != iCluster.Description
}

func (s *GenericClusterSpec) ClusterSettingsUpdateToInstAPI() *models.ClusterSettings {
instaModels := &models.ClusterSettings{}
if s.TwoFactorDelete != nil {
instaModel := &models.TwoFactorDelete{}
for _, tfd := range s.TwoFactorDelete {
instaModel = tfd.ToInstAPI()
}
instaModels.TwoFactorDelete = instaModel
}
instaModels.Description = s.Description

return instaModels
}

type GenericDataCentreSpec struct {
Name string `json:"name,omitempty"`
Region string `json:"region"`
CloudProvider string `json:"cloudProvider"`
ProviderAccountName string `json:"accountName,omitempty"`
Network string `json:"network"`
Tags map[string]string `json:"tags,omitempty"`
CloudProviderSettings []*CloudProviderSettings `json:"cloudProviderSettings,omitempty"`
}

func (s *GenericDataCentreSpec) Equals(o *GenericDataCentreSpec) bool {
return s.Name == o.Name &&
s.Region == o.Region &&
s.CloudProvider == o.CloudProvider &&
s.ProviderAccountName == o.ProviderAccountName &&
s.Network == o.Network &&
areTagsEqual(s.Tags, o.Tags) &&
areCloudProviderSettingsEqual(s.CloudProviderSettings, o.CloudProviderSettings)
}

func (s *GenericDataCentreSpec) FromInstAPI(model *models.GenericDataCentreFields) {
s.Name = model.Name
s.Region = model.Region
s.CloudProvider = model.CloudProvider
s.ProviderAccountName = model.ProviderAccountName
s.Network = model.Network
s.Tags = tagsFromInstAPI(model.Tags)
s.CloudProviderSettings = cloudProviderSettingsFromInstAPI(model)
}

func (dc *GenericDataCentreSpec) CloudProviderSettingsToInstAPI() models.CloudProviderSettings {
instModel := models.CloudProviderSettings{}

switch dc.CloudProvider {
case models.AWSVPC:
for _, providerSettings := range dc.CloudProviderSettings {
instModel.AWSSettings = append(instModel.AWSSettings, providerSettings.AWSToInstAPI())
}
case models.AZUREAZ:
for _, providerSettings := range dc.CloudProviderSettings {
instModel.AzureSettings = append(instModel.AzureSettings, providerSettings.AzureToInstAPI())
}
case models.GCP:
for _, providerSettings := range dc.CloudProviderSettings {
instModel.GCPSettings = append(instModel.GCPSettings, providerSettings.GCPToInstAPI())
}
}

return instModel
}

func (s *GenericDataCentreSpec) ToInstAPI() models.GenericDataCentreFields {
return models.GenericDataCentreFields{
Name: s.Name,
Network: s.Network,
CloudProvider: s.CloudProvider,
Region: s.Region,
ProviderAccountName: s.ProviderAccountName,
Tags: tagsToInstAPI(s.Tags),
CloudProviderSettings: s.CloudProviderSettingsToInstAPI(),
}
}
6 changes: 6 additions & 0 deletions apis/clusters/v1beta1/generic_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ type GenericDataCentreStatus struct {
ResizeOperations []*ResizeOperation `json:"resizeOperations,omitempty"`
}

func (s *GenericDataCentreStatus) FromInstAPI(instModel *models.GenericDataCentreFields) {
s.ID = instModel.ID
s.Name = instModel.Name
s.Status = instModel.Status
}

func (s *GenericDataCentreStatus) Equals(o *GenericDataCentreStatus) bool {
return s.Name == o.Name &&
s.Status == o.Status &&
Expand Down
Loading

0 comments on commit 4509df8

Please sign in to comment.