@@ -13,6 +13,7 @@ import (
1313 appsv1 "k8s.io/api/apps/v1"
1414 batchv1 "k8s.io/api/batch/v1"
1515 corev1 "k8s.io/api/core/v1"
16+ discoveryv1 "k8s.io/api/discovery/v1"
1617 apierrors "k8s.io/apimachinery/pkg/api/errors"
1718 "k8s.io/apimachinery/pkg/api/resource"
1819 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -39,6 +40,7 @@ const (
3940 longhornStaticStorageClassName = "longhorn-static"
4041
4142 harvesterManagedLabel = "harvesterhci.io/managed"
43+ serviceNameLabel = "kubernetes.io/service-name"
4244 imageComponent = "iso"
4345 repoComponent = "repo"
4446
@@ -1151,20 +1153,29 @@ func isServiceReady(ctx context.Context, c client.Client, svc *corev1.Service) b
11511153 if svc .Spec .ClusterIP == "" {
11521154 return false
11531155 }
1154- return hasReadyEndpoints (ctx , c , svc )
1156+ return isAnyEndpointReady (ctx , c , svc )
11551157}
11561158
1157- // TODO: This should be updated with EndpointSlice since Endpoints is deprecated in Kubernetes v1.33+.
1158- func hasReadyEndpoints (ctx context.Context , c client.Client , svc * corev1.Service ) bool {
1159- var ep corev1.Endpoints
1160- if err := c .Get (ctx , types.NamespacedName {Namespace : svc .Namespace , Name : svc .Name }, & ep ); err != nil {
1159+ func isAnyEndpointReady (ctx context.Context , c client.Client , svc * corev1.Service ) bool {
1160+ var epsList discoveryv1.EndpointSliceList
1161+ if err := c .List (ctx , & epsList , & client.ListOptions {
1162+ LabelSelector : labels .SelectorFromSet (labels.Set {
1163+ serviceNameLabel : svc .Name ,
1164+ }),
1165+ }); err != nil {
1166+ return false
1167+ }
1168+
1169+ if len (epsList .Items ) == 0 {
11611170 return false
11621171 }
1163- for _ , subset := range ep .Subsets {
1164- if len (subset .Addresses ) > 0 {
1172+
1173+ for _ , ep := range epsList .Items [0 ].Endpoints {
1174+ if ep .Conditions .Ready != nil && * ep .Conditions .Ready {
11651175 return true
11661176 }
11671177 }
1178+
11681179 return false
11691180}
11701181
0 commit comments