Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,22 @@ func (h *SyncMetadataHandler) patchLabelsAndAnnotations(ctx context.Context, obj
patch.NewJSONPatchOperation(patch.PatchReplaceOp, "/metadata/labels", metadata.Labels),
patch.NewJSONPatchOperation(patch.PatchReplaceOp, "/metadata/annotations", metadata.Annotations),
)

// For KubeVirt VirtualMachine, also patch spec.template.metadata
// to ensure consistency with future VMI instances.
// KubeVirt doesn't trigger VMI restart on template metadata changes.
if _, ok := obj.(*virtv1.VirtualMachine); ok {
jp.Append(
patch.NewJSONPatchOperation(patch.PatchReplaceOp, "/spec/template/metadata/labels", metadata.Labels),
patch.NewJSONPatchOperation(patch.PatchReplaceOp, "/spec/template/metadata/annotations", metadata.Annotations),
Comment on lines +148 to +149
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use patch.WithTest and patch.WithReplace

example

jp.Append(
    patch.WithTest(/spec/template/metadata/labels", oldLabels),
    patch.WithReplace(/spec/template/metadata/labels", newLabels),
)

)
}

bytes, err := jp.Bytes()
if err != nil {
return err
}

return h.client.Patch(ctx, obj, client.RawPatch(types.JSONPatchType, bytes))
}

Expand Down
Loading