mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Merge pull request #134176 from adrianmoisey/remove-deprecated-WaitForServiceEndpointsNum
Remove deprecated WaitForServiceEndpointsNum
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user