I wouldn’t really classify Cody as a “villain” or “betrayer” simply because he was just following orders. Now, if he elected to go against the Jedi on his own free will, then yes, he indeed would have betrayed them. But again, he was just acting under Order 66 so we gotta cut him some slack.
Yeah I'd say Cody was more like the fighter pilot at the end of the Avengers movie that launched the nuke at New York City. A questionable order to be sure but one that he was trained to follow in the overall service of his country.