This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
list_targets.go
48 lines (40 loc) · 1.51 KB
/
list_targets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package impl
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/flyteorg/flyteadmin/pkg/executioncluster"
"github.com/flyteorg/flyteadmin/pkg/executioncluster/interfaces"
runtime "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
)
type listTargets struct {
allTargets map[string]*executioncluster.ExecutionTarget
validTargets map[string]*executioncluster.ExecutionTarget
}
func (l *listTargets) GetAllTargets() map[string]*executioncluster.ExecutionTarget {
return l.allTargets
}
func (l *listTargets) GetValidTargets() map[string]*executioncluster.ExecutionTarget {
return l.validTargets
}
func NewListTargets(initializationErrorCounter prometheus.Counter, executionTargetProvider interfaces.ExecutionTargetProvider,
clusterConfig runtime.ClusterConfiguration) (interfaces.ListTargetsInterface, error) {
allTargets := make(map[string]*executioncluster.ExecutionTarget)
validTargets := make(map[string]*executioncluster.ExecutionTarget)
for _, cluster := range clusterConfig.GetClusterConfigs() {
if _, ok := allTargets[cluster.Name]; ok {
return nil, fmt.Errorf("duplicate clusters for name %s", cluster.Name)
}
executionTarget, err := executionTargetProvider.GetExecutionTarget(initializationErrorCounter, cluster)
if err != nil {
return nil, err
}
allTargets[cluster.Name] = executionTarget
if executionTarget.Enabled {
validTargets[cluster.Name] = executionTarget
}
}
return &listTargets{
allTargets: allTargets,
validTargets: validTargets,
}, nil
}