Skip to content

Commit

Permalink
Fix createTargetObject for object whose namespace is mutated
Browse files Browse the repository at this point in the history
Previously, createTargetObject updated an object using the metadata
(including namespace) of the unmutated object, even when the object
was mutated.
  • Loading branch information
dlipovetsky committed Jul 29, 2024
1 parent 2f7c92a commit 88476cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,12 +946,10 @@ func (o *objectMover) createTargetObject(ctx context.Context, nodeToCreate *node
obj := &unstructured.Unstructured{}
obj.SetAPIVersion(nodeToCreate.identity.APIVersion)
obj.SetKind(nodeToCreate.identity.Kind)
objKey := client.ObjectKey{
Namespace: nodeToCreate.identity.Namespace,
Name: nodeToCreate.identity.Name,
}
obj.SetName(nodeToCreate.identity.Name)
obj.SetNamespace(nodeToCreate.identity.Namespace)

if err := cFrom.Get(ctx, objKey, obj); err != nil {
if err := cFrom.Get(ctx, client.ObjectKeyFromObject(obj), obj); err != nil {
return errors.Wrapf(err, "error reading %q %s/%s",
obj.GroupVersionKind(), obj.GetNamespace(), obj.GetName())
}
Expand Down Expand Up @@ -1006,7 +1004,7 @@ func (o *objectMover) createTargetObject(ctx context.Context, nodeToCreate *node
existingTargetObj := &unstructured.Unstructured{}
existingTargetObj.SetAPIVersion(obj.GetAPIVersion())
existingTargetObj.SetKind(obj.GetKind())
if err := cTo.Get(ctx, objKey, existingTargetObj); err != nil {
if err := cTo.Get(ctx, client.ObjectKeyFromObject(obj), existingTargetObj); err != nil {
return errors.Wrapf(err, "error reading resource for %q %s/%s",
existingTargetObj.GroupVersionKind(), existingTargetObj.GetNamespace(), existingTargetObj.GetName())
}
Expand Down

0 comments on commit 88476cd

Please sign in to comment.