mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Updating e2e test to check EndpointSlices and Endpoints as well
This commit is contained in:
		@@ -413,7 +413,7 @@ func (e *Controller) syncService(ctx context.Context, key string) error {
 | 
			
		||||
	var totalNotReadyEps int
 | 
			
		||||
 | 
			
		||||
	for _, pod := range pods {
 | 
			
		||||
		if !endpointutil.ShouldPodBeInEndpointSlice(pod, service.Spec.PublishNotReadyAddresses) {
 | 
			
		||||
		if !endpointutil.ShouldPodBeInEndpoints(pod, service.Spec.PublishNotReadyAddresses) {
 | 
			
		||||
			klog.V(5).Infof("Pod %s/%s is not included on endpoints for Service %s/%s", pod.Namespace, pod.Name, service.Namespace, service.Name)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
@@ -587,7 +587,7 @@ func (e *Controller) checkLeftoverEndpoints() {
 | 
			
		||||
// addEndpointSubset add the endpoints addresses and ports to the EndpointSubset.
 | 
			
		||||
// The addresses are added to the corresponding field, ready or not ready, depending
 | 
			
		||||
// on the pod status and the Service PublishNotReadyAddresses field value.
 | 
			
		||||
// The pod passed to this function must have already been filtered through ShouldPodBeInEndpointSlice.
 | 
			
		||||
// The pod passed to this function must have already been filtered through ShouldPodBeInEndpoints.
 | 
			
		||||
func addEndpointSubset(subsets []v1.EndpointSubset, pod *v1.Pod, epa v1.EndpointAddress,
 | 
			
		||||
	epp *v1.EndpointPort, tolerateUnreadyEndpoints bool) ([]v1.EndpointSubset, int, int) {
 | 
			
		||||
	var readyEps int
 | 
			
		||||
 
 | 
			
		||||
@@ -154,7 +154,7 @@ func (r *reconciler) reconcileByAddressType(service *corev1.Service, pods []*cor
 | 
			
		||||
 | 
			
		||||
	for _, pod := range pods {
 | 
			
		||||
		includeTerminating := service.Spec.PublishNotReadyAddresses || utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceTerminatingCondition)
 | 
			
		||||
		if !endpointutil.ShouldPodBeInEndpointSlice(pod, includeTerminating) {
 | 
			
		||||
		if !endpointutil.ShouldPodBeInEndpoints(pod, includeTerminating) {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -135,15 +135,17 @@ func DeepHashObjectToString(objectToWrite interface{}) string {
 | 
			
		||||
	return hex.EncodeToString(hasher.Sum(nil)[0:])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ShouldPodBeInEndpointSlice returns true if a specified pod should be in an Endpoint or EndpointSlice object.
 | 
			
		||||
// Terminating pods are only included if includeTerminating is true
 | 
			
		||||
func ShouldPodBeInEndpointSlice(pod *v1.Pod, includeTerminating bool) bool {
 | 
			
		||||
// ShouldPodBeInEndpoints returns true if a specified pod should be in an
 | 
			
		||||
// Endpoints or EndpointSlice resource. Terminating pods are only included if
 | 
			
		||||
// includeTerminating is true.
 | 
			
		||||
func ShouldPodBeInEndpoints(pod *v1.Pod, includeTerminating bool) bool {
 | 
			
		||||
	// "Terminal" describes when a Pod is complete (in a succeeded or failed phase).
 | 
			
		||||
	// This is distinct from the "Terminating" condition which represents when a Pod
 | 
			
		||||
	// is being terminated (metadata.deletionTimestamp is non nil).
 | 
			
		||||
	if podutil.IsPodTerminal(pod) {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(pod.Status.PodIP) == 0 && len(pod.Status.PodIPs) == 0 {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -99,7 +99,7 @@ func TestDetermineNeededServiceUpdates(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestShouldPodBeInEndpointSlice(t *testing.T) {
 | 
			
		||||
func TestShouldPodBeInEndpoints(t *testing.T) {
 | 
			
		||||
	testCases := []struct {
 | 
			
		||||
		name               string
 | 
			
		||||
		pod                *v1.Pod
 | 
			
		||||
@@ -263,7 +263,7 @@ func TestShouldPodBeInEndpointSlice(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	for _, test := range testCases {
 | 
			
		||||
		t.Run(test.name, func(t *testing.T) {
 | 
			
		||||
			result := ShouldPodBeInEndpointSlice(test.pod, test.includeTerminating)
 | 
			
		||||
			result := ShouldPodBeInEndpoints(test.pod, test.includeTerminating)
 | 
			
		||||
			if result != test.expected {
 | 
			
		||||
				t.Errorf("expected: %t, got: %t", test.expected, result)
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -2080,6 +2080,35 @@ var _ = common.SIGDescribe("Services", func() {
 | 
			
		||||
			e2epod.SetNodeSelection(&pod.Spec, nodeSelection)
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		if epErr := wait.PollImmediate(framework.Poll, e2eservice.ServiceEndpointsTimeout, func() (bool, error) {
 | 
			
		||||
			endpoints, err := cs.CoreV1().Endpoints(namespace).Get(context.TODO(), serviceName, metav1.GetOptions{})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				framework.Logf("error fetching '%s/%s' Endpoints: %s", namespace, serviceName, err.Error())
 | 
			
		||||
				return false, err
 | 
			
		||||
			}
 | 
			
		||||
			if len(endpoints.Subsets) > 0 {
 | 
			
		||||
				framework.Logf("expected '%s/%s' Endpoints to be empty, got: %v", namespace, serviceName, endpoints.Subsets)
 | 
			
		||||
				return false, nil
 | 
			
		||||
			}
 | 
			
		||||
			epsList, err := cs.DiscoveryV1().EndpointSlices(namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", discoveryv1.LabelServiceName, serviceName)})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				framework.Logf("error fetching '%s/%s' EndpointSlices: %s", namespace, serviceName, err.Error())
 | 
			
		||||
				return false, err
 | 
			
		||||
			}
 | 
			
		||||
			if len(epsList.Items) != 1 {
 | 
			
		||||
				framework.Logf("expected exactly 1 EndpointSlice, got: %d", len(epsList.Items))
 | 
			
		||||
				return false, nil
 | 
			
		||||
			}
 | 
			
		||||
			endpointSlice := epsList.Items[0]
 | 
			
		||||
			if len(endpointSlice.Endpoints) > 0 {
 | 
			
		||||
				framework.Logf("expected EndpointSlice to be empty, got %d endpoints", len(endpointSlice.Endpoints))
 | 
			
		||||
				return false, nil
 | 
			
		||||
			}
 | 
			
		||||
			return true, nil
 | 
			
		||||
		}); epErr != nil {
 | 
			
		||||
			framework.ExpectNoError(epErr)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		serviceAddress := net.JoinHostPort(serviceName, strconv.Itoa(port))
 | 
			
		||||
		framework.Logf("waiting up to %v to connect to %v", e2eservice.KubeProxyEndpointLagTimeout, serviceAddress)
 | 
			
		||||
		cmd := fmt.Sprintf("/agnhost connect --timeout=3s %s", serviceAddress)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user