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

Cluster Sync Event #715

Merged
merged 1 commit into from
Feb 19, 2024
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
12 changes: 6 additions & 6 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -1089,35 +1089,35 @@
"filename": "pkg/models/operator.go",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 153
"line_number": 154
},
{
"type": "Secret Keyword",
"filename": "pkg/models/operator.go",
"hashed_secret": "d65d45369e8aef106a8ca1c3bad151ad24163494",
"is_verified": false,
"line_number": 183
"line_number": 184
},
{
"type": "Secret Keyword",
"filename": "pkg/models/operator.go",
"hashed_secret": "638724dcc0799a22cc4adce12434fcac73c8af58",
"is_verified": false,
"line_number": 184
"line_number": 185
},
{
"type": "Secret Keyword",
"filename": "pkg/models/operator.go",
"hashed_secret": "4fe486f255f36f8787d5c5cc1185e3d5d5c91c03",
"is_verified": false,
"line_number": 185
"line_number": 186
},
{
"type": "Secret Keyword",
"filename": "pkg/models/operator.go",
"hashed_secret": "2331919a92cbb5c2d530947171fa5e1a1415af2f",
"is_verified": false,
"line_number": 186
"line_number": 187
}
],
"pkg/utils/user_creds_from_secret_test.go": [
Expand Down Expand Up @@ -1146,5 +1146,5 @@
}
]
},
"generated_at": "2024-02-16T12:41:16Z"
"generated_at": "2024-02-19T13:01:03Z"
}
10 changes: 5 additions & 5 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ func (cv *cassandraValidator) ValidateUpdate(ctx context.Context, old runtime.Ob
return fmt.Errorf("cannot assert object %v to cassandra", new.GetObjectKind())
}

if c.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return nil
}

// skip validation when we receive cluster specification update from the Instaclustr Console.
if c.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if c.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}

Expand All @@ -162,10 +166,6 @@ func (cv *cassandraValidator) ValidateUpdate(ctx context.Context, old runtime.Ob

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

if c.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}

oldCluster, ok := old.(*Cassandra)
if !ok {
return models.ErrTypeAssertion
Expand Down
12 changes: 6 additions & 6 deletions apis/clusters/v1beta1/kafka_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ func (kv *kafkaValidator) ValidateUpdate(ctx context.Context, old runtime.Object
return fmt.Errorf("cannot assert object %v to kafka", new.GetObjectKind())
}

if k.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if k.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return nil
}

// skip validation when handle external changes from Instaclustr
if k.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}

Expand All @@ -181,11 +186,6 @@ func (kv *kafkaValidator) ValidateUpdate(ctx context.Context, old runtime.Object

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

// skip validation when handle external changes from Instaclustr
if k.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}

oldKafka, ok := old.(*Kafka)
if !ok {
return fmt.Errorf("cannot assert object %v to Kafka", old.GetObjectKind())
Expand Down
17 changes: 6 additions & 11 deletions apis/clusters/v1beta1/opensearch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,21 @@ func (osv *openSearchValidator) ValidateUpdate(ctx context.Context, old runtime.
return fmt.Errorf("cannot assert object %v to openSearch", new.GetObjectKind())
}

if os.Status.ID == "" {
return osv.ValidateCreate(ctx, os)
if os.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return nil
}

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

oldCluster := old.(*OpenSearch)

if os.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if os.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}

// skip validation when we receive cluster specification update from the Instaclustr Console.
if os.Status.ID == "" {
return osv.ValidateCreate(ctx, os)
}

if os.Annotations[models.ExternalChangesAnnotation] == models.True {
return nil
}
opensearchlog.Info("validate update", "name", os.Name)

oldCluster := old.(*OpenSearch)

if oldCluster.Spec.BundledUseOnly && !oldCluster.Spec.IsEqual(os.Spec) {
return models.ErrBundledUseOnlyResourceUpdateIsNotSupported
Expand Down
14 changes: 7 additions & 7 deletions apis/clusters/v1beta1/redis_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ func (rv *redisValidator) ValidateUpdate(ctx context.Context, old runtime.Object
return fmt.Errorf("cannot assert object %v to redis", new.GetObjectKind())
}

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

if r.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if r.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return nil
}

