Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inhrtitance feature for clusters #737

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@
}
],
"results": {
".idea/workspace.xml": [
{
"type": "Base64 High Entropy String",
"filename": ".idea/workspace.xml",
"hashed_secret": "ceda554256d1b9fa42791b09d9798634f930ad04",
"is_verified": false,
"line_number": 42
}
],
"apis/clusterresources/v1beta1/cassandrauser_types.go": [
{
"type": "Secret Keyword",
Expand Down Expand Up @@ -213,7 +204,7 @@
"filename": "apis/clusters/v1beta1/cassandra_webhook.go",
"hashed_secret": "e0a46b27231f798fe22dc4d5d82b5feeb5dcf085",
"is_verified": false,
"line_number": 232
"line_number": 244
}
],
"apis/clusters/v1beta1/kafka_types.go": [
Expand Down Expand Up @@ -356,7 +347,7 @@
"filename": "apis/clusters/v1beta1/redis_webhook.go",
"hashed_secret": "bc1c5ae5fd4a238d86261f422e62c489de408c22",
"is_verified": false,
"line_number": 323
"line_number": 335
}
],
"apis/clusters/v1beta1/zz_generated.deepcopy.go": [
Expand Down Expand Up @@ -501,12 +492,40 @@
}
],
"controllers/clusters/cadence_controller.go": [
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "2d8ca9a11a2e2ef6931d0f0ef52b1896114a4558",
"is_verified": false,
"line_number": 167
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "8902e39ab80b0808afb4654751df63517d106008",
"is_verified": false,
"line_number": 171
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "dd8e1e714663d659a0b6932bfad048e0f0ef1f82",
"is_verified": false,
"line_number": 221
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "2ba76f2b678a4173c4989c88db3505b0a0265d6f",
"is_verified": false,
"line_number": 222
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 750
"line_number": 831
}
],
"controllers/clusters/datatest/kafka_v1beta1.yaml": [
Expand Down Expand Up @@ -558,7 +577,7 @@
"filename": "controllers/clusters/postgresql_controller.go",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 1192
"line_number": 1199
}
],
"controllers/clusters/zookeeper_controller_test.go": [
Expand Down Expand Up @@ -1130,5 +1149,5 @@
}
]
},
"generated_at": "2024-03-05T16:46:11Z"
"generated_at": "2024-03-11T14:02:24Z"
}
62 changes: 62 additions & 0 deletions apis/clusters/v1beta1/cadence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ func (cs *CadenceSpec) FromInstAPI(instaModel *models.CadenceCluster) {
cs.ResizeSettings.FromInstAPI(instaModel.ResizeSettings)

cs.DCsFromInstAPI(instaModel.DataCentres)
cs.StandardProvisioningFromInstAPI(instaModel.StandardProvisioning)
cs.SharedProvisioningFromInstAPI(instaModel.SharedProvisioning)
cs.TargetPrimaryCadenceFromInstAPI(instaModel.TargetPrimaryCadence)

// TODO AWS ARCHIVAL

cs.UseHTTPAPI = instaModel.UseHTTPAPI
cs.UseCadenceWebAuth = instaModel.UseCadenceWebAuth
cs.PCICompliance = instaModel.PCIComplianceMode
}

func (cs *CadenceSpec) DCsFromInstAPI(instaModels []*models.CadenceDataCentre) {
Expand Down Expand Up @@ -590,3 +599,56 @@ func (c *CadenceSpec) CalculateNodeSize(cloudProvider, solution, app string) str
}
return ""
}

func (cs *CadenceSpec) StandardProvisioningFromInstAPI(instaModels []*models.CadenceStandardProvisioning) {
provisioning := make([]*StandardProvisioning, len(instaModels))
for i, instaModel := range instaModels {
p := &StandardProvisioning{}
p.FromInstAPI(instaModel)
provisioning[i] = p
}
cs.StandardProvisioning = provisioning
}

func (s *StandardProvisioning) FromInstAPI(instaModel *models.CadenceStandardProvisioning) {
s.AdvancedVisibility = make([]*AdvancedVisibility, len(instaModel.AdvancedVisibility))
for i, visibility := range instaModel.AdvancedVisibility {
vis := &AdvancedVisibility{
TargetKafka: &CadenceDependencyTarget{
DependencyCDCID: visibility.TargetKafka.DependencyCDCID,
DependencyVPCType: visibility.TargetKafka.DependencyVPCType,
},
TargetOpenSearch: &CadenceDependencyTarget{
DependencyCDCID: visibility.TargetOpenSearch.DependencyCDCID,
DependencyVPCType: visibility.TargetOpenSearch.DependencyVPCType,
},
}
s.AdvancedVisibility[i] = vis
}

if instaModel.TargetCassandra != nil {
s.TargetCassandra = &CadenceDependencyTarget{
DependencyCDCID: instaModel.TargetCassandra.DependencyCDCID,
DependencyVPCType: instaModel.TargetCassandra.DependencyVPCType,
}
}
}

