@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"net"
23
23
"reflect"
24
+ "sort"
24
25
"strings"
25
26
"testing"
26
27
@@ -695,6 +696,236 @@ func TestNodePort(t *testing.T) {
695
696
},
696
697
},
697
698
},
699
+ {
700
+ name : "node port service with protocol sctp on a node with multiple nodeIPs" ,
701
+ services : []* v1.Service {
702
+ makeTestService ("ns1" , "svc1" , func (svc * v1.Service ) {
703
+ svc .Spec .Type = "NodePort"
704
+ svc .Spec .ClusterIP = "10.20.30.41"
705
+ svc .Spec .Ports = []v1.ServicePort {{
706
+ Name : "p80" ,
707
+ Port : int32 (80 ),
708
+ Protocol : v1 .ProtocolSCTP ,
709
+ NodePort : int32 (3001 ),
710
+ }}
711
+ }),
712
+ },
713
+ endpoints : []* v1.Endpoints {
714
+ makeTestEndpoints ("ns1" , "svc1" , func (ept * v1.Endpoints ) {
715
+ ept .Subsets = []v1.EndpointSubset {{
716
+ Addresses : []v1.EndpointAddress {{
717
+ IP : "10.180.0.1" ,
718
+ }},
719
+ Ports : []v1.EndpointPort {{
720
+ Name : "p80" ,
721
+ Port : int32 (80 ),
722
+ }},
723
+ }}
724
+ }),
725
+ },
726
+ nodeIPs : []net.IP {
727
+ net .ParseIP ("100.101.102.103" ),
728
+ net .ParseIP ("100.101.102.104" ),
729
+ net .ParseIP ("100.101.102.105" ),
730
+ net .ParseIP ("2001:db8::1:1" ),
731
+ net .ParseIP ("2001:db8::1:2" ),
732
+ net .ParseIP ("2001:db8::1:3" ),
733
+ },
734
+ nodePortAddresses : []string {},
735
+ expectedIPVS : & ipvstest.FakeIPVS {
736
+ Services : map [ipvstest.ServiceKey ]* utilipvs.VirtualServer {
737
+ {
738
+ IP : "10.20.30.41" ,
739
+ Port : 80 ,
740
+ Protocol : "SCTP" ,
741
+ }: {
742
+ Address : net .ParseIP ("10.20.30.41" ),
743
+ Protocol : "SCTP" ,
744
+ Port : uint16 (80 ),
745
+ Scheduler : "rr" ,
746
+ },
747
+ {
748
+ IP : "100.101.102.103" ,
749
+ Port : 3001 ,
750
+ Protocol : "SCTP" ,
751
+ }: {
752
+ Address : net .ParseIP ("100.101.102.103" ),
753
+ Protocol : "SCTP" ,
754
+ Port : uint16 (3001 ),
755
+ Scheduler : "rr" ,
756
+ },
757
+ {
758
+ IP : "100.101.102.104" ,
759
+ Port : 3001 ,
760
+ Protocol : "SCTP" ,
761
+ }: {
762
+ Address : net .ParseIP ("100.101.102.104" ),
763
+ Protocol : "SCTP" ,
764
+ Port : uint16 (3001 ),
765
+ Scheduler : "rr" ,
766
+ },
767
+ {
768
+ IP : "100.101.102.105" ,
769
+ Port : 3001 ,
770
+ Protocol : "SCTP" ,
771
+ }: {
772
+ Address : net .ParseIP ("100.101.102.105" ),
773
+ Protocol : "SCTP" ,
774
+ Port : uint16 (3001 ),
775
+ Scheduler : "rr" ,
776
+ },
777
+ {
778
+ IP : "2001:db8::1:1" ,
779
+ Port : 3001 ,
780
+ Protocol : "SCTP" ,
781
+ }: {
782
+ Address : net .ParseIP ("2001:db8::1:1" ),
783
+ Protocol : "SCTP" ,
784
+ Port : uint16 (3001 ),
785
+ Scheduler : "rr" ,
786
+ },
787
+ {
788
+ IP : "2001:db8::1:2" ,
789
+ Port : 3001 ,
790
+ Protocol : "SCTP" ,
791
+ }: {
792
+ Address : net .ParseIP ("2001:db8::1:2" ),
793
+ Protocol : "SCTP" ,
794
+ Port : uint16 (3001 ),
795
+ Scheduler : "rr" ,
796
+ },
797
+ {
798
+ IP : "2001:db8::1:3" ,
799
+ Port : 3001 ,
800
+ Protocol : "SCTP" ,
801
+ }: {
802
+ Address : net .ParseIP ("2001:db8::1:3" ),
803
+ Protocol : "SCTP" ,
804
+ Port : uint16 (3001 ),
805
+ Scheduler : "rr" ,
806
+ },
807
+ },
808
+ Destinations : map [ipvstest.ServiceKey ][]* utilipvs.RealServer {
809
+ {
810
+ IP : "10.20.30.41" ,
811
+ Port : 80 ,
812
+ Protocol : "SCTP" ,
813
+ }: {
814
+ {
815
+ Address : net .ParseIP ("10.180.0.1" ),
816
+ Port : uint16 (80 ),
817
+ Weight : 1 ,
818
+ },
819
+ },
820
+ {
821
+ IP : "100.101.102.103" ,
822
+ Port : 3001 ,
823
+ Protocol : "SCTP" ,
824
+ }: {
825
+ {
826
+ Address : net .ParseIP ("10.180.0.1" ),
827
+ Port : uint16 (80 ),
828
+ Weight : 1 ,
829
+ },
830
+ },
831
+ {
832
+ IP : "100.101.102.104" ,
833
+ Port : 3001 ,
834
+ Protocol : "SCTP" ,
835
+ }: {
836
+ {
837
+ Address : net .ParseIP ("10.180.0.1" ),
838
+ Port : uint16 (80 ),
839
+ Weight : 1 ,
840
+ },
841
+ },
842
+ {
843
+ IP : "100.101.102.105" ,
844
+ Port : 3001 ,
845
+ Protocol : "SCTP" ,
846
+ }: {
847
+ {
848
+ Address : net .ParseIP ("10.180.0.1" ),
849
+ Port : uint16 (80 ),
850
+ Weight : 1 ,
851
+ },
852
+ },
853
+ {
854
+ IP : "2001:db8::1:1" ,
855
+ Port : 3001 ,
856
+ Protocol : "SCTP" ,
857
+ }: {
858
+ {
859
+ Address : net .ParseIP ("10.180.0.1" ),
860
+ Port : uint16 (80 ),
861
+ Weight : 1 ,
862
+ },
863
+ },
864
+ {
865
+ IP : "2001:db8::1:2" ,
866
+ Port : 3001 ,
867
+ Protocol : "SCTP" ,
868
+ }: {
869
+ {
870
+ Address : net .ParseIP ("10.180.0.1" ),
871
+ Port : uint16 (80 ),
872
+ Weight : 1 ,
873
+ },
874
+ },
875
+ {
876
+ IP : "2001:db8::1:3" ,
877
+ Port : 3001 ,
878
+ Protocol : "SCTP" ,
879
+ }: {
880
+ {
881
+ Address : net .ParseIP ("10.180.0.1" ),
882
+ Port : uint16 (80 ),
883
+ Weight : 1 ,
884
+ },
885
+ },
886
+ },
887
+ },
888
+ expectedIPSets : netlinktest.ExpectedIPSet {
889
+ kubeNodePortSetSCTP : {
890
+ {
891
+ IP : "100.101.102.103" ,
892
+ Port : 3001 ,
893
+ Protocol : strings .ToLower (string (v1 .ProtocolSCTP )),
894
+ SetType : utilipset .HashIPPort ,
895
+ },
896
+ {
897
+ IP : "100.101.102.104" ,
898
+ Port : 3001 ,
899
+ Protocol : strings .ToLower (string (v1 .ProtocolSCTP )),
900
+ SetType : utilipset .HashIPPort ,
901
+ },
902
+ {
903
+ IP : "100.101.102.105" ,
904
+ Port : 3001 ,
905
+ Protocol : strings .ToLower (string (v1 .ProtocolSCTP )),
906
+ SetType : utilipset .HashIPPort ,
907
+ },
908
+ {
909
+ IP : "2001:db8::1:1" ,
910
+ Port : 3001 ,
911
+ Protocol : strings .ToLower (string (v1 .ProtocolSCTP )),
912
+ SetType : utilipset .HashIPPort ,
913
+ },
914
+ {
915
+ IP : "2001:db8::1:2" ,
916
+ Port : 3001 ,
917
+ Protocol : strings .ToLower (string (v1 .ProtocolSCTP )),
918
+ SetType : utilipset .HashIPPort ,
919
+ },
920
+ {
921
+ IP : "2001:db8::1:3" ,
922
+ Port : 3001 ,
923
+ Protocol : strings .ToLower (string (v1 .ProtocolSCTP )),
924
+ SetType : utilipset .HashIPPort ,
925
+ },
926
+ },
927
+ },
928
+ },
698
929
}
699
930
700
931
for _ , test := range tests {
@@ -2897,10 +3128,14 @@ func checkIPSet(t *testing.T, fp *Proxier, ipSet netlinktest.ExpectedIPSet) {
2897
3128
t .Errorf ("Check ipset entries failed for ipset: %q, expect %d, got %d" , set , len (entries ), len (ents ))
2898
3129
continue
2899
3130
}
2900
- if len (entries ) == 1 {
2901
- if ents [0 ] != entries [0 ].String () {
2902
- t .Errorf ("Check ipset entries failed for ipset: %q" , set )
2903
- }
3131
+ expectedEntries := []string {}
3132
+ for _ , entry := range entries {
3133
+ expectedEntries = append (expectedEntries , entry .String ())
3134
+ }
3135
+ sort .Strings (ents )
3136
+ sort .Strings (expectedEntries )
3137
+ if ! reflect .DeepEqual (ents , expectedEntries ) {
3138
+ t .Errorf ("Check ipset entries failed for ipset: %q" , set )
2904
3139
}
2905
3140
}
2906
3141
}
0 commit comments