Skip to content

Commit 7fc1e07

Browse files
committed
tests: update e2e test for endpointslice compatibility
Assisted-By: Cursor AI Signed-off-by: Jayapriya Pai <janantha@redhat.com>
1 parent 54aa451 commit 7fc1e07

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

test/e2e/delete_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ func (tc *testContext) testWindowsNodeDeletion(t *testing.T) {
273273
_, err = tc.waitForWindowsMachines(int(expectedNodeCount), "", true)
274274
require.NoError(t, err, "ConfigMap controller Windows machine deletion failed")
275275

276-
// Test if prometheus configuration is updated to have no node entries in the endpoints object
276+
// Test if prometheus configuration is updated to have no node entries in the endpointslice objects.
277277
t.Run("Prometheus configuration", tc.testPrometheus)
278+
t.Run("Prometheus endpoint slice cleanup", tc.testPrometheusEndpointSliceCleanup)
278279

279280
// Cleanup windows-instances ConfigMap
280281
tc.deleteWindowsInstanceConfigMap()

test/e2e/metrics_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,41 @@ func (tc *testContext) testPrometheus(t *testing.T) {
8282

8383
}
8484

85+
// testPrometheusEndpointSliceCleanup verifies that no Windows nodes remain in kubelet EndpointSlices
86+
func (tc *testContext) testPrometheusEndpointSliceCleanup(t *testing.T) {
87+
// List all EndpointSlices for the kubelet service in kube-system namespace
88+
endpointSlices, err := tc.client.K8s.DiscoveryV1().EndpointSlices("kube-system").List(
89+
context.TODO(),
90+
metav1.ListOptions{
91+
LabelSelector: "kubernetes.io/service-name=kubelet",
92+
},
93+
)
94+
require.NoError(t, err, "error listing EndpointSlices for kubelet service")
95+
96+
// Verify that no Windows node addresses appear in any EndpointSlice
97+
var foundWindowsNodes []string
98+
for _, slice := range endpointSlices.Items {
99+
for _, endpoint := range slice.Endpoints {
100+
// Check if this endpoint references a node
101+
if endpoint.TargetRef == nil || endpoint.TargetRef.Kind != "Node" {
102+
continue
103+
}
104+
// Try to get the node to check its OS
105+
node, err := tc.client.K8s.CoreV1().Nodes().Get(context.Background(),
106+
endpoint.TargetRef.Name, metav1.GetOptions{})
107+
require.NoError(t, err, "node %s referenced in EndpointSlice not found - EndpointSlice not synced properly",
108+
endpoint.TargetRef.Name)
109+
// Check if this is a Windows node
110+
if nodeOS, exists := node.Labels["kubernetes.io/os"]; exists && nodeOS == "windows" {
111+
foundWindowsNodes = append(foundWindowsNodes, node.Name)
112+
}
113+
}
114+
}
115+
116+
require.Empty(t, foundWindowsNodes,
117+
"Found Windows nodes in kubelet EndpointSlices after deletion: %v", foundWindowsNodes)
118+
}
119+
85120
// PrometheusQuery defines the result of the /query request
86121
// Example Reference of Prometheus Query Response: https://prometheus.io/docs/prometheus/latest/querying/api/
87122
type PrometheusQuery struct {
@@ -239,9 +274,12 @@ func (tc *testContext) testPodMetrics(t *testing.T, podName string) {
239274
fmt.Sprintf("pod_interface_network:container_network_receive_bytes:irate5m{pod='%s',namespace='%s'}", podName, tc.workloadNamespace),
240275
fmt.Sprintf("pod_interface_network:container_network_transmit_bytes_total:irate5m{pod='%s',namespace='%s'}", podName, tc.workloadNamespace),
241276
}
277+
// Use extended timeout to account for EndpointSlice propagation, metric scraping,
278+
// and recording rule evaluation when using EndpointSlice-based service discovery
279+
podMetricsTimeout := 5 * time.Minute
242280
for i, query := range queries {
243281
t.Run("query "+strconv.Itoa(i), func(t *testing.T) {
244-
err := wait.PollUntilContextTimeout(context.TODO(), retry.Interval, retry.ResourceChangeTimeout, true,
282+
err := wait.PollUntilContextTimeout(context.TODO(), retry.Interval, podMetricsTimeout, true,
245283
func(ctx context.Context) (done bool, err error) {
246284
results, err := makePrometheusQuery(prometheusRoute.Spec.Host, query, prometheusToken)
247285
if err != nil {

0 commit comments

Comments
 (0)