Skip to content

Commit

Permalink
Deep copy object before invoking Client (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandswaminathan committed Oct 3, 2019
1 parent 25595fd commit cb881dd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/clusterresource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,14 @@ func (c *controller) syncNamespace(ctx context.Context, namespace NamespaceName)
c.appliedTemplates[namespace] = make(LastModTimeCache)
}
for _, target := range c.executionCluster.GetAllValidTargets() {
err = target.Client.Create(ctx, k8sObj)
k8sObjCopy := k8sObj.DeepCopyObject()
err = target.Client.Create(ctx, k8sObjCopy)
if err != nil {
if k8serrors.IsAlreadyExists(err) {
logger.Debugf(ctx, "Resource [%+v] in namespace [%s] already exists - attempting update instead",
k8sObj.GetObjectKind().GroupVersionKind().Kind, namespace)
c.metrics.AppliedTemplateExists.Inc()
err = target.Client.Patch(ctx, k8sObj, client.MergeFrom(k8sObj))
err = target.Client.Patch(ctx, k8sObjCopy, client.MergeFrom(k8sObjCopy))
if err != nil {
c.metrics.TemplateUpdateErrors.Inc()
logger.Infof(ctx, "Failed to update resource [%+v] in namespace [%s] with err :%v",
Expand Down

0 comments on commit cb881dd

Please sign in to comment.