Use deepcopy to propagate the spec to clusters.

Avoid sharing pointers to the same spec data between the informer
and the clusters. The only catch is that the error field is cleared
during deepcopy, since it is an interface that may contain private
fields that cannot be copied, however, the error is only used when
the manifest is parsed and before it is queued, therefore, we never
refer to that field in the cluster structure.
This commit is contained in:
Oleksii Kliukin
2018-05-17 16:05:12 +02:00
parent ebe50abccb
commit da4cc2705b
5 changed files with 42 additions and 22 deletions
+5 -15
View File
@@ -348,10 +348,9 @@ func (c *Controller) mergeDeprecatedPostgreSQLSpecParameters(spec *spec.Postgres
func (c *Controller) queueClusterEvent(informerOldSpec, informerNewSpec *spec.Postgresql, eventType spec.EventType) {
var (
uid types.UID
clusterName spec.NamespacedName
clusterError error
oldSpec, newSpec *spec.Postgresql
uid types.UID
clusterName spec.NamespacedName
clusterError error
)
if informerOldSpec != nil { //update, delete
@@ -380,22 +379,13 @@ func (c *Controller) queueClusterEvent(informerOldSpec, informerNewSpec *spec.Po
// in the informer internal state, making it incohherent with the actual Kubernetes object (and, as a side
// effect, the modified state will be returned together with subsequent events).
if informerOldSpec != nil {
t := *informerOldSpec
oldSpec = &t
}
if informerNewSpec != nil {
t := *informerNewSpec
newSpec = &t
}
workerID := c.clusterWorkerID(clusterName)
clusterEvent := spec.ClusterEvent{
EventTime: time.Now(),
EventType: eventType,
UID: uid,
OldSpec: oldSpec,
NewSpec: newSpec,
OldSpec: informerOldSpec.Clone(),
NewSpec: informerNewSpec.Clone(),
WorkerID: workerID,
}