Skip to content

Commit

Permalink
Cadence packaged provisioning was refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
testisnullus committed Feb 27, 2024
1 parent 944f92a commit 2a6212c
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 649 deletions.
29 changes: 9 additions & 20 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@
{
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
},
{
"path": "detect_secrets.filters.common.is_baseline_file",
"filename": ".secrets.baseline"
},
{
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
"min_level": 2
Expand Down Expand Up @@ -208,7 +204,7 @@
"filename": "apis/clusters/v1beta1/cassandra_webhook.go",
"hashed_secret": "e0a46b27231f798fe22dc4d5d82b5feeb5dcf085",
"is_verified": false,
"line_number": 235
"line_number": 232
}
],
"apis/clusters/v1beta1/kafka_types.go": [
Expand Down Expand Up @@ -319,21 +315,21 @@
"filename": "apis/clusters/v1beta1/postgresql_types.go",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 355
"line_number": 354
},
{
"type": "Secret Keyword",
"filename": "apis/clusters/v1beta1/postgresql_types.go",
"hashed_secret": "a3d7d4a96d18c8fc5a1cf9c9c01c45b4690b4008",
"is_verified": false,
"line_number": 361
"line_number": 360
},
{
"type": "Secret Keyword",
"filename": "apis/clusters/v1beta1/postgresql_types.go",
"hashed_secret": "a57ce131bd944bdf8ba2f2f93e179dc416ed0315",
"is_verified": false,
"line_number": 481
"line_number": 480
}
],
"apis/clusters/v1beta1/redis_types.go": [
Expand Down Expand Up @@ -365,7 +361,7 @@
"filename": "apis/clusters/v1beta1/redis_webhook.go",
"hashed_secret": "bc1c5ae5fd4a238d86261f422e62c489de408c22",
"is_verified": false,
"line_number": 322
"line_number": 323
}
],
"apis/clusters/v1beta1/zookeeper_types.go": [
Expand All @@ -390,7 +386,7 @@
"filename": "apis/clusters/v1beta1/zz_generated.deepcopy.go",
"hashed_secret": "44e17306b837162269a410204daaa5ecee4ec22c",
"is_verified": false,
"line_number": 1316
"line_number": 1327
}
],
"apis/kafkamanagement/v1beta1/kafkauser_types.go": [
Expand Down Expand Up @@ -529,16 +525,9 @@
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "bcf196cdeea4d7ed8b04dcbbd40111eb5e9abeac",
"is_verified": false,
"line_number": 644
},
{
"type": "Secret Keyword",
"filename": "controllers/clusters/cadence_controller.go",
"hashed_secret": "192d703e91a60432ce06bfe26adfd12f5c7b931f",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 677
"line_number": 750
}
],
"controllers/clusters/datatest/kafka_v1beta1.yaml": [
Expand Down Expand Up @@ -1146,5 +1135,5 @@
}
]
},
"generated_at": "2024-02-21T14:33:43Z"
"generated_at": "2024-02-27T10:56:47Z"
}
20 changes: 14 additions & 6 deletions apis/clusters/v1beta1/cadence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ type AWSArchival struct {
}

type PackagedProvisioning struct {
UseAdvancedVisibility bool `json:"useAdvancedVisibility"`
BundledKafkaSpec *BundledKafkaSpec `json:"bundledKafkaSpec,omitempty"`
BundledOpenSearchSpec *BundledOpenSearchSpec `json:"bundledOpenSearchSpec,omitempty"`
BundledCassandraSpec *BundledCassandraSpec `json:"bundledCassandraSpec"`
UseAdvancedVisibility bool `json:"useAdvancedVisibility"`
SolutionSize string `json:"solutionSize"`
}

