@@ -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/
87122type 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