From 01f7de46f6c319c56c19c42e36a24c4791fd5175 Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Sun, 21 Sep 2025 14:47:03 +0200 Subject: [PATCH 1/2] Replace deprecated WaitForServiceEndpointsNum call with WaitForEndpointCount --- test/e2e/framework/autoscaling/autoscaling_utils.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/e2e/framework/autoscaling/autoscaling_utils.go b/test/e2e/framework/autoscaling/autoscaling_utils.go index 799cd56e965..23365fa4ae8 100644 --- a/test/e2e/framework/autoscaling/autoscaling_utils.go +++ b/test/e2e/framework/autoscaling/autoscaling_utils.go @@ -40,6 +40,7 @@ import ( scaleclient "k8s.io/client-go/scale" "k8s.io/kubernetes/test/e2e/framework" e2edebug "k8s.io/kubernetes/test/e2e/framework/debug" + e2eendpointslice "k8s.io/kubernetes/test/e2e/framework/endpointslice" e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl" e2erc "k8s.io/kubernetes/test/e2e/framework/rc" e2eresource "k8s.io/kubernetes/test/e2e/framework/resource" @@ -62,8 +63,6 @@ const ( targetPort = 8080 sidecarTargetPort = 8081 timeoutRC = 120 * time.Second - startServiceTimeout = time.Minute - startServiceInterval = 5 * time.Second invalidKind = "ERROR: invalid workload kind for resource consumer" customMetricName = "QPS" serviceInitializationTimeout = 2 * time.Minute @@ -613,8 +612,8 @@ func runServiceAndSidecarForResourceConsumer(ctx context.Context, c clientset.In framework.ExpectNoError(e2erc.RunRC(ctx, controllerRcConfig)) // Wait for endpoints to propagate for the controller service. - framework.ExpectNoError(framework.WaitForServiceEndpointsNum( - ctx, c, ns, controllerName, 1, startServiceInterval, startServiceTimeout)) + framework.ExpectNoError(e2eendpointslice.WaitForEndpointCount( + ctx, c, ns, controllerName, 1)) } func runServiceAndWorkloadForResourceConsumer(ctx context.Context, c clientset.Interface, resourceClient dynamic.ResourceInterface, apiExtensionClient crdclientset.Interface, ns, name string, kind schema.GroupVersionKind, replicas int, cpuLimitMillis, memLimitMb int64, podAnnotations, serviceAnnotations map[string]string, additionalContainers []v1.Container, podResources *v1.ResourceRequirements) { @@ -699,8 +698,8 @@ func runServiceAndWorkloadForResourceConsumer(ctx context.Context, c clientset.I framework.ExpectNoError(e2erc.RunRC(ctx, controllerRcConfig)) // Wait for endpoints to propagate for the controller service. - framework.ExpectNoError(framework.WaitForServiceEndpointsNum( - ctx, c, ns, controllerName, 1, startServiceInterval, startServiceTimeout)) + framework.ExpectNoError(e2eendpointslice.WaitForEndpointCount( + ctx, c, ns, controllerName, 1)) } func CreateHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, targetRef autoscalingv2.CrossVersionObjectReference, namespace string, metrics []autoscalingv2.MetricSpec, resourceType v1.ResourceName, metricTargetType autoscalingv2.MetricTargetType, metricTargetValue, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler { From ea914d8077fda3ac1560a6ca6223e09d773328e5 Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Sun, 21 Sep 2025 14:47:27 +0200 Subject: [PATCH 2/2] Remove unused WaitForServiceEndpointsNum function along with the now-unused countEndpointsSlicesNum function --- test/e2e/framework/util.go | 41 -------------------------------------- 1 file changed, 41 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index b47c9ae5a9d..0c7dffa7190 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -36,7 +36,6 @@ import ( "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" - discoveryv1 "k8s.io/api/discovery/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -410,46 +409,6 @@ func CheckTestingNSDeletedExcept(ctx context.Context, c clientset.Interface, ski return fmt.Errorf("Waiting for terminating namespaces to be deleted timed out") } -// WaitForServiceEndpointsNum waits until there are EndpointSlices for serviceName -// containing a total of expectNum endpoints. (If the service is dual-stack, expectNum -// must count the endpoints of both IP families.) -// -// Deprecated: use e2eendpointslice.WaitForEndpointCount or other related functions. -func WaitForServiceEndpointsNum(ctx context.Context, c clientset.Interface, namespace, serviceName string, expectNum int, interval, timeout time.Duration) error { - return wait.PollUntilContextTimeout(ctx, interval, timeout, false, func(ctx context.Context) (bool, error) { - Logf("Waiting for amount of service:%s endpoints to be %d", serviceName, expectNum) - esList, err := c.DiscoveryV1().EndpointSlices(namespace).List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", discoveryv1.LabelServiceName, serviceName)}) - if err != nil { - Logf("Unexpected error trying to get EndpointSlices for %s : %v", serviceName, err) - return false, nil - } - - if len(esList.Items) == 0 { - Logf("Waiting for at least 1 EndpointSlice to exist") - return false, nil - } - - if countEndpointsSlicesNum(esList) != expectNum { - Logf("Unexpected number of Endpoints on Slices, got %d, expected %d", countEndpointsSlicesNum(esList), expectNum) - return false, nil - } - return true, nil - }) -} - -func countEndpointsSlicesNum(epList *discoveryv1.EndpointSliceList) int { - // EndpointSlices can contain the same address on multiple Slices - addresses := sets.Set[string]{} - for _, epSlice := range epList.Items { - for _, ep := range epSlice.Endpoints { - if len(ep.Addresses) > 0 { - addresses.Insert(ep.Addresses[0]) - } - } - } - return addresses.Len() -} - // restclientConfig returns a config holds the information needed to build connection to kubernetes clusters. func restclientConfig(kubeContext string) (*clientcmdapi.Config, error) { Logf(">>> kubeConfig: %s", TestContext.KubeConfig)