Expand All @@ -172,15 +170,17 @@ func (rv *redisValidator) ValidateUpdate(ctx context.Context, old runtime.Object
return nil
}

if r.Status.ID == "" {
return rv.ValidateCreate(ctx, r)
}

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

oldRedis, ok := old.(*Redis)
if !ok {
return models.ErrTypeAssertion
}

if r.Status.ID == "" {
return rv.ValidateCreate(ctx, r)
}

if oldRedis.Spec.RestoreFrom != nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions apis/clusters/v1beta1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func validateIngestNodes(new, old []*OpenSearchIngestNodes) error {
return models.ErrImmutableIngestNodes
}

if *old[0] != *new[0] {
if len(old) > 0 && *old[0] != *new[0] {
return models.ErrImmutableIngestNodes
}

Expand All @@ -240,7 +240,7 @@ func validateClusterManagedNodes(new, old []*ClusterManagerNodes) error {
return models.ErrImmutableClusterManagedNodes
}

if *old[0] != *new[0] {
if len(old) > 0 && *old[0] != *new[0] {
return models.ErrImmutableClusterManagedNodes
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/clusters/cassandra_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (r *CassandraReconciler) createCluster(ctx context.Context, c *v1beta1.Cass
}

c.Spec.FromInstAPI(instModel)
c.Annotations[models.ResourceStateAnnotation] = models.SyncingEvent
err = r.Update(ctx, c)
if err != nil {
return fmt.Errorf("failed to update cassandra spec, err: %w", err)
Expand Down Expand Up @@ -1054,7 +1055,7 @@ func (r *CassandraReconciler) SetupWithManager(mgr ctrl.Manager) error {

newObj := event.ObjectNew.(*v1beta1.Cassandra)

if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return false
}

Expand Down
5 changes: 3 additions & 2 deletions controllers/clusters/kafka_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (r *KafkaReconciler) createCluster(ctx context.Context, k *v1beta1.Kafka, l
)

k.Spec.FromInstAPI(&instaModel)
k.Annotations[models.ResourceStateAnnotation] = models.SyncingEvent
err = r.Update(ctx, k)
if err != nil {
return fmt.Errorf("failed to update kafka spec, err: %w", err)
Expand Down Expand Up @@ -692,8 +693,8 @@ func (r *KafkaReconciler) SetupWithManager(mgr ctrl.Manager) error {

newObj := event.ObjectNew.(*v1beta1.Kafka)

if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
return true
if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return false
}

if newObj.Status.ID == "" {
Expand Down
3 changes: 2 additions & 1 deletion controllers/clusters/opensearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (r *OpenSearchReconciler) createCluster(ctx context.Context, o *v1beta1.Ope
}

o.Spec.FromInstAPI(instaModel)
o.Annotations[models.ResourceStateAnnotation] = models.SyncingEvent
err = r.Update(ctx, o)
if err != nil {
return fmt.Errorf("failed to update cluster spec, err: %w", err)
Expand Down Expand Up @@ -932,7 +933,7 @@ func (r *OpenSearchReconciler) SetupWithManager(mgr ctrl.Manager) error {

newObj := event.ObjectNew.(*v1beta1.OpenSearch)

if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return false
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/clusters/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (r *RedisReconciler) createCluster(ctx context.Context, redis *v1beta1.Redi
}

redis.Spec.FromInstAPI(instaModel)
redis.Annotations[models.ResourceStateAnnotation] = models.SyncingEvent
err = r.Update(ctx, redis)
if err != nil {
return fmt.Errorf("failed to update redis spec, err: %w", err)
Expand Down Expand Up @@ -961,7 +962,7 @@ func (r *RedisReconciler) SetupWithManager(mgr ctrl.Manager) error {

newObj := event.ObjectNew.(*v1beta1.Redis)

if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.CreatingEvent {
if newObj.Status.ID == "" && newObj.Annotations[models.ResourceStateAnnotation] == models.SyncingEvent {
return false
}

Expand Down
1 change: 1 addition & 0 deletions pkg/models/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const (
GenericEvent = "generic"
SecretEvent = "secret"
ClusterDeletingEvent = "cluster deleting"
SyncingEvent = "syncing"
)

const (
Expand Down
Loading