func (cs *CadenceSpec) SharedProvisioningFromInstAPI(instaModels []*models.CadenceSharedProvisioning) {
cs.SharedProvisioning = make([]*SharedProvisioning, len(instaModels))
for i, instaModel := range instaModels {
cs.SharedProvisioning[i] = &SharedProvisioning{
UseAdvancedVisibility: instaModel.UseAdvancedVisibility,
}
}
}

func (cs *CadenceSpec) TargetPrimaryCadenceFromInstAPI(instaModels []*models.CadenceDependencyTarget) {
cs.TargetPrimaryCadence = make([]*CadenceDependencyTarget, len(instaModels))
for i, instaModel := range instaModels {
cs.TargetPrimaryCadence[i] = &CadenceDependencyTarget{
DependencyCDCID: instaModel.DependencyCDCID,
DependencyVPCType: instaModel.DependencyVPCType,
}
}
}
12 changes: 12 additions & 0 deletions apis/clusters/v1beta1/cadence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ var _ webhook.Defaulter = &Cadence{}
func (c *Cadence) Default() {
cadencelog.Info("default", "name", c.Name)

if c.Spec.Inherits() && c.Status.ID == "" && c.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
c.Spec = CadenceSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: c.Spec.InheritsFrom},
DataCentres: []*CadenceDataCentre{{}},
}
c.Spec.GenericClusterSpec.setDefaultValues()
}

if c.Spec.Name == "" {
c.Spec.Name = c.Name
}
Expand Down Expand Up @@ -85,6 +93,10 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje

cadencelog.Info("validate create", "name", c.Name)

if c.Spec.Inherits() {
return nil
}

err := requiredfieldsvalidator.ValidateRequiredFields(c.Spec)
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ var _ webhook.Defaulter = &Cassandra{}
func (c *Cassandra) Default() {
cassandralog.Info("default", "name", c.Name)

if c.Spec.Inherits() && c.Status.ID == "" && c.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
c.Spec = CassandraSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: c.Spec.InheritsFrom},
DataCentres: []*CassandraDataCentre{{}},
}
c.Spec.GenericClusterSpec.setDefaultValues()
}

if c.Spec.Name == "" {
c.Spec.Name = c.Name
}
Expand All @@ -76,6 +84,10 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
return fmt.Errorf("cannot assert object %v to cassandra", obj.GetObjectKind())
}

if c.Spec.Inherits() {
return nil
}

cassandralog.Info("validate create", "name", c.Name)

err := requiredfieldsvalidator.ValidateRequiredFields(c.Spec)
Expand Down
11 changes: 11 additions & 0 deletions apis/clusters/v1beta1/generic_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type GenericClusterSpec struct {

Description string `json:"description,omitempty"`

InheritsFrom string `json:"inheritsFrom,omitempty"`

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

Expand Down Expand Up @@ -227,3 +229,12 @@ func (s *GenericDataCentreSpec) cloudProviderSettingsFromInstAPI(instaModel *mod
}}
}
}

func (s *GenericClusterSpec) Inherits() bool {
return s.InheritsFrom != ""
}

func (in *GenericClusterSpec) setDefaultValues() {
in.Version = "DEFAULT_VERSION"
in.SLATier = "NON_PRODUCTION"
}
12 changes: 12 additions & 0 deletions apis/clusters/v1beta1/kafka_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ var _ webhook.Defaulter = &Kafka{}
func (k *Kafka) Default() {
kafkalog.Info("default", "name", k.Name)

if k.Spec.Inherits() && k.Status.ID == "" && k.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
k.Spec = KafkaSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: k.Spec.InheritsFrom},
DataCentres: []*KafkaDataCentre{{}},
}
k.Spec.GenericClusterSpec.setDefaultValues()
}

if k.Spec.Name == "" {
k.Spec.Name = k.Name
}
Expand All @@ -79,6 +87,10 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object
return fmt.Errorf("cannot assert object %v to kafka", obj.GetObjectKind())
}

if k.Spec.Inherits() {
return nil
}

kafkalog.Info("validate create", "name", k.Name)

