Skip to content

Commit

Permalink
fixed a bug when a job deletes itself and it ends up with locked mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Siryk authored and Bohdan Siryk committed Sep 21, 2023
1 parent 88ad6c2 commit 6f03ac9
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/samples/clusters_v1beta1_cassandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
pciCompliance: false
luceneEnabled: false # can be enabled only on 3.11.13 version of Cassandra
passwordAndUserAuth: true
# userRef:
# userRefs:
# - namespace: default
# name: cassandrauser-sample
# - namespace: default
Expand Down
2 changes: 1 addition & 1 deletion config/samples/clusters_v1beta1_postgresql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
# - email: "rostyslp@netapp.com"
# description: "test 222"
slaTier: "NON_PRODUCTION"
# userRef:
# userRefs:
# - namespace: default
# name: postgresqluser-sample
privateNetworkCluster: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (r *AWSSecurityGroupFirewallRuleReconciler) newWatchStatusJob(firewallRule
}

if instaFirewallRuleStatus.Status == statusDELETED {
go r.Scheduler.RemoveJob(firewallRule.GetJobID(scheduler.StatusChecker))
r.Scheduler.RemoveJob(firewallRule.GetJobID(scheduler.StatusChecker))
}
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/clusterresources/awsvpcpeering_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (r *AWSVPCPeeringReconciler) newWatchStatusJob(awsPeering *v1beta1.AWSVPCPe
"namespaced name", namespacedName,
)

go r.Scheduler.RemoveJob(awsPeering.GetJobID(scheduler.StatusChecker))
r.Scheduler.RemoveJob(awsPeering.GetJobID(scheduler.StatusChecker))

return nil
}
Expand Down Expand Up @@ -459,6 +459,7 @@ func (r *AWSVPCPeeringReconciler) newWatchStatusJob(awsPeering *v1beta1.AWSVPCPe
}
}

// SetupWithManager sets up the controller with the Manager.
func (r *AWSVPCPeeringReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1beta1.AWSVPCPeering{}, builder.WithPredicates(predicate.Funcs{
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusters/cadence_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ func (r *CadenceReconciler) newWatchStatusJob(cadence *v1beta1.Cadence) schedule
if k8serrors.IsNotFound(err) {
l.Info("Resource is not found in the k8s cluster. Closing Instaclustr status sync.",
"namespaced name", namespacedName)
go r.Scheduler.RemoveJob(cadence.GetJobID(scheduler.StatusChecker))
r.Scheduler.RemoveJob(cadence.GetJobID(scheduler.StatusChecker))
return nil
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusters/cassandra_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ func (r *CassandraReconciler) newUsersCreationJob(c *v1beta1.Cassandra) schedule
l.Info("User creation job successfully finished", "resource name", c.Name)
r.EventRecorder.Eventf(c, models.Normal, models.Created, "User creation job successfully finished")

go r.Scheduler.RemoveJob(c.GetJobID(scheduler.UserCreator))
r.Scheduler.RemoveJob(c.GetJobID(scheduler.UserCreator))

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusters/kafka_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (r *KafkaReconciler) newUsersCreationJob(kafka *v1beta1.Kafka) scheduler.Jo
"User creation job successfully finished",
)

go r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.UserCreator))
r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.UserCreator))

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusters/opensearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func (r *OpenSearchReconciler) newUsersCreationJob(o *v1beta1.OpenSearch) schedu
"User creation job successfully finished",
)

go r.Scheduler.RemoveJob(o.GetJobID(scheduler.UserCreator))
r.Scheduler.RemoveJob(o.GetJobID(scheduler.UserCreator))

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusters/postgresql_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ func (r *PostgreSQLReconciler) newUsersCreationJob(c *v1beta1.PostgreSQL) schedu
l.Info("User creation job successfully finished", "resource name", c.Name)
r.EventRecorder.Eventf(c, models.Normal, models.Created, "User creation job successfully finished")

go r.Scheduler.RemoveJob(c.GetJobID(scheduler.UserCreator))
r.Scheduler.RemoveJob(c.GetJobID(scheduler.UserCreator))

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/clusters/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ func (r *RedisReconciler) newUsersCreationJob(redis *v1beta1.Redis) scheduler.Jo
"User creation job successfully finished",
)

go r.Scheduler.RemoveJob(redis.GetJobID(scheduler.UserCreator))
r.Scheduler.RemoveJob(redis.GetJobID(scheduler.UserCreator))

return nil
}
Expand All @@ -889,7 +889,7 @@ func (r *RedisReconciler) newWatchStatusJob(redis *v1beta1.Redis) scheduler.Job
"namespaced name", namespacedName)
r.Scheduler.RemoveJob(redis.GetJobID(scheduler.UserCreator))
r.Scheduler.RemoveJob(redis.GetJobID(scheduler.BackupsChecker))
go r.Scheduler.RemoveJob(redis.GetJobID(scheduler.StatusChecker))
r.Scheduler.RemoveJob(redis.GetJobID(scheduler.StatusChecker))
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,7 @@ func (s *scheduler) RemoveJob(jobID string) {
delete(s.workItems, jobID)
s.logger.Info("Job was removed", "job id", jobID)

v.done <- struct{}{}
go func() {
v.done <- struct{}{}
}()
}

0 comments on commit 6f03ac9

Please sign in to comment.