type SharedProvisioning struct {
Expand All @@ -131,8 +129,9 @@ type AdvancedVisibility struct {
type CadenceStatus struct {
GenericStatus `json:",inline"`

DataCentres []*CadenceDataCentreStatus `json:"dataCentres,omitempty"`
TargetSecondaryCadence []*CadenceDependencyTarget `json:"targetSecondaryCadence,omitempty"`
PackagedProvisioningClusterRefs []*Reference `json:"packagedProvisioningClusterRefs,omitempty"`
DataCentres []*CadenceDataCentreStatus `json:"dataCentres,omitempty"`
TargetSecondaryCadence []*CadenceDependencyTarget `json:"targetSecondaryCadence,omitempty"`
}

type CadenceDataCentreStatus struct {
Expand Down Expand Up @@ -569,3 +568,12 @@ func (cdc *CadenceDataCentreStatus) Equals(o *CadenceDataCentreStatus) bool {
nodesEqual(cdc.Nodes, o.Nodes) &&
cdc.NumberOfNodes == o.NumberOfNodes
}

func (c *CadenceSpec) CalculateNodeSize(cloudProvider, solution, app string) string {
if appSizes, ok := models.SolutionSizesMap[cloudProvider]; ok {
if solutionMap, ok := appSizes[app]; ok {
return solutionMap[solution]
}
}
return ""
}
125 changes: 11 additions & 114 deletions apis/clusters/v1beta1/cadence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
}
}

err = c.Spec.validatePackagedProvisioningCreation()
if err != nil {
return err
for _, pp := range c.Spec.PackagedProvisioning {
err = pp.validatePackagedProvisioningCreation()
if err != nil {
return err
}
}

for _, dc := range c.Spec.DataCentres {
Expand Down Expand Up @@ -348,24 +350,8 @@ func (cs *CadenceSpec) validatePackagedProvisioning(old []*PackagedProvisioning)
}

for i, pp := range cs.PackagedProvisioning {
if pp.UseAdvancedVisibility {
if pp.BundledKafkaSpec == nil || pp.BundledOpenSearchSpec == nil {
return fmt.Errorf("BundledKafkaSpec and BundledOpenSearchSpec structs must not be empty because UseAdvancedVisibility is set to true")
}
if *pp.BundledKafkaSpec != *old[i].BundledKafkaSpec {
return models.ErrImmutablePackagedProvisioning
}
if *pp.BundledOpenSearchSpec != *old[i].BundledOpenSearchSpec {
return models.ErrImmutablePackagedProvisioning
}
} else {
if pp.BundledKafkaSpec != nil || pp.BundledOpenSearchSpec != nil {
return fmt.Errorf("BundledKafkaSpec and BundledOpenSearchSpec structs must be empty because UseAdvancedVisibility is set to false")
}
}

if *pp.BundledCassandraSpec != *old[i].BundledCassandraSpec ||
pp.UseAdvancedVisibility != old[i].UseAdvancedVisibility {
if pp.UseAdvancedVisibility != old[i].UseAdvancedVisibility ||
pp.SolutionSize != old[i].SolutionSize {
return models.ErrImmutablePackagedProvisioning
}
}
Expand Down Expand Up @@ -507,99 +493,10 @@ func (sp *StandardProvisioning) validate() error {
return nil
}

func (b *BundledKafkaSpec) validate() error {
networkMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(b.Network))
if !networkMatched || err != nil {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28. %v", b.Network, err)
}

err = validateReplicationFactor(models.KafkaReplicationFactors, b.ReplicationFactor)
if err != nil {
return err
}

if ((b.NodesNumber*b.ReplicationFactor)/b.ReplicationFactor)%b.ReplicationFactor != 0 {
return fmt.Errorf("kafka: number of nodes must be a multiple of replication factor: %v", b.ReplicationFactor)
}

return nil
}

func (c *BundledCassandraSpec) validate() error {
networkMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(c.Network))
if !networkMatched || err != nil {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28. %v", c.Network, err)
}

err = validateReplicationFactor(models.CassandraReplicationFactors, c.ReplicationFactor)
if err != nil {
return err
}

if ((c.NodesNumber*c.ReplicationFactor)/c.ReplicationFactor)%c.ReplicationFactor != 0 {
return fmt.Errorf("cassandra: number of nodes must be a multiple of replication factor: %v", c.ReplicationFactor)
}

return nil
}

func (o *BundledOpenSearchSpec) validate() error {
networkMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(o.Network))
if !networkMatched || err != nil {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28. %v", o.Network, err)
}

err = validateOpenSearchNumberOfRacks(o.NumberOfRacks)
if err != nil {
return err
}

return nil
}

func (cs *CadenceSpec) validatePackagedProvisioningCreation() error {
for _, dc := range cs.DataCentres {
for _, pp := range cs.PackagedProvisioning {
if (pp.UseAdvancedVisibility && pp.BundledKafkaSpec == nil) || (pp.UseAdvancedVisibility && pp.BundledOpenSearchSpec == nil) {
return fmt.Errorf("BundledKafkaSpec and BundledOpenSearchSpec structs must not be empty because UseAdvancedVisibility is set to true")
}

if pp.BundledKafkaSpec != nil {
err := pp.BundledKafkaSpec.validate()
if err != nil {
return err
}

err = dc.validateNetwork(pp.BundledKafkaSpec.Network)
if err != nil {
return err
}
}

if pp.BundledCassandraSpec != nil {
err := pp.BundledCassandraSpec.validate()
if err != nil {
return err
}

err = dc.validateNetwork(pp.BundledCassandraSpec.Network)
if err != nil {
return err
}
}

if pp.BundledOpenSearchSpec != nil {
err := pp.BundledOpenSearchSpec.validate()
if err != nil {
return err
}

err = dc.validateNetwork(pp.BundledOpenSearchSpec.Network)
if err != nil {
return err
}
}
}
func (pp *PackagedProvisioning) validatePackagedProvisioningCreation() error {
contains := validation.Contains(pp.SolutionSize, models.SolutionSizes)
if !contains {
return fmt.Errorf("the %s solution size is not supported. Supported ones: %v", pp.SolutionSize, models.SolutionSizes)
}

return nil
Expand Down
4 changes: 0 additions & 4 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ func (cv *cassandraValidator) ValidateUpdate(ctx context.Context, old runtime.Ob
return models.ErrTypeAssertion
}

if oldCluster.Spec.BundledUseOnly && c.Generation != oldCluster.Generation {
return models.ErrBundledUseOnlyResourceUpdateIsNotSupported
}

if oldCluster.Spec.RestoreFrom != nil {
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions apis/clusters/v1beta1/kafka_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ func (kv *kafkaValidator) ValidateUpdate(ctx context.Context, old runtime.Object
return fmt.Errorf("cannot assert object %v to Kafka", old.GetObjectKind())
}

if oldKafka.Spec.BundledUseOnly && k.Generation != oldKafka.Generation {
return models.ErrBundledUseOnlyResourceUpdateIsNotSupported
}

err := k.Spec.validateUpdate(&oldKafka.Spec)
if err != nil {
return fmt.Errorf("cannot update, error: %v", err)
Expand Down
4 changes: 0 additions & 4 deletions apis/clusters/v1beta1/opensearch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ func (osv *openSearchValidator) ValidateUpdate(ctx context.Context, old runtime.

oldCluster := old.(*OpenSearch)

if oldCluster.Spec.BundledUseOnly && !oldCluster.Spec.IsEqual(os.Spec) {
return models.ErrBundledUseOnlyResourceUpdateIsNotSupported
}

if oldCluster.Spec.RestoreFrom != nil {
return nil
}
Expand Down
28 changes: 12 additions & 16 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.

Loading

0 comments on commit 2a6212c

Please sign in to comment.