err := requiredfieldsvalidator.ValidateRequiredFields(k.Spec)
Expand Down
25 changes: 19 additions & 6 deletions apis/clusters/v1beta1/kafkaconnect_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,24 @@ func (r *KafkaConnect) SetupWebhookWithManager(mgr ctrl.Manager, api validation.
var _ webhook.Defaulter = &KafkaConnect{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *KafkaConnect) Default() {
kafkaconnectlog.Info("default", "name", r.Name)
func (k *KafkaConnect) Default() {
kafkaconnectlog.Info("default", "name", k.Name)

if k.Spec.Inherits() && k.Status.ID == "" && k.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
k.Spec = KafkaConnectSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: k.Spec.InheritsFrom},
DataCentres: []*KafkaConnectDataCentre{},
TargetCluster: []*TargetCluster{},
}
k.Spec.GenericClusterSpec.setDefaultValues()
}

if r.Spec.Name == "" {
r.Spec.Name = r.Name
if k.Spec.Name == "" {
k.Spec.Name = k.Name
}

if r.GetAnnotations() == nil {
r.SetAnnotations(map[string]string{
if k.GetAnnotations() == nil {
k.SetAnnotations(map[string]string{
models.ResourceStateAnnotation: "",
})
}
Expand All @@ -79,6 +88,10 @@ func (kcv *kafkaConnectValidator) ValidateCreate(ctx context.Context, obj runtim
return fmt.Errorf("cannot assert object %v to kafka connect", obj.GetObjectKind())
}

if kc.Spec.Inherits() {
return nil
}

kafkaconnectlog.Info("validate create", "name", kc.Name)

err := requiredfieldsvalidator.ValidateRequiredFields(kc.Spec)
Expand Down
13 changes: 13 additions & 0 deletions apis/clusters/v1beta1/opensearch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ var _ webhook.CustomValidator = &openSearchValidator{}
var _ webhook.Defaulter = &OpenSearch{}

func (os *OpenSearch) Default() {
if os.Spec.Inherits() && os.Status.ID == "" && os.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
os.Spec = OpenSearchSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: os.Spec.InheritsFrom},
DataCentres: []*OpenSearchDataCentre{{}},
ClusterManagerNodes: []*ClusterManagerNodes{{}},
}
os.Spec.GenericClusterSpec.setDefaultValues()
}

for _, dataCentre := range os.Spec.DataCentres {
setDefaultValues(dataCentre)

Expand Down Expand Up @@ -86,6 +95,10 @@ func (osv *openSearchValidator) ValidateCreate(ctx context.Context, obj runtime.
return fmt.Errorf("cannot assert object %v to openSearch", obj.GetObjectKind())
}

if os.Spec.Inherits() {
return nil
}

opensearchlog.Info("validate create", "name", os.Name)

err := requiredfieldsvalidator.ValidateRequiredFields(os.Spec)
Expand Down
12 changes: 12 additions & 0 deletions apis/clusters/v1beta1/postgresql_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ var _ webhook.Defaulter = &PostgreSQL{}
func (pg *PostgreSQL) Default() {
postgresqllog.Info("default", "name", pg.Name)

if pg.Spec.Inherits() && pg.Status.ID == "" && pg.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
pg.Spec = PgSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: pg.Spec.InheritsFrom},
DataCentres: []*PgDataCentre{},
}
pg.Spec.GenericClusterSpec.setDefaultValues()
}

if pg.Spec.Name == "" {
pg.Spec.Name = pg.Name
}
Expand All @@ -78,6 +86,10 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
return fmt.Errorf("cannot assert object %v to postgreSQL", obj.GetObjectKind())
}

if pg.Spec.Inherits() {
return nil
}

postgresqllog.Info("validate create", "name", pg.Name)

err := requiredfieldsvalidator.ValidateRequiredFields(pg.Spec)
Expand Down
12 changes: 12 additions & 0 deletions apis/clusters/v1beta1/redis_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ var _ webhook.Defaulter = &Redis{}
func (r *Redis) Default() {
redislog.Info("default", "name", r.Name)

if r.Spec.Inherits() && r.Status.ID == "" && r.Annotations[models.ResourceStateAnnotation] != models.SyncingEvent {
r.Spec = RedisSpec{
GenericClusterSpec: GenericClusterSpec{InheritsFrom: r.Spec.InheritsFrom},
DataCentres: []*RedisDataCentre{{}},
}
r.Spec.GenericClusterSpec.setDefaultValues()
}

if r.Spec.Name == "" {
r.Spec.Name = r.Name
redislog.Info("default values are set", "name", r.Name)
Expand Down Expand Up @@ -89,6 +97,10 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object
return fmt.Errorf("cannot assert object %v to redis", obj.GetObjectKind())
}

if r.Spec.Inherits() {
return nil
}

redislog.Info("validate create", "name", r.Name)

err := requiredfieldsvalidator.ValidateRequiredFields(r.Spec)
Expand Down
Loading
Loading