It should be about competence, not marital fidelity" argument, when applied to somebody like General Petraeus, band if people choose to elect a President who has "made mistakes in his marriage" they have no business acting shocked when he makes more "mistakes". I have sympathy for the idea that one of the leading reasons that sexual behaviors put people at risk of blackmail is because of the fear of public disclosure.
But here's the thing: Even if there were no public stigma or shame in having an affair, it would remain grounds for divorce. And thus there would remain an incentive to keep the affair secret and, consequently, the possibility of blackmail would also remain.
So... hit divorce court first, then it's "dating", nobody cares, and you can keep your job.