@@ -563,11 +563,7 @@ func TestAllocateService(t *testing.T) {
563
563
564
564
err = na .AllocateService (s )
565
565
assert .NoError (t , err )
566
- assert .Equal (t , 2 , len (s .Endpoint .Ports ))
567
- assert .True (t , s .Endpoint .Ports [0 ].PublishedPort >= dynamicPortStart &&
568
- s .Endpoint .Ports [0 ].PublishedPort <= dynamicPortEnd )
569
- assert .True (t , s .Endpoint .Ports [1 ].PublishedPort >= dynamicPortStart &&
570
- s .Endpoint .Ports [1 ].PublishedPort <= dynamicPortEnd )
566
+ assert .Len (t , s .Endpoint .Ports , 0 ) // Network allocator is not responsible for allocating ports.
571
567
572
568
assert .Equal (t , 1 , len (s .Endpoint .VirtualIPs ))
573
569
@@ -579,94 +575,6 @@ func TestAllocateService(t *testing.T) {
579
575
assert .Equal (t , true , subnet .Contains (ip ))
580
576
}
581
577
582
- func TestAllocateServiceUserDefinedPorts (t * testing.T ) {
583
- na := newNetworkAllocator (t )
584
- s := & api.Service {
585
- ID : "testID1" ,
586
- Spec : api.ServiceSpec {
587
- Endpoint : & api.EndpointSpec {
588
- Ports : []* api.PortConfig {
589
- {
590
- Name : "some_tcp" ,
591
- TargetPort : 1234 ,
592
- PublishedPort : 1234 ,
593
- },
594
- {
595
- Name : "some_udp" ,
596
- TargetPort : 1234 ,
597
- PublishedPort : 1234 ,
598
- Protocol : api .ProtocolUDP ,
599
- },
600
- },
601
- },
602
- },
603
- }
604
-
605
- err := na .AllocateService (s )
606
- assert .NoError (t , err )
607
- assert .Equal (t , 2 , len (s .Endpoint .Ports ))
608
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
609
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [1 ].PublishedPort )
610
- }
611
-
612
- func TestAllocateServiceConflictingUserDefinedPorts (t * testing.T ) {
613
- na := newNetworkAllocator (t )
614
- s := & api.Service {
615
- ID : "testID1" ,
616
- Spec : api.ServiceSpec {
617
- Endpoint : & api.EndpointSpec {
618
- Ports : []* api.PortConfig {
619
- {
620
- Name : "some_tcp" ,
621
- TargetPort : 1234 ,
622
- PublishedPort : 1234 ,
623
- },
624
- {
625
- Name : "some_other_tcp" ,
626
- TargetPort : 1234 ,
627
- PublishedPort : 1234 ,
628
- },
629
- },
630
- },
631
- },
632
- }
633
-
634
- err := na .AllocateService (s )
635
- assert .Error (t , err )
636
- }
637
-
638
- func TestDeallocateServiceAllocate (t * testing.T ) {
639
- na := newNetworkAllocator (t )
640
- s := & api.Service {
641
- ID : "testID1" ,
642
- Spec : api.ServiceSpec {
643
- Endpoint : & api.EndpointSpec {
644
- Ports : []* api.PortConfig {
645
- {
646
- Name : "some_tcp" ,
647
- TargetPort : 1234 ,
648
- PublishedPort : 1234 ,
649
- },
650
- },
651
- },
652
- },
653
- }
654
-
655
- err := na .AllocateService (s )
656
- assert .NoError (t , err )
657
- assert .Equal (t , 1 , len (s .Endpoint .Ports ))
658
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
659
-
660
- err = na .DeallocateService (s )
661
- assert .NoError (t , err )
662
- assert .Equal (t , 0 , len (s .Endpoint .Ports ))
663
- // Allocate again.
664
- err = na .AllocateService (s )
665
- assert .NoError (t , err )
666
- assert .Equal (t , 1 , len (s .Endpoint .Ports ))
667
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
668
- }
669
-
670
578
func TestDeallocateServiceAllocateIngressMode (t * testing.T ) {
671
579
na := newNetworkAllocator (t )
672
580
@@ -705,8 +613,6 @@ func TestDeallocateServiceAllocateIngressMode(t *testing.T) {
705
613
706
614
err = na .AllocateService (s )
707
615
assert .NoError (t , err )
708
- assert .Len (t , s .Endpoint .Ports , 1 )
709
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
710
616
assert .Len (t , s .Endpoint .VirtualIPs , 1 )
711
617
712
618
err = na .DeallocateService (s )
@@ -719,129 +625,7 @@ func TestDeallocateServiceAllocateIngressMode(t *testing.T) {
719
625
720
626
err = na .AllocateService (s )
721
627
assert .NoError (t , err )
722
- assert .Len (t , s .Endpoint .Ports , 1 )
723
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
724
- assert .Len (t , s .Endpoint .VirtualIPs , 1 )
725
- }
726
-
727
- func TestServiceAddRemovePortsIngressMode (t * testing.T ) {
728
- na := newNetworkAllocator (t )
729
-
730
- n := & api.Network {
731
- ID : "testNetID1" ,
732
- Spec : api.NetworkSpec {
733
- Annotations : api.Annotations {
734
- Name : "test" ,
735
- },
736
- Ingress : true ,
737
- },
738
- }
739
-
740
- err := na .Allocate (n )
741
- assert .NoError (t , err )
742
-
743
- s := & api.Service {
744
- ID : "testID1" ,
745
- Spec : api.ServiceSpec {
746
- Endpoint : & api.EndpointSpec {
747
- Ports : []* api.PortConfig {
748
- {
749
- Name : "some_tcp" ,
750
- TargetPort : 1234 ,
751
- PublishedPort : 1234 ,
752
- PublishMode : api .PublishModeIngress ,
753
- },
754
- },
755
- },
756
- },
757
- Endpoint : & api.Endpoint {},
758
- }
759
-
760
- s .Endpoint .VirtualIPs = append (s .Endpoint .VirtualIPs ,
761
- & api.Endpoint_VirtualIP {NetworkID : n .ID })
762
-
763
- err = na .AllocateService (s )
764
- assert .NoError (t , err )
765
- assert .Len (t , s .Endpoint .Ports , 1 )
766
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
767
628
assert .Len (t , s .Endpoint .VirtualIPs , 1 )
768
- allocatedVIP := s .Endpoint .VirtualIPs [0 ].Addr
769
-
770
- // Unpublish port
771
- s .Spec .Endpoint .Ports = s .Spec .Endpoint .Ports [:0 ]
772
- err = na .AllocateService (s )
773
- assert .NoError (t , err )
774
- assert .Len (t , s .Endpoint .Ports , 0 )
775
- assert .Len (t , s .Endpoint .VirtualIPs , 0 )
776
-
777
- // Publish port again and ensure VIP is not the same that was deallocated.
778
- // Since IP allocation is serial we should receive the next available IP.
779
- s .Spec .Endpoint .Ports = append (s .Spec .Endpoint .Ports , & api.PortConfig {Name : "some_tcp" ,
780
- TargetPort : 1234 ,
781
- PublishedPort : 1234 ,
782
- PublishMode : api .PublishModeIngress ,
783
- })
784
- s .Endpoint .VirtualIPs = append (s .Endpoint .VirtualIPs ,
785
- & api.Endpoint_VirtualIP {NetworkID : n .ID })
786
- err = na .AllocateService (s )
787
- assert .NoError (t , err )
788
- assert .Len (t , s .Endpoint .Ports , 1 )
789
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
790
- assert .Len (t , s .Endpoint .VirtualIPs , 1 )
791
- assert .NotEqual (t , allocatedVIP , s .Endpoint .VirtualIPs [0 ].Addr )
792
- }
793
-
794
- func TestServiceUpdate (t * testing.T ) {
795
- na1 := newNetworkAllocator (t )
796
- na2 := newNetworkAllocator (t )
797
- s := & api.Service {
798
- ID : "testID1" ,
799
- Spec : api.ServiceSpec {
800
- Endpoint : & api.EndpointSpec {
801
- Ports : []* api.PortConfig {
802
- {
803
- Name : "some_tcp" ,
804
- TargetPort : 1234 ,
805
- PublishedPort : 1234 ,
806
- },
807
- {
808
- Name : "some_other_tcp" ,
809
- TargetPort : 1235 ,
810
- PublishedPort : 0 ,
811
- },
812
- },
813
- },
814
- },
815
- }
816
-
817
- err := na1 .AllocateService (s )
818
- assert .NoError (t , err )
819
- assert .True (t , na1 .IsServiceAllocated (s ))
820
- assert .Equal (t , 2 , len (s .Endpoint .Ports ))
821
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
822
- assert .NotEqual (t , 0 , s .Endpoint .Ports [1 ].PublishedPort )
823
-
824
- // Cache the secode node port
825
- allocatedPort := s .Endpoint .Ports [1 ].PublishedPort
826
-
827
- // Now allocate the same service in another allocator instance
828
- err = na2 .AllocateService (s )
829
- assert .NoError (t , err )
830
- assert .True (t , na2 .IsServiceAllocated (s ))
831
- assert .Equal (t , 2 , len (s .Endpoint .Ports ))
832
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
833
- // Make sure we got the same port
834
- assert .Equal (t , allocatedPort , s .Endpoint .Ports [1 ].PublishedPort )
835
-
836
- s .Spec .Endpoint .Ports [1 ].PublishedPort = 1235
837
- assert .False (t , na1 .IsServiceAllocated (s ))
838
-
839
- err = na1 .AllocateService (s )
840
- assert .NoError (t , err )
841
- assert .True (t , na1 .IsServiceAllocated (s ))
842
- assert .Equal (t , 2 , len (s .Endpoint .Ports ))
843
- assert .Equal (t , uint32 (1234 ), s .Endpoint .Ports [0 ].PublishedPort )
844
- assert .Equal (t , uint32 (1235 ), s .Endpoint .Ports [1 ].PublishedPort )
845
629
}
846
630
847
631
func TestServiceNetworkUpdate (t * testing.T ) {
0 commit comments