@@ -2845,6 +2845,333 @@ func Test_getPortConfig(t *testing.T) {
28452845 },
28462846 nil ,
28472847 },
2848+ {
2849+ "different algorithm specified for tcp protocol" ,
2850+ & v1.Service {
2851+ ObjectMeta : metav1.ObjectMeta {
2852+ Name : randString (),
2853+ UID : "abc123" ,
2854+ Annotations : map [string ]string {
2855+ annotations .AnnLinodeDefaultProtocol : "tcp" ,
2856+ annotations .AnnLinodeDefaultAlgorithm : string (linodego .AlgorithmSource ),
2857+ },
2858+ },
2859+ },
2860+ v1.ServicePort {
2861+ Name : "test" ,
2862+ Protocol : v1 .ProtocolTCP ,
2863+ Port : 443 ,
2864+ },
2865+ portConfig {
2866+ Port : 443 ,
2867+ Protocol : "tcp" ,
2868+ ProxyProtocol : linodego .ProxyProtocolNone ,
2869+ Algorithm : linodego .AlgorithmSource ,
2870+ },
2871+ nil ,
2872+ },
2873+ {
2874+ "algorithm ring_hash is not allowed for tcp protocol" ,
2875+ & v1.Service {
2876+ ObjectMeta : metav1.ObjectMeta {
2877+ Name : randString (),
2878+ UID : "abc123" ,
2879+ Annotations : map [string ]string {
2880+ annotations .AnnLinodeDefaultProtocol : "tcp" ,
2881+ annotations .AnnLinodeDefaultAlgorithm : string (linodego .AlgorithmRingHash ),
2882+ },
2883+ },
2884+ },
2885+ v1.ServicePort {
2886+ Name : "test" ,
2887+ Protocol : v1 .ProtocolTCP ,
2888+ Port : 443 ,
2889+ },
2890+ portConfig {
2891+ Port : 443 ,
2892+ Protocol : "tcp" ,
2893+ ProxyProtocol : linodego .ProxyProtocolNone ,
2894+ },
2895+ fmt .Errorf ("invalid algorithm: %q specified for TCP/HTTP/HTTPS protocol" , string (linodego .AlgorithmRingHash )),
2896+ },
2897+ {
2898+ "default udp protocol specified" ,
2899+ & v1.Service {
2900+ ObjectMeta : metav1.ObjectMeta {
2901+ Name : randString (),
2902+ UID : "abc123" ,
2903+ Annotations : map [string ]string {
2904+ annotations .AnnLinodeDefaultProtocol : "udp" ,
2905+ },
2906+ },
2907+ },
2908+ v1.ServicePort {
2909+ Name : "test" ,
2910+ Protocol : v1 .ProtocolUDP ,
2911+ Port : 2222 ,
2912+ },
2913+ portConfig {
2914+ Port : 2222 ,
2915+ Protocol : "udp" ,
2916+ ProxyProtocol : linodego .ProxyProtocolNone ,
2917+ Algorithm : linodego .AlgorithmRoundRobin ,
2918+ Stickiness : linodego .StickinessSession ,
2919+ UDPCheckPort : 80 ,
2920+ },
2921+ nil ,
2922+ },
2923+ {
2924+ "default udp protocol with different port specific udp check port specified" ,
2925+ & v1.Service {
2926+ ObjectMeta : metav1.ObjectMeta {
2927+ Name : randString (),
2928+ UID : "abc123" ,
2929+ Annotations : map [string ]string {
2930+ annotations .AnnLinodeDefaultProtocol : "udp" ,
2931+ annotations .AnnLinodePortConfigPrefix + "2222" : `{"udp-check-port": "8080"}` ,
2932+ },
2933+ },
2934+ },
2935+ v1.ServicePort {
2936+ Name : "test" ,
2937+ Protocol : v1 .ProtocolUDP ,
2938+ Port : 2222 ,
2939+ },
2940+ portConfig {
2941+ Port : 2222 ,
2942+ Protocol : "udp" ,
2943+ ProxyProtocol : linodego .ProxyProtocolNone ,
2944+ Algorithm : linodego .AlgorithmRoundRobin ,
2945+ Stickiness : linodego .StickinessSession ,
2946+ UDPCheckPort : 8080 ,
2947+ },
2948+ nil ,
2949+ },
2950+ {
2951+ "default udp protocol with different global udp check port specified" ,
2952+ & v1.Service {
2953+ ObjectMeta : metav1.ObjectMeta {
2954+ Name : randString (),
2955+ UID : "abc123" ,
2956+ Annotations : map [string ]string {
2957+ annotations .AnnLinodeDefaultProtocol : "udp" ,
2958+ annotations .AnnLinodeUDPCheckPort : "8080" ,
2959+ },
2960+ },
2961+ },
2962+ v1.ServicePort {
2963+ Name : "test" ,
2964+ Protocol : v1 .ProtocolUDP ,
2965+ Port : 2222 ,
2966+ },
2967+ portConfig {
2968+ Port : 2222 ,
2969+ Protocol : "udp" ,
2970+ ProxyProtocol : linodego .ProxyProtocolNone ,
2971+ Algorithm : linodego .AlgorithmRoundRobin ,
2972+ Stickiness : linodego .StickinessSession ,
2973+ UDPCheckPort : 8080 ,
2974+ },
2975+ nil ,
2976+ },
2977+ {
2978+ "invalid proxyprotocol specified for udp protocol" ,
2979+ & v1.Service {
2980+ ObjectMeta : metav1.ObjectMeta {
2981+ Name : randString (),
2982+ UID : "abc123" ,
2983+ Annotations : map [string ]string {
2984+ annotations .AnnLinodeDefaultProtocol : "udp" ,
2985+ annotations .AnnLinodeDefaultProxyProtocol : string (linodego .ProxyProtocolV1 ),
2986+ },
2987+ },
2988+ },
2989+ v1.ServicePort {
2990+ Name : "test" ,
2991+ Protocol : v1 .ProtocolUDP ,
2992+ Port : 2222 ,
2993+ },
2994+ portConfig {
2995+ Port : 2222 ,
2996+ Protocol : "udp" ,
2997+ },
2998+ fmt .Errorf ("proxy protocol [%s] is not supported for UDP" , string (linodego .ProxyProtocolV1 )),
2999+ },
3000+ {
3001+ "algorithm source is not allowed for udp protocol" ,
3002+ & v1.Service {
3003+ ObjectMeta : metav1.ObjectMeta {
3004+ Name : randString (),
3005+ UID : "abc123" ,
3006+ Annotations : map [string ]string {
3007+ annotations .AnnLinodeDefaultProtocol : "udp" ,
3008+ annotations .AnnLinodeDefaultAlgorithm : string (linodego .AlgorithmSource ),
3009+ },
3010+ },
3011+ },
3012+ v1.ServicePort {
3013+ Name : "test" ,
3014+ Protocol : v1 .ProtocolUDP ,
3015+ Port : 2222 ,
3016+ },
3017+ portConfig {
3018+ Port : 2222 ,
3019+ Protocol : "udp" ,
3020+ ProxyProtocol : linodego .ProxyProtocolNone ,
3021+ },
3022+ fmt .Errorf ("invalid algorithm: %q specified for UDP protocol" , string (linodego .AlgorithmSource )),
3023+ },
3024+ {
3025+ "udp_check_port should be within 1-65535" ,
3026+ & v1.Service {
3027+ ObjectMeta : metav1.ObjectMeta {
3028+ Name : randString (),
3029+ UID : "abc123" ,
3030+ Annotations : map [string ]string {
3031+ annotations .AnnLinodeDefaultProtocol : "udp" ,
3032+ annotations .AnnLinodePortConfigPrefix + "2222" : `{"udp-check-port": "88888"}` ,
3033+ },
3034+ },
3035+ },
3036+ v1.ServicePort {
3037+ Name : "test" ,
3038+ Protocol : v1 .ProtocolUDP ,
3039+ Port : 2222 ,
3040+ },
3041+ portConfig {
3042+ Port : 2222 ,
3043+ Protocol : "udp" ,
3044+ ProxyProtocol : linodego .ProxyProtocolNone ,
3045+ Algorithm : linodego .AlgorithmRoundRobin ,
3046+ },
3047+ fmt .Errorf ("UDPCheckPort must be between 1 and 65535, got %d" , 88888 ),
3048+ },
3049+ {
3050+ "tls secret is not allowed for udp protocol" ,
3051+ & v1.Service {
3052+ ObjectMeta : metav1.ObjectMeta {
3053+ Name : randString (),
3054+ UID : "abc123" ,
3055+ Annotations : map [string ]string {
3056+ annotations .AnnLinodeDefaultProtocol : "udp" ,
3057+ annotations .AnnLinodePortConfigPrefix + "2222" : `{"tls-secret-name": "test"}` ,
3058+ },
3059+ },
3060+ },
3061+ v1.ServicePort {
3062+ Name : "test" ,
3063+ Protocol : v1 .ProtocolUDP ,
3064+ Port : 2222 ,
3065+ },
3066+ portConfig {
3067+ Port : 2222 ,
3068+ Protocol : "udp" ,
3069+ ProxyProtocol : linodego .ProxyProtocolNone ,
3070+ Algorithm : linodego .AlgorithmRoundRobin ,
3071+ },
3072+ fmt .Errorf ("specifying TLS secret name is not supported for UDP" ),
3073+ },
3074+ {
3075+ "no error on stickiness for tcp protocol, it gets ignored" ,
3076+ & v1.Service {
3077+ ObjectMeta : metav1.ObjectMeta {
3078+ Name : randString (),
3079+ UID : "abc123" ,
3080+ Annotations : map [string ]string {
3081+ annotations .AnnLinodeDefaultProtocol : "tcp" ,
3082+ annotations .AnnLinodePortConfigPrefix + "443" : `{"stickiness": "table"}` ,
3083+ },
3084+ },
3085+ },
3086+ v1.ServicePort {
3087+ Name : "test" ,
3088+ Protocol : v1 .ProtocolUDP ,
3089+ Port : 443 ,
3090+ },
3091+ portConfig {
3092+ Port : 443 ,
3093+ Protocol : "tcp" ,
3094+ ProxyProtocol : linodego .ProxyProtocolNone ,
3095+ Algorithm : linodego .AlgorithmRoundRobin ,
3096+ },
3097+ nil ,
3098+ },
3099+ {
3100+ "stickiness table is not allowed for udp protocol" ,
3101+ & v1.Service {
3102+ ObjectMeta : metav1.ObjectMeta {
3103+ Name : randString (),
3104+ UID : "abc123" ,
3105+ Annotations : map [string ]string {
3106+ annotations .AnnLinodeDefaultProtocol : "udp" ,
3107+ annotations .AnnLinodeDefaultStickiness : string (linodego .StickinessTable ),
3108+ },
3109+ },
3110+ },
3111+ v1.ServicePort {
3112+ Name : "test" ,
3113+ Protocol : v1 .ProtocolUDP ,
3114+ Port : 2222 ,
3115+ },
3116+ portConfig {
3117+ Port : 2222 ,
3118+ Protocol : "udp" ,
3119+ ProxyProtocol : linodego .ProxyProtocolNone ,
3120+ Algorithm : linodego .AlgorithmRoundRobin ,
3121+ UDPCheckPort : 80 ,
3122+ },
3123+ fmt .Errorf ("invalid stickiness: %q specified for UDP protocol" , linodego .StickinessTable ),
3124+ },
3125+ {
3126+ "stickiness session is not allowed for http protocol" ,
3127+ & v1.Service {
3128+ ObjectMeta : metav1.ObjectMeta {
3129+ Name : randString (),
3130+ UID : "abc123" ,
3131+ Annotations : map [string ]string {
3132+ annotations .AnnLinodeDefaultProtocol : "http" ,
3133+ annotations .AnnLinodeDefaultStickiness : string (linodego .StickinessSession ),
3134+ },
3135+ },
3136+ },
3137+ v1.ServicePort {
3138+ Name : "test" ,
3139+ Protocol : v1 .ProtocolTCP ,
3140+ Port : 443 ,
3141+ },
3142+ portConfig {
3143+ Port : 443 ,
3144+ Protocol : "http" ,
3145+ ProxyProtocol : linodego .ProxyProtocolNone ,
3146+ Algorithm : linodego .AlgorithmRoundRobin ,
3147+ },
3148+ fmt .Errorf ("invalid stickiness: %q specified for HTTP protocol" , linodego .StickinessSession ),
3149+ },
3150+ {
3151+ "stickiness session is not allowed for https protocol" ,
3152+ & v1.Service {
3153+ ObjectMeta : metav1.ObjectMeta {
3154+ Name : randString (),
3155+ UID : "abc123" ,
3156+ Annotations : map [string ]string {
3157+ annotations .AnnLinodeDefaultProtocol : "https" ,
3158+ annotations .AnnLinodeDefaultStickiness : string (linodego .StickinessSession ),
3159+ },
3160+ },
3161+ },
3162+ v1.ServicePort {
3163+ Name : "test" ,
3164+ Protocol : v1 .ProtocolTCP ,
3165+ Port : 443 ,
3166+ },
3167+ portConfig {
3168+ Port : 443 ,
3169+ Protocol : "https" ,
3170+ ProxyProtocol : linodego .ProxyProtocolNone ,
3171+ Algorithm : linodego .AlgorithmRoundRobin ,
3172+ },
3173+ fmt .Errorf ("invalid stickiness: %q specified for HTTPS protocol" , linodego .StickinessSession ),
3174+ },
28483175 {
28493176 "default capitalized protocol specified" ,
28503177 & v1.Service {
0 commit comments