Opers, surface defects, and Yang-Yang functional