From f3a98d8d6d35cac58da94713e8ccb55aa549e0cb Mon Sep 17 00:00:00 2001 From: Bohdan Siryk Date: Wed, 25 Oct 2023 11:33:11 +0300 Subject: [PATCH] issue-598, hadnling of updating bundled use only resources was implemented --- apis/clusters/v1beta1/cassandra_types.go | 3 ++- apis/clusters/v1beta1/cassandra_webhook.go | 4 ++++ apis/clusters/v1beta1/kafka_webhook.go | 4 ++++ apis/clusters/v1beta1/opensearch_webhook.go | 5 +++++ controllers/clusters/cadence_controller.go | 3 +++ pkg/models/errors.go | 6 +++++- 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apis/clusters/v1beta1/cassandra_types.go b/apis/clusters/v1beta1/cassandra_types.go index 060a043fd..71fdf78dc 100644 --- a/apis/clusters/v1beta1/cassandra_types.go +++ b/apis/clusters/v1beta1/cassandra_types.go @@ -395,7 +395,8 @@ func (cs *CassandraSpec) IsEqual(spec CassandraSpec) bool { cs.AreDCsEqual(spec.DataCentres) && cs.LuceneEnabled == spec.LuceneEnabled && cs.PasswordAndUserAuth == spec.PasswordAndUserAuth && - cs.IsSparkEqual(spec.Spark) + cs.IsSparkEqual(spec.Spark) && + cs.BundledUseOnly == spec.BundledUseOnly } func (cs *CassandraSpec) AreDCsEqual(dcs []*CassandraDataCentre) bool { diff --git a/apis/clusters/v1beta1/cassandra_webhook.go b/apis/clusters/v1beta1/cassandra_webhook.go index 8195d30f6..4d4a6fef6 100644 --- a/apis/clusters/v1beta1/cassandra_webhook.go +++ b/apis/clusters/v1beta1/cassandra_webhook.go @@ -160,6 +160,10 @@ func (cv *cassandraValidator) ValidateUpdate(ctx context.Context, old runtime.Ob return models.ErrTypeAssertion } + if oldCluster.Spec.BundledUseOnly && !oldCluster.Spec.IsEqual(c.Spec) { + return models.ErrBundledUseOnlyResourceUpdateIsNotSupported + } + if oldCluster.Spec.RestoreFrom != nil { return nil } diff --git a/apis/clusters/v1beta1/kafka_webhook.go b/apis/clusters/v1beta1/kafka_webhook.go index 4ce2a0868..47971e2ab 100644 --- a/apis/clusters/v1beta1/kafka_webhook.go +++ b/apis/clusters/v1beta1/kafka_webhook.go @@ -173,6 +173,10 @@ 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 && !oldKafka.Spec.IsEqual(k.Spec) { + return models.ErrBundledUseOnlyResourceUpdateIsNotSupported + } + err := k.Spec.validateUpdate(&oldKafka.Spec) if err != nil { return fmt.Errorf("cannot update, error: %v", err) diff --git a/apis/clusters/v1beta1/opensearch_webhook.go b/apis/clusters/v1beta1/opensearch_webhook.go index 5bf96e3b8..41c52dab0 100644 --- a/apis/clusters/v1beta1/opensearch_webhook.go +++ b/apis/clusters/v1beta1/opensearch_webhook.go @@ -211,6 +211,11 @@ 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 } diff --git a/controllers/clusters/cadence_controller.go b/controllers/clusters/cadence_controller.go index 3c95990b9..50aca3498 100644 --- a/controllers/clusters/cadence_controller.go +++ b/controllers/clusters/cadence_controller.go @@ -752,6 +752,7 @@ func (r *CadenceReconciler) newCassandraSpec(cadence *v1beta1.Cadence, latestCas }, DataCentres: cassandraDataCentres, PasswordAndUserAuth: cassPasswordAndUserAuth, + BundledUseOnly: true, } return &v1beta1.Cassandra{ @@ -996,6 +997,7 @@ func (r *CadenceReconciler) newKafkaSpec(cadence *v1beta1.Cadence, latestKafkaVe AllowDeleteTopics: true, AutoCreateTopics: true, ClientToClusterEncryption: clientEncryption, + BundledUseOnly: true, } return &v1beta1.Kafka{ @@ -1080,6 +1082,7 @@ func (r *CadenceReconciler) newOpenSearchSpec(cadence *v1beta1.Cadence, oldestOp }, DataCentres: osDataCentres, ClusterManagerNodes: managerNodes, + BundledUseOnly: true, } return &v1beta1.OpenSearch{ diff --git a/pkg/models/errors.go b/pkg/models/errors.go index 13b133067..a642f48bd 100644 --- a/pkg/models/errors.go +++ b/pkg/models/errors.go @@ -16,7 +16,9 @@ limitations under the License. package models -import "errors" +import ( + "errors" +) var ( ErrNotEmptyCSRs = errors.New("certificate creation allowed only if the user is created on the specific cluster") @@ -65,4 +67,6 @@ var ( ErrExposeServiceNotCreatedYet = errors.New("expose service is not created yet") ErrExposeServiceEndpointsNotCreatedYet = errors.New("expose service endpoints is not created yet") ErrOnlySingleConcurrentResizeAvailable = errors.New("only single concurrent resize is allowed") + + ErrBundledUseOnlyResourceUpdateIsNotSupported = errors.New("updating of bundled use resource is not supported") )