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
/
cluster_execution_target_provider.go
56 lines (51 loc) · 1.82 KB
/
cluster_execution_target_provider.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
49
50
51
52
53
54
55
56
package impl
import (
"github.com/flyteorg/flyteadmin/pkg/executioncluster"
"github.com/flyteorg/flyteadmin/pkg/executioncluster/interfaces"
"github.com/flyteorg/flyteadmin/pkg/flytek8s"
runtime "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
flyteclient "github.com/flyteorg/flytepropeller/pkg/client/clientset/versioned"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type clusterExecutionTargetProvider struct{}
// Creates a new Execution target for a cluster based on config passed in.
func (c *clusterExecutionTargetProvider) GetExecutionTarget(initializationErrorCounter prometheus.Counter, k8sCluster runtime.ClusterConfig) (*executioncluster.ExecutionTarget, error) {
kubeConf, err := flytek8s.GetRestClientConfig("", "", &k8sCluster)
if err != nil {
return nil, err
}
flyteClient, err := getRestClientFromKubeConfig(initializationErrorCounter, kubeConf)
if err != nil {
return nil, err
}
client, err := client.New(kubeConf, client.Options{})
if err != nil {
return nil, err
}
dynamicClient, err := dynamic.NewForConfig(kubeConf)
if err != nil {
return nil, err
}
return &executioncluster.ExecutionTarget{
FlyteClient: flyteClient,
Client: client,
DynamicClient: dynamicClient,
ID: k8sCluster.Name,
Enabled: k8sCluster.Enabled,
Config: *kubeConf,
}, nil
}
func getRestClientFromKubeConfig(initializationErrorCounter prometheus.Counter, kubeConfiguration *rest.Config) (*flyteclient.Clientset, error) {
fc, err := flyteclient.NewForConfig(kubeConfiguration)
if err != nil {
initializationErrorCounter.Inc()
return nil, err
}
return fc, nil
}
func NewExecutionTargetProvider() interfaces.ExecutionTargetProvider {
return &clusterExecutionTargetProvider{}
}