You're trying to check if "ply" is set to a group, yet "ply" is never defined.
You're only defining target_ply, never calling_ply, which you have used in the logging.
As stated by JamminR as well, SetUserGroup also requires the player (same way you're using IsUserGroup).
Also, if you're making a command that can only be used on yourself and no one else. You wouldn't really need target_ply, calling_ply would work fine just as-is.
I might have forgotten to mention something, it's sort of late at night here, but this should work:
function ulx.undercover( calling_ply )
if calling_ply:IsUserGroup("owner") then
calling_ply:SetUserGroup("ucowner")
elseif calling_ply:IsUserGroup("ucowner") then
calling_ply:SetUserGroup("owner")
end
ulx.fancyLogAdmin( calling_ply, true, "#A went undercover" )
end
local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercov", true )
undercover:defaultAccess( ULib.ACCESS_ADMIN )
undercover:help( "Makes Mods undercover (no mod tag)" )