omni/internal/backend/runtime/helpers/helpers.go
Artem Chernyshev ed946b30a6
feat: display OMNI_ENDPOINT in the service account creation UI
Fixes: https://github.com/siderolabs/omni/issues/858

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
2025-01-29 15:27:36 +03:00

39 lines
1.1 KiB
Go

// Copyright (c) 2025 Sidero Labs, Inc.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
// Package helpers defines common runtime helper functions.
package helpers
import (
"context"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/safe"
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/omni/client/pkg/omni/resources/omni"
)
// GetMachineEndpoints reads all possible machine endpoints from the ClusterMachineIdentity resources.
func GetMachineEndpoints(ctx context.Context, st state.State, clusterName string) ([]string, error) {
endpoints, err := safe.ReaderListAll[*omni.ClusterMachineIdentity](ctx, st,
state.WithLabelQuery(
resource.LabelEqual(omni.LabelCluster, clusterName),
resource.LabelExists(omni.LabelControlPlaneRole),
),
)
if err != nil {
return nil, err
}
res := make([]string, 0, endpoints.Len())
endpoints.ForEach(func(r *omni.ClusterMachineIdentity) {
res = append(res, r.TypedSpec().Value.NodeIps...)
})
return res, nil
}