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

Validation for KafkaSpec fields while update was added, redis DC validation was fixed #479

Merged
merged 1 commit into from
Jul 18, 2023
Merged
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
32 changes: 20 additions & 12 deletions apis/clusters/v1beta1/kafka_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,23 +312,31 @@ type immutableKafkaFields struct {
}

type specificKafkaFields struct {
replicationFactor int
partitionsNumber int
allowDeleteTopics bool
autoCreateTopics bool
clientToClusterEncryption bool
bundledUseOnly bool
replicationFactor int
partitionsNumber int
allowDeleteTopics bool
autoCreateTopics bool
clientToClusterEncryption bool
bundledUseOnly bool
privateNetworkCluster bool
clientAuthBrokerWithEncryption bool
clientAuthBrokerWithoutEncryption bool
clientBrokerAuthWithMtls bool
}

func (ks *KafkaSpec) newKafkaImmutableFields() *immutableKafkaFields {
return &immutableKafkaFields{
specificFields: specificKafkaFields{
replicationFactor: ks.ReplicationFactor,
partitionsNumber: ks.PartitionsNumber,
allowDeleteTopics: ks.AllowDeleteTopics,
autoCreateTopics: ks.AutoCreateTopics,
clientToClusterEncryption: ks.ClientToClusterEncryption,
bundledUseOnly: ks.BundledUseOnly,
replicationFactor: ks.ReplicationFactor,
partitionsNumber: ks.PartitionsNumber,
allowDeleteTopics: ks.AllowDeleteTopics,
autoCreateTopics: ks.AutoCreateTopics,
clientToClusterEncryption: ks.ClientToClusterEncryption,
bundledUseOnly: ks.BundledUseOnly,
privateNetworkCluster: ks.PrivateNetworkCluster,
clientAuthBrokerWithEncryption: ks.ClientAuthBrokerWithEncryption,
clientAuthBrokerWithoutEncryption: ks.ClientAuthBrokerWithoutEncryption,
clientBrokerAuthWithMtls: ks.ClientBrokerAuthWithMTLS,
},
cluster: ks.Cluster.newImmutableFields(),
}
Expand Down
40 changes: 23 additions & 17 deletions apis/clusters/v1beta1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,30 @@ func (rs *RedisSpec) validateDCsUpdate(oldSpec RedisSpec) error {
return models.ErrDecreasedDataCentresNumber
}

for i, oldDC := range oldSpec.DataCentres {
newDC := oldSpec.DataCentres[i]
newDCImmutableFields := newDC.newImmutableFields()
oldDCImmutableFields := oldDC.newImmutableFields()

if *newDCImmutableFields != *oldDCImmutableFields {
return fmt.Errorf("cannot update immutable data centre fields: new spec: %v: old spec: %v", newDCImmutableFields, oldDCImmutableFields)
}

err := newDC.validateImmutableCloudProviderSettingsUpdate(oldDC.CloudProviderSettings)
if err != nil {
return err
}

if newDC.NodesNumber < oldDC.NodesNumber {
return fmt.Errorf("deleting nodes is not supported. Number of nodes must be greater than: %v", oldDC.NodesNumber)
for _, newDC := range rs.DataCentres {
for _, oldDC := range oldSpec.DataCentres {
if newDC.Name == oldDC.Name {
newDCImmutableFields := newDC.newImmutableFields()
oldDCImmutableFields := oldDC.newImmutableFields()

if *newDCImmutableFields != *oldDCImmutableFields {
return fmt.Errorf("cannot update immutable data centre fields: new spec: %v: old spec: %v", newDCImmutableFields, oldDCImmutableFields)
}

err := newDC.validateImmutableCloudProviderSettingsUpdate(oldDC.CloudProviderSettings)
if err != nil {
return err
}

if newDC.MasterNodes < oldDC.MasterNodes {
return fmt.Errorf("deleting nodes is not supported. Number of nodes must be greater than: %v", oldDC.NodesNumber)
}

if newDC.NodesNumber < oldDC.NodesNumber {
return fmt.Errorf("deleting nodes is not supported. Number of nodes must be greater than: %v", oldDC.NodesNumber)
}
}
}

}

for i := len(oldSpec.DataCentres); i < len(rs.DataCentres); i++ {
Expand Down
1 change: 0 additions & 1 deletion apis/clusters/v1beta1/redis_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (rv *redisValidator) ValidateUpdate(ctx context.Context, old runtime.Object
if r.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}

oldRedis, ok := old.(*Redis)
if !ok {
return models.ErrTypeAssertion
Expand Down
2 changes: 1 addition & 1 deletion config/samples/clusterresources_v1beta1_clusterbackup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ kind: ClusterBackup
metadata:
name: clusterbackup-sample
spec:
clusterId: b3eb2b51-1b89-45a1-906d-10cf340c7bd7
clusterId: 2ae611cf-ac91-4325-941c-a35c043f9c34
clusterKind: PostgreSQl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: MaintenanceEvents
metadata:
name: maintenanceevents-sample
spec:
clusterId: "917062a6-a449-4527-a3aa-e3904b04b39f"
clusterId: "2ae611cf-ac91-4325-941c-a35c043f9c34"
exclusionWindows:
- dayOfWeek: "MONDAY"
startHour: 1
Expand Down
4 changes: 2 additions & 2 deletions config/samples/clusterresources_v1beta1_nodereload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ metadata:
name: nodereload-sample
spec:
nodes:
- nodeID: "ac3c5fbd-ffa1-4a73-8b7a-74b68b464a1b"
- nodeID: "4234f82b-aef0-46f1-b52c-d4f4a1139268"
- nodeID: "8b5e3cb1-d1ca-400c-92e5-3279a79133a2"
- nodeID: "8de5f5ad-d776-4c19-a322-1efffe149018"
2 changes: 1 addition & 1 deletion config/samples/clusters_v1beta1_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
# nodeSize: "t3.medium-80-r"
nodeSize: "t3.small-20-r"
masterNodes: 3
nodesNumber: 0
nodesNumber: 3
# - region: "US_WEST_2"
# name: "testDC2"
# cloudProvider: "AWS_VPC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (r *MaintenanceEventsReconciler) Reconcile(ctx context.Context, req ctrl.Re

r.EventRecorder.Eventf(
me, models.Normal, models.Created,
"Cluster backups check job is started",
"Cluster maintenance events check job is started",
)

l.Info("Maintenance Event resource was reconciled",
Expand Down