mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* Updating client-go to v1.36.0-beta.0 (and updating golang to 1.26) Signed-off-by: Mark Rossetti <[email protected]> * Bump golangci-lint to v2.11.4 and fix lint issues for Go 1.26 Signed-off-by: Mark Rossetti <[email protected]> * bump go to 1.26 in ray-operator docker file Signed-off-by: Mark Rossetti <[email protected]> * Migrate webhooks from deprecated CustomValidator to admission.Validation[T] Signed-off-by: Mark Rossetti <[email protected]> * Target K8s 1.36 GA deps Signed-off-by: Mark Rossetti <[email protected]> * Merge branch 'master' into go-client-go-updates Signed-off-by: Rueian <[email protected]> --------- Signed-off-by: Mark Rossetti <[email protected]> Signed-off-by: Rueian <[email protected]> Co-authored-by: Rueian <[email protected]>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package support
|
|
|
|
import (
|
|
"context"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
discoveryv1 "k8s.io/api/discovery/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"k8s.io/utils/ptr"
|
|
)
|
|
|
|
//go:fix inline
|
|
func Ptr[T any](v T) *T {
|
|
return new(v)
|
|
}
|
|
|
|
type OutputType string
|
|
|
|
const (
|
|
Log OutputType = "log"
|
|
)
|
|
|
|
func WriteToOutputDir(t Test, fileName string, fileType OutputType, data []byte) {
|
|
t.T().Helper()
|
|
err := os.WriteFile(path.Join(t.OutputDir(), fileName+"."+string(fileType)), data, fs.ModePerm)
|
|
require.NoError(t.T(), err)
|
|
}
|
|
|
|
// EndpointInfo contains information about a ready endpoint from an EndpointSlice.
|
|
type EndpointInfo struct {
|
|
TargetRefName string
|
|
TargetRefUID types.UID
|
|
}
|
|
|
|
// GetReadyEndpointsFromSlices retrieves all ready endpoints from EndpointSlices
|
|
// associated with the given service name in the specified namespace.
|
|
// It returns a slice of EndpointInfo containing target reference names and UIDs of ready endpoints.
|
|
func GetReadyEndpointsFromSlices(ctx context.Context, client Client, namespace, serviceName string) ([]EndpointInfo, error) {
|
|
endpointSliceList, err := client.Core().DiscoveryV1().EndpointSlices(namespace).List(ctx, metav1.ListOptions{
|
|
LabelSelector: discoveryv1.LabelServiceName + "=" + serviceName,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var readyEndpoints []EndpointInfo
|
|
for _, slice := range endpointSliceList.Items {
|
|
for _, endpoint := range slice.Endpoints {
|
|
if ptr.Deref(endpoint.Conditions.Ready, false) {
|
|
if endpoint.TargetRef != nil && endpoint.TargetRef.UID != "" {
|
|
readyEndpoints = append(readyEndpoints, EndpointInfo{
|
|
TargetRefName: endpoint.TargetRef.Name,
|
|
TargetRefUID: endpoint.TargetRef.UID,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return readyEndpoints, nil
|
|
}
|