@@ -842,35 +842,51 @@ func (lbc *LoadBalancerController) syncEndpointSlices(task task) bool {
842
842
}
843
843
844
844
endpointSlice := obj .(* discovery_v1.EndpointSlice )
845
- svcResource := lbc .configuration .FindResourcesForService (endpointSlice .Namespace , endpointSlice .Labels ["kubernetes.io/service-name" ])
845
+ svcName := endpointSlice .Labels ["kubernetes.io/service-name" ]
846
+ svcResource := lbc .configuration .FindResourcesForService (endpointSlice .Namespace , svcName )
846
847
847
848
resourceExes := lbc .createExtendedResources (svcResource )
848
849
849
850
if len (resourceExes .IngressExes ) > 0 {
<
BB54
/code>
850
- resourcesFound = true
851
- glog .V (3 ).Infof ("Updating EndpointSlices for %v" , resourceExes .IngressExes )
852
- err = lbc .configurator .UpdateEndpoints (resourceExes .IngressExes )
853
- if err != nil {
854
- glog .Errorf ("Error updating EndpointSlices for %v: %v" , resourceExes .IngressExes , err )
851
+ for _ , ingEx := range resourceExes .IngressExes {
852
+ if lbc .ingressRequiresEndpointsUpdate (ingEx , svcName ) {
853
+ resourcesFound = true
854
+ glog .V (3 ).Infof ("Updating EndpointSlices for %v" , resourceExes .IngressExes )
855
+ err = lbc .configurator .UpdateEndpoints (resourceExes .IngressExes )
856
+ if err != nil {
857
+ glog .Errorf ("Error updating EndpointSlices for %v: %v" , resourceExes .IngressExes , err )
858
+ }
859
+ break
860
+ }
855
861
}
856
862
}
857
863
858
864
if len (resourceExes .MergeableIngresses ) > 0 {
859
- resourcesFound = true
860
- glog .V (3 ).Infof ("Updating EndpointSlices for %v" , resourceExes .MergeableIngresses )
861
- err = lbc .configurator .UpdateEndpointsMergeableIngress (resourceExes .MergeableIngresses )
862
- if err != nil {
863
- glog .Errorf ("Error updating EndpointSlices for %v: %v" , resourceExes .MergeableIngresses , err )
865
+ for _ , mergeableIngresses := range resourceExes .MergeableIngresses {
866
+ if lbc .mergeableIngressRequiresEndpointsUpdate (mergeableIngresses , svcName ) {
867
+ resourcesFound = true
868
+ glog .V (3 ).Infof ("Updating EndpointSlices for %v" , resourceExes .MergeableIngresses )
869
+ err = lbc .configurator .UpdateEndpointsMergeableIngress (resourceExes .MergeableIngresses )
870
+ if err != nil {
871
+ glog .Errorf ("Error updating EndpointSlices for %v: %v" , resourceExes .MergeableIngresses , err )
872
+ }
873
+ break
874
+ }
864
875
}
865
876
}
866
877
867
878
if lbc .areCustomResourcesEnabled {
868
879
if len (resourceExes .VirtualServerExes ) > 0 {
869
- resourcesFound = true
870
- glog .V (3 ).Infof ("Updating EndpointSlices for %v" , resourceExes .VirtualServerExes )
871
- err := lbc .configurator .UpdateEndpointsForVirtualServers (resourceExes .VirtualServerExes )
872
- if err != nil {
873
- glog .Errorf ("Error updating EndpointSlices for %v: %v" , resourceExes .VirtualServerExes , err )
880
+ for _ , vsEx := range resourceExes .VirtualServerExes {
881
+ if lbc .virtualServerRequiresEndpointsUpdate (vsEx , svcName ) {
882
+ resourcesFound = true
883
+ glog .V (3 ).Infof ("Updating EndpointSlices for %v" , resourceExes .VirtualServerExes )
884
+ err := lbc .configurator .UpdateEndpointsForVirtualServers (resourceExes .VirtualServerExes )
885
+ if err != nil {
886
+ glog .Errorf ("Error updating EndpointSlices for %v: %v" , resourceExes .VirtualServerExes , err )
887
+ }
888
+ break
889
+ }
874
890
}
875
891
}
876
892
@@ -886,6 +902,63 @@ func (lbc *LoadBalancerController) syncEndpointSlices(task task) bool {
886
902
return resourcesFound
887
903
}
888
904
905
+ func (lbc * LoadBalancerController ) virtualServerRequiresEndpointsUpdate (vsEx * configs.VirtualServerEx , serviceName string ) bool {
906
+ for _ , upstream := range vsEx .VirtualServer .Spec .Upstreams {
907
+ if upstream .Service == serviceName && ! upstream .UseClusterIP {
908
+ return true
909
+ }
910
+ }
911
+
912
+ for _ , vsr := range vsEx .VirtualServerRoutes {
913
+ for _ , upstream := range vsr .Spec .Upstreams {
914
+ if upstream .Service == serviceName && ! upstream .UseClusterIP {
915
+ return true
916
+ }
917
+ }
918
+ }
919
+
920
+ return false
921
+ }
922
+
923
+ func (lbc * LoadBalancerController ) ingressRequiresEndpointsUpdate (ingressEx * configs.IngressEx , serviceName string ) bool {
924
+ hasUseClusterIPAnnotation := ingressEx .Ingress .Annotations [useClusterIPAnnotation ] == "true"
925
+
926
+ for _ , rule := range ingressEx .Ingress .Spec .Rules {
927
+ if http := rule .HTTP ; http != nil {
928
+ for _ , path := range http .Paths {
929
+ if path .Backend .Service != nil && path .Backend .Service .Name == serviceName {
930
+ if ! hasUseClusterIPAnnotation {
931
+ return true
932
+ }
933
+ }
934
+ }
935
+ }
936
+ }
937
+
938
+ if http := ingressEx .Ingress .Spec .DefaultBackend ; http != nil {
939
+ if http .Service != nil && http .Service .Name == serviceName {
940
+ if ! hasUseClusterIPAnnotation {
941
+ return true
942
+ }
943
+ }
944
+ }
945
+
946
+ return false
947
+ }
948
+
949
+ func (lbc * LoadBalancerController ) mergeableIngressRequiresEndpointsUpdate (mergeableIngresses * configs.MergeableIngresses , serviceName string ) bool {
950
+ masterIngress := mergeableIngresses .Master
951
+ minions := mergeableIngresses .Minions
952
+
953
+ for _ , minion := range minions {
954
+ if lbc .ingressRequiresEndpointsUpdate (minion , serviceName ) {
955
+ return true
956
+ }
957
+ }
958
+
959
+ return lbc .ingressRequiresEndpointsUpdate (masterIngress , serviceName )
960
+ }
961
+
889
962
func (lbc * LoadBalancerController ) createExtendedResources (resources []Resource ) configs.ExtendedResources {
890
963
var result configs.ExtendedResources
891
964
@@ -2793,6 +2866,7 @@ func (lbc *LoadBalancerController) createMergeableIngresses(ingConfig *IngressCo
2793
2866
}
2794
2867
2795
2868
func (lbc * LoadBalancerController ) createIngressEx (ing * networking.Ingress , validHosts map [string ]bool , validMinionPaths map [string ]bool ) * configs.IngressEx {
2869
+ var endps []string
2796
2870
ingEx := & configs.IngressEx {
2797
2871
Ingress : ing ,
2798
2872
ValidHosts : validHosts ,
@@ -2874,6 +2948,7 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
2874
2948
ingEx .HealthChecks = make (map [string ]* api_v1.Probe )
2875
2949
ingEx .ExternalNameSvcs = make (map [string ]bool )
2876
2950
ingEx .PodsByIP = make (map [string ]configs.PodInfo )
2951
+ hasUseClusterIP := ingEx .Ingress .Annotations [configs .UseClusterIPAnnotation ] == "true"
2877
2952
2878
2953
if ing .Spec .DefaultBackend != nil {
2879
2954
podEndps := []podEndpoint {}
@@ -2892,7 +2967,11 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
2892
2967
glog .Warningf ("Error retrieving endpoints for the service %v: %v" , ing .Spec .DefaultBackend .Service .Name , err )
2893
2968
}
2894
2969
2895
- endps := getIPAddressesFromEndpoints (podEndps )
2970
+ if svc != nil && ! external && hasUseClusterIP {
2971
+ endps = []string {ipv6SafeAddrPort (svc .Spec .ClusterIP , ing .Spec .DefaultBackend .Service .Port .Number )}
2972
+ } else {
2973
+ endps = getIPAddressesFromEndpoints (podEndps )
2974
+ }
2896
2975
2897
2976
// endps is empty if there was any error before this point
2898
2977
ingEx .Endpoints [ing .Spec .DefaultBackend .Service .Name + configs .GetBackendPortAsString (ing .Spec .DefaultBackend .Service .Port )] = endps
@@ -2948,7 +3027,11 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
2948
3027
glog .Warningf ("Error retrieving endpoints for the service %v: %v" , path .Backend .Service .Name , err )
2949
3028
}
2950
3029
2951
- endps := getIPAddressesFromEndpoints (podEndps )
3030
+ if svc != nil && ! external && hasUseClusterIP {
3031
+ endps = []string {ipv6SafeAddrPort (svc .Spec .ClusterIP , path .Backend .Service .Port .Number )}
3032
+ } else {
3033
+ endps = getIPAddressesFromEndpoints (podEndps )
3034
+ }
2952
3035
2953
3036
// endps is empty if there was any error before this point
2954
3037
ingEx .Endpoints [path .Backend .Service .Name + configs .GetBackendPortAsString (path .Backend .Service .Port )] = endps
0 commit comments