The affair was outed because of the FBI investigation..supposedly
From the Associated Press
Officials say revelations about the affair that led to Friday's resignation of CIA Director David Petraeus were discovered in the course of an FBI investigation. The officials, briefed on what led to the CIA director's sudden resignation, spoke to The Associated Press on condition of anonymity because they were not authorized to publicly discuss the matter.
It was unclear what the FBI was investigating or when it discovered the Petraeus affair.